mirror of
https://github.com/wfxr/forgit.git
synced 2026-09-10 07:16:23 -04:00
Fish checkout branch - updated internal function names to checkout::file and checkout::branch (#134)
* Initial commit, gcb working and function names fixed * Fixing indentation
This commit is contained in:
parent
4cd46818a5
commit
7b18caa340
|
|
@ -117,12 +117,12 @@ forgit_diff=gd
|
|||
forgit_add=ga
|
||||
forgit_reset_head=grh
|
||||
forgit_ignore=gi
|
||||
forgit_restore=gcf
|
||||
forgit_checkout_file=gcf
|
||||
forgit_clean=gclean
|
||||
forgit_stash_show=gss
|
||||
forgit_cherry_pick=gcp
|
||||
forgit_rebase=grb
|
||||
forgit_checkout=gcb
|
||||
forgit_checkout_branch=gcb
|
||||
```
|
||||
|
||||
Forgit will use the default configured pager from git (`core.pager`,
|
||||
|
|
@ -158,7 +158,7 @@ Customizing fzf options for each command individually is also supported:
|
|||
| `gi` | `FORGIT_IGNORE_FZF_OPTS` |
|
||||
| `gd` | `FORGIT_DIFF_FZF_OPTS` |
|
||||
| `grh` | `FORGIT_RESET_HEAD_FZF_OPTS` |
|
||||
| `gcf` | `FORGIT_CHECKOUT_FZF_OPTS` |
|
||||
| `gcf` | `FORGIT_CHECKOUT_FILE_FZF_OPTS` |
|
||||
| `gss` | `FORGIT_STASH_FZF_OPTS` |
|
||||
| `gclean` | `FORGIT_CLEAN_FZF_OPTS` |
|
||||
| `grb` | `FORGIT_REBASE_FZF_OPTS` |
|
||||
|
|
|
|||
|
|
@ -146,17 +146,18 @@ function forgit::reset::head -d "git reset HEAD (unstage) selector"
|
|||
end
|
||||
|
||||
# git checkout-restore selector
|
||||
function forgit::checkout_file -d "git checkout-restore selector"
|
||||
function forgit::checkout::file -d "git checkout-file selector"
|
||||
forgit::inside_work_tree || return 1
|
||||
|
||||
set cmd "git diff --color=always -- {} | $forgit_diff_pager"
|
||||
set opts "
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
-m -0
|
||||
$FORGIT_CHECKOUT_FZF_OPTS
|
||||
$FORGIT_CHECKOUT_FILE_FZF_OPTS
|
||||
"
|
||||
set git_rev_parse (git rev-parse --show-toplevel)
|
||||
set files (git ls-files --modified "$git_rev_parse" | env FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd")
|
||||
|
||||
if test -n "$files"
|
||||
for file in $files
|
||||
echo $file | tr '\n' '\0' | xargs -I{} -0 git checkout -q {}
|
||||
|
|
@ -167,6 +168,20 @@ function forgit::checkout_file -d "git checkout-restore selector"
|
|||
echo 'Nothing to restore.'
|
||||
end
|
||||
|
||||
function forgit::checkout::branch -d "git checkout branch selector"
|
||||
forgit::inside_work_tree || return 1
|
||||
|
||||
set cmd "git branch --color=always --verbose --all --format=\"%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%(refname:short)%(end)\" $argv $forgit_emojify | sed '/^\$/d'"
|
||||
set preview "git log {} --graph --pretty=format:'%C(auto)%h%d %s %C(black)%C(bold)%cr%Creset' --color=always --abbrev-commit --date=relative"
|
||||
|
||||
set opts "
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
+s +m --tiebreak=index --ansi
|
||||
$FORGIT_CHECKOUT_BRANCH_FZF_OPTS
|
||||
"
|
||||
eval "$cmd" | env FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" | xargs -I% git checkout %
|
||||
end
|
||||
|
||||
# git stash viewer
|
||||
function forgit::stash::show -d "git stash viewer"
|
||||
forgit::inside_work_tree || return 1
|
||||
|
|
@ -374,10 +389,16 @@ if test -z "$FORGIT_NO_ALIASES"
|
|||
alias gi 'forgit::ignore'
|
||||
end
|
||||
|
||||
if test -n "$forgit_restore"
|
||||
alias $forgit_restore 'forgit::checkout_file'
|
||||
if test -n "$forgit_checkout_file"
|
||||
alias $forgit_checkout_file 'forgit::checkout::file'
|
||||
else
|
||||
alias gcf 'forgit::checkout_file'
|
||||
alias gcf 'forgit::checkout::file'
|
||||
end
|
||||
|
||||
if test -n "$forgit_checkout_branch"
|
||||
alias $forgit_branch 'forgit::checkout::branch'
|
||||
else
|
||||
alias gcb 'forgit::checkout::branch'
|
||||
end
|
||||
|
||||
if test -n "$forgit_clean"
|
||||
|
|
|
|||
10
forgit.plugin.zsh
Normal file → Executable file
10
forgit.plugin.zsh
Normal file → Executable file
|
|
@ -106,14 +106,14 @@ forgit::reset::head() {
|
|||
}
|
||||
|
||||
# git checkout-restore selector
|
||||
forgit::restore() {
|
||||
forgit::checkout::file() {
|
||||
forgit::inside_work_tree || return 1
|
||||
local cmd files opts
|
||||
cmd="git diff --color=always -- {} | $forgit_diff_pager"
|
||||
opts="
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
-m -0
|
||||
$FORGIT_CHECKOUT_FZF_OPTS
|
||||
$FORGIT_CHECKOUT_FILE_FZF_OPTS
|
||||
"
|
||||
files="$(git ls-files --modified "$(git rev-parse --show-toplevel)"| FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd")"
|
||||
[[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | xargs -0 -I% git checkout % && git status --short && return
|
||||
|
|
@ -182,7 +182,7 @@ forgit::rebase() {
|
|||
xargs -I% git rebase -i %
|
||||
}
|
||||
|
||||
forgit::checkout() {
|
||||
forgit::checkout::branch() {
|
||||
forgit::inside_work_tree || return 1
|
||||
local cmd preview opts
|
||||
cmd="git branch --color=always --verbose --all --format=\"%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%(refname:short)%(end)\" $* $forgit_emojify | sed '/^$/d'"
|
||||
|
|
@ -266,8 +266,8 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then
|
|||
alias "${forgit_log:-glo}"='forgit::log'
|
||||
alias "${forgit_diff:-gd}"='forgit::diff'
|
||||
alias "${forgit_ignore:-gi}"='forgit::ignore'
|
||||
alias "${forgit_restore:-gcf}"='forgit::restore'
|
||||
alias "${forgit_checkout:-gcb}"='forgit::checkout'
|
||||
alias "${forgit_checkout_file:-gcf}"='forgit::checkout::file'
|
||||
alias "${forgit_checkout_branch:-gcb}"='forgit::checkout::branch'
|
||||
alias "${forgit_clean:-gclean}"='forgit::clean'
|
||||
alias "${forgit_stash_show:-gss}"='forgit::stash::show'
|
||||
alias "${forgit_cherry_pick:-gcp}"='forgit::cherry::pick'
|
||||
|
|
|
|||
Loading…
Reference in a new issue