Skip to content

Instantly share code, notes, and snippets.

@jaysonsantos
Last active April 17, 2021 21:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaysonsantos/1d6d7011ad2bf355124ba36c85005078 to your computer and use it in GitHub Desktop.
Save jaysonsantos/1d6d7011ad2bf355124ba36c85005078 to your computer and use it in GitHub Desktop.
# based on https://github.com/junegunn/fzf/wiki/Examples#autojump
function _fzf_autojump() {
fzf --height 40% --reverse --inline-info
}
function _fzf_cleanup() {
awk '$1 ~ /[0-9]:/ && $2 ~ /^\// { for (i=2; i<=NF; i++) { print $(i) } }'
}
function j() {
local folder
if [[ "$#" -ne 0 ]]; then
folder=$(autojump "$@")
if [[ $folder = "." ]]; then
echo "Falling back to fd with fzf"
folder=$(fd "$1" -td "$HOME" | fzf)
if [[ -n $folder ]]; then
autojump --add "$folder"
cd "$folder" || return
fi
else
cd "$folder" || return
fi
return
fi
cd "$(autojump -s | sort -k1gr | _fzf_cleanup | _fzf_autojump)" || exit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment