Last active
March 17, 2023 01:02
-
-
Save iul1an/5f8e52cdf04e628f804287494dfd96fb to your computer and use it in GitHub Desktop.
fzfun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# desc: open a new shell using aws-vault and use fzf to choose a profile if no profile is provided as argument | |
# desc: append "--stdout" to print the SSO login link instead of automatically opening a browser | |
# shell: zsh | |
aws-vault () { | |
local ARGS=("$@") | |
if [[ $1 == "exec" ]]; then | |
if [[ $# -eq 1 ]]; then | |
local AWS_PROFILE | |
AWS_PROFILE="$(command aws-vault list --profiles | fzf)" | |
ARGS=("exec" "$AWS_PROFILE" "--stdout") | |
else | |
if [[ "$*" != *"--stdout"* ]]; then | |
ARGS+=("--stdout") | |
fi | |
fi | |
fi | |
command aws-vault "$ARGS" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# desc: use fzf to attach a screen when there's more than one detached session and no session is provided as argument | |
# shell: zsh | |
screen () { | |
local ARGS=("$@") | |
if [[ $# -eq 1 ]] && [[ $1 == "-r" ]]; then | |
local SESSIONS | |
SESSIONS="$(command screen -ls | awk '/(Detached)/{print $1}')" | |
if [[ $(echo $SESSIONS | wc -l) -gt 1 ]]; then | |
ARGS=("-r" "$(echo $SESSIONS | fzf)") | |
fi | |
fi | |
command screen "$ARGS" | |
} | |
# shell: bash | |
screen () { | |
local ARGS="$@" | |
if [[ $# -eq 1 ]] && [[ $1 == "-r" ]]; then | |
local SESSIONS | |
SESSIONS=$(command screen -ls | awk '/(Detached)/{print $1}') | |
if [[ $(echo "${SESSIONS}" | wc -l) -gt 1 ]]; then | |
ARGS="-r $(echo "${SESSIONS}" | fzf)" | |
fi | |
fi | |
command screen "$ARGS" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# desc: easily switch Kubernetes namespace without installing extra tools such as kubens | |
# shell: zsh | |
kns () { | |
local NAMESPACE | |
NAMESPACE=${1:=$(kubectl get ns --no-headers -o custom-columns=":metadata.name" | fzf)} | |
if [[ -n $NAMESPACE ]]; then | |
kubectl config \ | |
set-context \ | |
--current \ | |
--namespace "$NAMESPACE" | |
else | |
echo "$0: no namespace provided or selected" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment