Skip to content

Commit

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

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

- **Interactive `git revert <commit>` selector** (`grc`)

- **Interactive `git stash` viewer** (`gss`)

- **Interactive `git clean` selector** (`gclean`)
Expand Down Expand Up @@ -140,6 +142,7 @@ forgit_checkout_file=gcf
forgit_checkout_branch=gcb
forgit_checkout_tag=gct
forgit_checkout_commit=gco
forgit_revert_commit=grc
forgit_clean=gclean
forgit_stash_show=gss
forgit_cherry_pick=gcp
Expand Down Expand Up @@ -220,6 +223,7 @@ Customizing fzf options for each command individually is also supported:
| `gcb` | `FORGIT_CHECKOUT_BRANCH_FZF_OPTS` |
| `gct` | `FORGIT_CHECKOUT_TAG_FZF_OPTS` |
| `gco` | `FORGIT_CHECKOUT_COMMIT_FZF_OPTS` |
| `grc` | `FORGIT_REVERT_COMMIT_OPTS` |
| `gss` | `FORGIT_STASH_FZF_OPTS` |
| `gclean` | `FORGIT_CLEAN_FZF_OPTS` |
| `grb` | `FORGIT_REBASE_FZF_OPTS` |
Expand Down
23 changes: 23 additions & 0 deletions forgit.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,28 @@ forgit::checkout::commit() {
FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd" |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git checkout % --
}

# git revert-commit selector
forgit::revert::commit() {
forgit::inside_work_tree || return 1
[[ $# -ne 0 ]] && { git revert "$@"; return $?; }
local cmd opts files preview commits
cmd="git log --graph --color=always --format='$forgit_log_format' $* $forgit_emojify"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+s --tiebreak=index
$FORGIT_REVERT_COMMIT_OPTS
"
files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command
preview="echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | $forgit_show_pager"
commits="$(eval "$cmd" |
FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" -m |
grep -Eo '^\*\s[a-f0-9]+' |
cut -c 3- |
tr $'\n' ' ')"
[[ -z "$commits" ]] && return 1
eval "git revert $commits"
}

# git ignore generator
export FORGIT_GI_REPO_REMOTE=${FORGIT_GI_REPO_REMOTE:-https://github.com/dvcs/gitignore}
export FORGIT_GI_REPO_LOCAL="${FORGIT_GI_REPO_LOCAL:-${XDG_CACHE_HOME:-$HOME/.cache}/forgit/gi/repos/dvcs/gitignore}"
Expand Down Expand Up @@ -352,6 +374,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_revert_commit:-grc}"='forgit::revert::commit'
alias "${forgit_checkout_tag:-gct}"='forgit::checkout::tag'
alias "${forgit_clean:-gclean}"='forgit::clean'
alias "${forgit_stash_show:-gss}"='forgit::stash::show'
Expand Down

0 comments on commit 45cab4d

Please sign in to comment.