Skip to content

Commit

Permalink
shellrc: Introduce new ggclone alias
Browse files Browse the repository at this point in the history
This commit introduces a new `ggclone` alias that is a hybrid of `ggcd`
and `ggman clone`. It clones a repository, unless it already exists.
Afterwards it `cd`s into the target location.
  • Loading branch information
tkw1536 committed Jul 10, 2022
1 parent fb2c0e2 commit 45941d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ eval "$(ggman shellrc)"
For example, `ggcd github.com/hello/world` will cd into the directory where the `github.com/hello/world` repository is checked out.
This also works with any pattern matching a repository, e.g. `ggcd world` will cd into the first repository matching `world`.

#### ggclone

`ggclone` behaves similar to `ggman clone` and `ggcd`.
It takes the exact same arguments as `ggman clone`, but when the repository already exists in the default location does not clone it again.
Furthermore, after finishing the clone, automatically `cd`s into the cloned repository.

#### ggcode

ggcode is like ggcd, except it opens an editor (here vscode) instead of cding.
Expand Down Expand Up @@ -412,7 +418,8 @@ ggman comes with the following builtin aliases:

### 1.18.0 (Upcoming)

- move aliases to new `ggman shellrc` command
- move aliases to new `ggman shellrc` command
- add new `ggclone` alias
- build universal mac executables

### 1.17.0 (Released [May 30 2022](https://github.com/tkw1536/ggman/releases/tag/v1.17.0))
Expand Down
14 changes: 12 additions & 2 deletions cmd/shellrc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@
# This also works with short names, e.g. "ggcd world" will cd into the first
# repository matching "world".
ggcd () {
ggman -f $1 ls --exit-code --one && cd "$(ggman -f $1 ls --exit-code --one 2>&1)"
ggman -f "$1" ls --exit-code --one && cd "$(ggman -f "$1" ls --exit-code --one 2>&1)"
}

# ggcode is like ggcd, except it opens an editor (here vscode) instead of cding.
ggcode () {
ggman -f $1 ls --exit-code --one && code "$(ggman -f $1 ls --exit-code --one 2>&1)"
ggman -f "$1" ls --exit-code --one && code "$(ggman -f "$1" ls --exit-code --one 2>&1)"
}

# ggclone clones a repository if it does not yet exist, and then ccds into the correct directory.
ggclone () {
DEST=$(ggman --no-fuzzy-filter -f "$1" ls --one)
if [ -n "$DEST" ] && ! [ -d "$DEST" ]; then
ggman clone "$@" || return 1
fi
echo "$DEST"
cd "$DEST"
}

0 comments on commit 45941d8

Please sign in to comment.