Skip to content

Instantly share code, notes, and snippets.

@TaKO8Ki
Last active April 12, 2023 00:19
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TaKO8Ki/19df90e7de8c0cd1dfed283e9b6a011e to your computer and use it in GitHub Desktop.
Save TaKO8Ki/19df90e7de8c0cd1dfed283e9b6a011e to your computer and use it in GitHub Desktop.
An alternative to `cd`
# requirements
# fd: https://github.com/sharkdp/fd
# fzf: https://github.com/junegunn/fzf
function cd() {
flag='-f'
if [ $# -eq 0 ]; then
builtin cd
elif [ $# -eq 1 ]; then
if [ $1 = "$flag" ]; then
dirs=$(fd --type d . $HOME | fzf)
if [ "$dirs" != '' ]; then
builtin cd "$dirs"
fi
else
builtin cd $1
fi
elif [ $2 = "$flag" ]; then
target=${1:-$HOME}
dirs=$(fd --type d . $target | fzf)
if [ "$dirs" != '' ]; then
builtin cd "$dirs"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment