Merge pull request #122 from wfxr/feat-rebase

Add rebase function
This commit is contained in:
Chris Apple 2020-11-06 09:05:27 -08:00 committed by GitHub
commit d142b681ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

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

View file

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