Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate jump navigation #294

Open
blaggacao opened this issue Jul 20, 2020 · 7 comments
Open

Incorporate jump navigation #294

blaggacao opened this issue Jul 20, 2020 · 7 comments

Comments

@blaggacao
Copy link

blaggacao commented Jul 20, 2020

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

It allows to jump to

  • ~/ghq/github.com/x-motemen/ghq by just typing h 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 to ghq - 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?

@zimbatm
Copy link

zimbatm commented Jul 20, 2020

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
Copy link
Author

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
Copy link

glucas commented Jul 21, 2020

@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
Copy link
Author

blaggacao commented Jul 21, 2020

@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
Copy link

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants