ghq
ghq copied to clipboard
Incorporate jump navigation
https://github.com/zimbatm/h is a very similar tool.
It allows to jump to
-
~/ghq/github.com/x-motemen/ghq
by just typingh ghq
- or (to diambiguate in the presence of a local fork)
h blaggacao/ghq
for~/ghq/github.com/blaggacao/ghq
. - if one writes
h x-motemen/ghq
- somewhat similar toghq
- it clones from github, if a local copy doesn't exist. - If this repo was on gitlab, I'd have to write
h gitlab.com/x-motemen/ghq
to achieve the same.
The author of h suggests that it would be worth the effort to think about incorporatin h's functionality into ghq
since ghq is the more versatile tool.
@x-motemen what are your thoughts?
the h
implementation is quite trivial as well so it should be easy to figure it out.
- when
owner/repo
or URL is used, there is a heuristic to map it to a fixed filesystem location - when
repo
is used, it does a case insensitive search of depth 3 for all the folder with that name and selects the deepest result In both cases, it outputs the target path on stdout.
Then there is a bash shell wrapper that gets installed and simply forwards the command and then cd
to the outputted folder.
Meanwhile I came up with this shell function:
function j() {
local ROOT="$HOME/ghq"
if [ $# -eq 0 ]; then
_j_dir="$ROOT/$(ghq list | fzf)"
else
_j_dir=$(command h --resolve "$ROOT" "$@")
fi
_j_ret=$?
[ "$_j_dir" != "$PWD" ] && cd "$_j_dir"
return $_j_ret
}
@blaggacao
Meanwhile I came up with this shell function:
_j_dir="$ROOT/$(ghq list | fzf)"
If you are already using fzf, perhaps something like cd $(ghq list -p | fzf -1 -e)
is sufficient? I use something similar.
@glucas
cd $(ghq list -p | fzf -1 -e)
Thanks, the disadvantage is that it populates the fzf list with my ghq
-path prefix directory. That is redundant information I wanted to avoid.
EDIT: I really like ease of h
. This is why I wanted to combine. I have an inline shell history completion which does a reasonable good job in matching past commands. This little extra features makes this in the perfect auto-completing jump list. With fzf I'd have to ever go through fzf selection.
But I think you didn't actually intent to suggest avoiding h
altogether.
This is written using peco and the Fish shell, but should illustrate how I fixed the prefix/no prefix issue:
function ws
set -l short_dest (ghq list 2>/dev/null | peco --on-cancel=error --select-1 --query "$argv"); or return 1
set -l full_dest (ghq list --full-path --exact "$short_dest" 2>/dev/null)
cd "$full_dest"
end
So if I type ws
and start narrowing it down, I get:

Or, if I run ws wait
, it'll cd
to that folder by default, as there's only one match.
When cloning manually from ~/src/github.com/
into its subdirectory organisation/project
by amending this information to the git clone
command, it was quick to jump into the new project with (Alt + .), Enter
(in zsh
without cd
).
Including h into ghq can help regain similar speeds in finding that project's directory.
In case you also use fzf
, an alternative approach is to change the way its Alt-C key-binding works, by setting the environment variable FZF_ALT_C_COMMAND
:
export FZF_ALT_C_COMMAND="ghq list --full-path"
With that set, Alt-C displays a list of every Git repository managed by ghq, which can be filtered with fzf.