From ce19cc80ec0837eec1a19477385742b86e2a1a60 Mon Sep 17 00:00:00 2001 From: sandroid Date: Sat, 12 Feb 2022 22:34:30 +0100 Subject: [PATCH] Added gct --- README.md | 4 ++++ forgit.plugin.zsh | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 0e0986a1..ddbbc42e 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,8 @@ source (curl -sSL git.io/forgit-fish | psub) - **Interactive `git checkout ` selector** (`gcb`) +- **Interactive `git checkout ` selector** (`gct`) + - **Interactive `git checkout ` selector** (`gco`) - **Interactive `git stash` viewer** (`gss`) @@ -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 @@ -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` | diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 6dfa3431..6160f050 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -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 @@ -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'