Last active
April 17, 2021 21:41
-
-
Save jaysonsantos/1d6d7011ad2bf355124ba36c85005078 to your computer and use it in GitHub Desktop.
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
# 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