From 968d3629970a97a237f2601f7b8b1d7916feab26 Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Tue, 3 Nov 2020 15:47:11 +0800 Subject: [PATCH 1/2] feat: add forgit::rebase function --- forgit.plugin.zsh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 7145075..3fdf226 100644 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -163,6 +163,25 @@ forgit::cherry::pick() { xargs -I% git cherry-pick % } +forgit::rebase() { + forgit::inside_work_tree || return 1 + local cmd preview opts graph files + graph=--graph + [[ $FORGIT_LOG_GRAPH_ENABLE == false ]] && graph= + cmd="git log $graph --color=always --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' $* $forgit_emojify" + 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" + opts=" + $FORGIT_FZF_DEFAULT_OPTS + +s +m --tiebreak=index + --bind=\"ctrl-y:execute-silent(echo {} |grep -Eo '[a-f0-9]+' | head -1 | tr -d '\n' |${FORGIT_COPY_CMD:-pbcopy})\" + $FORGIT_REBASE_FZF_OPTS + " + eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" | + grep -Eo '[a-f0-9]+' | head -1 | + xargs -I% git rebase -i % +} + # 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}" @@ -238,4 +257,5 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then alias "${forgit_clean:-gclean}"='forgit::clean' alias "${forgit_stash_show:-gss}"='forgit::stash::show' alias "${forgit_cherry_pick:-gcp}"='forgit::cherry::pick' + alias "${forgit_rebase:-grb}"='forgit::rebase' fi From 074059454d21475a617645e1a930fb45767ee596 Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Tue, 3 Nov 2020 15:49:55 +0800 Subject: [PATCH 2/2] docs: add `grb` docs --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ab419b0..47df0e6 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ source (curl -sSL git.io/forgit-fish | psub) - **Interactive `git cherry-pick` selector** (`gcp`) +- **Interactive `git rebase -i` selector** (`grb`) + ### ⌨ Keybinds | Key | Action | @@ -117,6 +119,7 @@ forgit_restore=gcf forgit_clean=gclean forgit_stash_show=gss forgit_cherry_pick=gcp +forgit_rebase=grb ``` Forgit will use the default configured pager from git (`core.pager`, @@ -155,6 +158,7 @@ Customizing fzf options for each command individually is also supported: | `gcf` | `FORGIT_CHECKOUT_FZF_OPTS` | | `gss` | `FORGIT_STASH_FZF_OPTS` | | `gclean` | `FORGIT_CLEAN_FZF_OPTS` | +| `grb` | `FORGIT_REBASE_FZF_OPTS` | Complete loading order of fzf options is: