Skip to content

Commit

Permalink
Added gct
Browse files Browse the repository at this point in the history
  • Loading branch information
sandr01d committed Feb 12, 2022
1 parent 7b26cd4 commit ce19cc8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ source (curl -sSL git.io/forgit-fish | psub)

- **Interactive `git checkout <branch>` selector** (`gcb`)

- **Interactive `git checkout <tag>` selector** (`gct`)

- **Interactive `git checkout <commit>` selector** (`gco`)

- **Interactive `git stash` viewer** (`gss`)
Expand Down Expand Up @@ -136,6 +138,7 @@ forgit_reset_head=grh
forgit_ignore=gi
forgit_checkout_file=gcf
forgit_checkout_branch=gcb
forgit_checkout_tag=gct
forgit_checkout_commit=gco
forgit_clean=gclean
forgit_stash_show=gss
Expand Down Expand Up @@ -215,6 +218,7 @@ Customizing fzf options for each command individually is also supported:
| `grh` | `FORGIT_RESET_HEAD_FZF_OPTS` |
| `gcf` | `FORGIT_CHECKOUT_FILE_FZF_OPTS` |
| `gcb` | `FORGIT_CHECKOUT_BRANCH_FZF_OPTS` |
| `gct` | `FORGIT_CHECKOUT_TAG_FZF_OPTS` |
| `gco` | `FORGIT_CHECKOUT_COMMIT_FZF_OPTS` |
| `gss` | `FORGIT_STASH_FZF_OPTS` |
| `gclean` | `FORGIT_CLEAN_FZF_OPTS` |
Expand Down
18 changes: 18 additions & 0 deletions forgit.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,23 @@ forgit::checkout::branch() {
fi
}

# git checkout-tag selector
forgit::checkout::tag() {
forgit::inside_work_tree || return 1
[[ $# -ne 0 ]] && { git checkout "$@"; return $?; }
local cmd opts preview
cmd="git tag -l --sort=-v:refname"
preview="git log {1} --graph --pretty=format:'$forgit_log_format' --color=always --abbrev-commit --date=relative"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+s +m --tiebreak=index
$FORGIT_CHECKOUT_TAG_FZF_OPTS
"
tag="$(eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview")"
[[ -z "$tag" ]] && return 1
git checkout "$tag"
}

# git checkout-commit selector
forgit::checkout::commit() {
forgit::inside_work_tree || return 1
Expand Down Expand Up @@ -335,6 +352,7 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then
alias "${forgit_checkout_file:-gcf}"='forgit::checkout::file'
alias "${forgit_checkout_branch:-gcb}"='forgit::checkout::branch'
alias "${forgit_checkout_commit:-gco}"='forgit::checkout::commit'
alias "${forgit_checkout_tag:-gct}"='forgit::checkout::tag'
alias "${forgit_clean:-gclean}"='forgit::clean'
alias "${forgit_stash_show:-gss}"='forgit::stash::show'
alias "${forgit_cherry_pick:-gcp}"='forgit::cherry::pick'
Expand Down

0 comments on commit ce19cc8

Please sign in to comment.