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: 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