x-motemen / ghq

Remote repository management made easy
MIT License
3.08k stars 184 forks source link

Incorporate jump navigation #294

Open blaggacao opened 4 years ago

blaggacao commented 4 years ago

https://github.com/zimbatm/h is a very similar tool.

It allows to jump to

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?

zimbatm commented 4 years ago

the h implementation is quite trivial as well so it should be easy to figure it out.

  1. when owner/repo or URL is used, there is a heuristic to map it to a fixed filesystem location
  2. 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.

blaggacao commented 4 years ago

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
}
glucas commented 4 years ago

@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.

blaggacao commented 4 years ago

@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.

liamdawson commented 4 years ago

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:

image

Or, if I run ws wait, it'll cd to that folder by default, as there's only one match.

almereyda commented 3 years ago

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.

adamantike commented 2 years ago

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.