dotfiles

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 0da5d6fb9eeb173448d73f68b4598345f84af46d (tree)
parent 17e09bfb1c8c707b855aafefd163d2f3498012aa
Author: Motiejus Jakštys <motiejus@uber.com>
Date:   Fri, 30 Aug 2019 14:50:53 +0300

better `g` and `gg`

Diffstat:
Mbash/.gg.sh | 13++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/bash/.gg.sh b/bash/.gg.sh @@ -2,9 +2,8 @@ # Change to the directory of the specified Go package name. # -maxdepth=3 - -_gopath=$HOME/.go-code +maxdepth=4 +_gopath=$HOME/.go-code/src/code.uber.internal gg() { paths=($(g "$@")) @@ -23,15 +22,15 @@ gg() { fi path=${paths[$path_index]} - cd $_gopath/src/$path + cd $_gopath/$path } # # Print the directories of the specified Go package name. # g() { - local pkg_candidates="$((cd $_gopath/src && find . -mindepth 1 -maxdepth ${maxdepth} -type d \( -path "*/$1" -or -path "*/$1.git" \) -and -not -path '*/vendor/*' -print) | sed 's/^\.\///g')" - echo "$pkg_candidates" + local pkg_candidates="$((cd $_gopath && find . -mindepth 1 -maxdepth ${maxdepth} -type d \( -path "*/$1" -or -path "*/$1.git" \) -and -not -path '*/vendor/*' -print) | sed 's/^\.\///g')" + echo "$pkg_candidates" | awk '{print length, $0 }' | sort -n | awk '{print $2}' } # # Bash autocomplete for g and gg functions. @@ -43,7 +42,7 @@ _g_complete() local prev cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - COMPREPLY=( $(compgen -W "$(for f in $(find "$_gopath/src" -mindepth 1 -maxdepth ${maxdepth} -type d -name "${cur}*" ! -name '.*' ! -path '*/.git/*' ! -path '*/test/*' ! -path '*/Godeps/*' ! -path '*/examples/*' ! -path '*/vendor/*'); do echo "${f##*/}"; done)" -- "$cur") ) + COMPREPLY=( $(compgen -W "$(for f in $(find "$_gopath" -mindepth 1 -maxdepth ${maxdepth} -type d -name "${cur}*" ! -name '.*' ! -path '*/.git/*' ! -path '*/test/*' ! -path '*/Godeps/*' ! -path '*/examples/*' ! -path '*/vendor/*'); do echo "${f##*/}"; done)" -- "$cur") ) return 0 } complete -F _g_complete g