Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created June 28, 2019 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmouel/e616d9bf0896ff61d8681d693b9e1715 to your computer and use it in GitHub Desktop.
Save chmouel/e616d9bf0896ff61d8681d693b9e1715 to your computer and use it in GitHub Desktop.
j () {
local root=~/GIT/go/src/github.com/
local res results args
while getopts "np" opt
do
if [[ $opt = "?" ]]
then
print -r -- "$myname: unrecognized option: -$OPTARG" >&2
return 1
fi
eval "opt_$opt=\${OPTARG:--\$opt}"
done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
local fnd=$1
type -f zshz 2> /dev/null > /dev/null || opt_n=true
if [[ -n ${fnd} ]]
then
[[ -z ${opt_n} ]] && {
local zz=$(zshz -e ${fnd})
[[ -n ${zz} ]] && {
echo "ZSHZ: ${zz}"
[[ -z ${opt_p} ]] && cd ${zz}
return
}
}
local results=($(fd -d 2 -t d . ${root}|gegrep -i "${fnd}"))
[[ ${#results} == 1 ]] && {
echo ${results}
[[ -z ${opt_p} ]] && cd ${results}
return
}
[[ ${#results} == 0 ]] && {
echo "No results found for ${fnd}"
return 1
}
args="-q ${fnd}"
fi
res=$(fd -d 2 -t d . ${root}|sed "s,${root},,"|fzf --height 50% --border ${args})
[[ -n ${res} ]] && {
echo ${root}${res}
[[ -z ${opt_p} ]] && cd ${root}${res}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment