Last active
April 12, 2023 00:19
-
-
Save TaKO8Ki/19df90e7de8c0cd1dfed283e9b6a011e to your computer and use it in GitHub Desktop.
An alternative to `cd`
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
# 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