^ / 003_fzf_recipes

Fzf Recipes

git branch selector

function gb() {
  branch=$(
    git branch --list --sort=-committerdate \
    | fzf \
        --header 'ctrl-r: remote | alt-l: local | alt-f: git-fetch' \
        --prompt='branch> ' \
        --bind='alt-l:change-prompt(local> )+reload(git branch --list --sort=-committerdate),ctrl-r:change-prompt(remote> )+reload(git branch --all --sort=-committerdate),alt-f:execute(git fetch)' \
  )

  if [k9s cluster selector]; then
    tr -d ' *' <<< "$branch" \
    | awk '{gsub(/remotes\/origin\//,"");}1' \
    | xargs git checkout
  fi
}

k9s cluster selector

function kc() {
  cluster=$(kubectl ctx | fzf)
  if [ "$cluster" = "" ]; then
    printf "no clusters selected\n"
    return 1
  fi
  k9s --context "$cluster"
}

k9s namespace selector

function kn() {
  cluster=$(kubectl ctx | fzf)
  if [ "$cluster" = "" ]; then
    printf "no clusters selected\n"
    return 1
  fi
  selection=$(kubectl --context $cluster get --no-headers namespaces > /dev/null | fzf)
  if [ "$selection" = "" ]; then
    printf "no namespace selected\n"
  fi
  namespace=$(awk '{ print $1 }' <<< "$selection")
  k9s --context "$cluster" --namespace "$namespace"
}