From 7b18caa34051edbcd67c765b4a7191a2d1b7d17c Mon Sep 17 00:00:00 2001 From: Chris Apple Date: Wed, 17 Feb 2021 19:51:54 -0800 Subject: [PATCH] Fish checkout branch - updated internal function names to checkout::file and checkout::branch (#134) * Initial commit, gcb working and function names fixed * Fixing indentation --- README.md | 6 +++--- conf.d/forgit.plugin.fish | 31 ++++++++++++++++++++++++++----- forgit.plugin.zsh | 10 +++++----- 3 files changed, 34 insertions(+), 13 deletions(-) mode change 100644 => 100755 forgit.plugin.zsh diff --git a/README.md b/README.md index 16af946..3f84a39 100644 --- a/README.md +++ b/README.md @@ -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` | diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index d7113a2..43bef8c 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -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" diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh old mode 100644 new mode 100755 index 057d142..630fdc9 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -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'