ghq/Q/Using ghq, what's the easiest way to cd to the local repo if it exists?
Properties
- logseq-entity
- Logseq/Entity/Question
Using ghq, what's the easiest way to cd to the local repo if it exists? card
AI Answer
- AI/Response
- Short answer: pipe
ghq list --full-paththroughgrepto get the path, thencdto it. - bash
cd "$(ghq list --full-path | grep -m 1 <repo-name>)" - For exact owner/repo matching,
ghq listoutput is inowner/repoform — combine withghq rootor use--full-path: - bash
# Exact owner/repo, full path cd "$(ghq list --full-path | grep -m 1 owner/repo)" - To guard against the repo not existing locally (silent no-op instead of a
cderror): - bash
dir="$(ghq list --full-path | grep -m 1 owner/repo)" && [ -d "$dir" ] && cd "$dir" - For interactive fuzzy selection across all local repos, pair with fzf:
- bash
cd "$(ghq list --full-path | fzf)" - Note:
ghq look <repo>(older versions) opened a sub-shell instead of a truecd;ghq list --full-path | grepis the idiomatic replacement.