From 4027bee420ea796a473ef1b83da93f87883b0208 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 07:52:58 -0700 Subject: [PATCH 01/14] Apparently working preview update --- conf.d/forgit.plugin.fish | 62 +++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index 4c848bc..355dd24 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -34,7 +34,7 @@ function forgit::log -d "git commit viewer" forgit::inside_work_tree || return 1 set files (echo $argv | sed -nE 's/.* -- (.*)/\1/p') - set cmd "echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | $forgit_show_pager" + set preview "echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | $forgit_show_pager" if test -n "$FORGIT_COPY_CMD" set copy_cmd $FORGIT_COPY_CMD @@ -45,8 +45,9 @@ function forgit::log -d "git commit viewer" set opts " $FORGIT_FZF_DEFAULT_OPTS +s +m --tiebreak=index - --bind=\"enter:execute($cmd |env LESS='-r' less)\" + --bind=\"enter:execute($preview |env LESS='-r' less)\" --bind=\"ctrl-y:execute-silent(echo {} |grep -Eo '[a-f0-9]+' | head -1 | tr -d '[:space:]' |$copy_cmd)\" + --preview=\"$preview\" $FORGIT_LOG_FZF_OPTS " @@ -57,7 +58,7 @@ function forgit::log -d "git commit viewer" end eval "git log $graph --color=always --format='$forgit_log_format' $argv $forgit_emojify" | - env FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd" + env FZF_DEFAULT_OPTS="$opts" fzf end ## git diff viewer @@ -72,14 +73,15 @@ function forgit::diff -d "git diff viewer" end set repo (git rev-parse --show-toplevel) - set cmd "echo {} |sed 's/.*] //' | xargs -I% git diff --color=always $commit -- '$repo/%' | $forgit_diff_pager" + set preview "echo {} |sed 's/.*] //' | xargs -I% git diff --color=always $commit -- '$repo/%' | $forgit_diff_pager" set opts " $FORGIT_FZF_DEFAULT_OPTS - +m -0 --bind=\"enter:execute($cmd |env LESS='-r' less)\" + +m -0 --bind=\"enter:execute($preview |env LESS='-r' less)\" + --preview=\"$preview\" $FORGIT_DIFF_FZF_OPTS " - eval "git diff --name-only $commit -- $files*| sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/'" | env FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd" + eval "git diff --name-only $commit -- $files*| sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/'" | env FZF_DEFAULT_OPTS="$opts" fzf end # git add selector @@ -110,12 +112,13 @@ function forgit::add -d "git add selector" set opts " $FORGIT_FZF_DEFAULT_OPTS -0 -m --nth 2..,.. + --preview=\"$preview\" $FORGIT_ADD_FZF_OPTS " set files (git -c color.status=always -c status.relativePaths=true status -su | grep -F -e "$changed" -e "$unmerged" -e "$untracked" | sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)\$/[\1] \2/' | # deal with white spaces internal to fname - env FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" | + env FZF_DEFAULT_OPTS="$opts" fzf | sh -c "$extract_file") # for rename case if test -n "$files" @@ -131,13 +134,14 @@ end ## git reset HEAD (unstage) selector function forgit::reset::head -d "git reset HEAD (unstage) selector" forgit::inside_work_tree || return 1 - set cmd "git diff --cached --color=always -- {} | $forgit_diff_pager" + set preview "git diff --cached --color=always -- {} | $forgit_diff_pager" set opts " $FORGIT_FZF_DEFAULT_OPTS -m -0 + --preview=\"$preview\" $FORGIT_RESET_HEAD_FZF_OPTS " - set files (git diff --cached --name-only --relative | env FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd") + set files (git diff --cached --name-only --relative | env FZF_DEFAULT_OPTS="$opts" fzf) if test -n "$files" for file in $files echo $file | tr '\n' '\0' |xargs -I{} -0 git reset -q HEAD {} @@ -160,14 +164,15 @@ function forgit::checkout::file -d "git checkout-file selector" --argument-names end - set cmd "git diff --color=always -- {} | $forgit_diff_pager" + set preview "git diff --color=always -- {} | $forgit_diff_pager" set opts " $FORGIT_FZF_DEFAULT_OPTS -m -0 + --preview=\"$preview\" $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") + set files (git ls-files --modified "$git_rev_parse" | env FZF_DEFAULT_OPTS="$opts" fzf) if test -n "$files" for file in $files @@ -196,11 +201,12 @@ function forgit::checkout::commit -d "git checkout commit selector" --argument-n end - set cmd "echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % | $forgit_show_pager" + set preview "echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % | $forgit_show_pager" set opts " $FORGIT_FZF_DEFAULT_OPTS +s +m --tiebreak=index --bind=\"ctrl-y:execute-silent(echo {} |grep -Eo '[a-f0-9]+' | head -1 | tr -d '[:space:]' | $copy_cmd)\" + --preview=\"$preview\" $FORGIT_COMMIT_FZF_OPTS " @@ -211,7 +217,7 @@ function forgit::checkout::commit -d "git checkout commit selector" --argument-n end eval "git log $graph --color=always --format='$forgit_log_format' $forgit_emojify" | - FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd" |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git checkout % -- + FZF_DEFAULT_OPTS="$opts" fzf | grep -Eo '[a-f0-9]+' | head -1 | xargs -I% git checkout % -- end @@ -225,16 +231,17 @@ function forgit::checkout::branch -d "git checkout branch selector" --argument-n return $checkout_status end - set cmd "git branch --color=always --verbose --all | sort -k1.1,1.1 -r" set preview "git log {1} --graph --pretty=format:'$forgit_log_format' --color=always --abbrev-commit --date=relative" set opts " $FORGIT_FZF_DEFAULT_OPTS +s +m --tiebreak=index --header-lines=1 + --preview=\"$preview\" $FORGIT_CHECKOUT_BRANCH_FZF_OPTS " - set branch (eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" | awk '{print $1}') + set cmd "git branch --color=always --verbose --all | sort -k1.1,1.1 -r" + set branch (eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf | awk '{print $1}') test -z "$branch" && return 1 @@ -247,13 +254,14 @@ end # git stash viewer function forgit::stash::show -d "git stash viewer" forgit::inside_work_tree || return 1 - set cmd "echo {} |cut -d: -f1 |xargs -I% git stash show --color=always --ext-diff % |$forgit_diff_pager" + set preview "echo {} |cut -d: -f1 |xargs -I% git stash show --color=always --ext-diff % |$forgit_diff_pager" set opts " $FORGIT_FZF_DEFAULT_OPTS - +s +m -0 --tiebreak=index --bind=\"enter:execute($cmd |env LESS='-r' less)\" + +s +m -0 --tiebreak=index --bind=\"enter:execute($preview |env LESS='-r' less)\" + --preview=\"$preview\" $FORGIT_STASH_FZF_OPTS " - git stash list | env FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd" + git stash list | env FZF_DEFAULT_OPTS="$opts" fzf end # git clean selector @@ -287,13 +295,14 @@ function forgit::cherry::pick -d "git cherry-picking" --argument-names 'target' end set preview "echo {1} | xargs -I% git show --color=always % | $forgit_show_pager" set opts " + --preview=\"$preview\" $FORGIT_FZF_DEFAULT_OPTS -m -0 " echo $base echo $target git cherry "$base" "$target" --abbrev -v | cut -d ' ' -f2- | - env FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" | cut -d' ' -f1 | + env FZF_DEFAULT_OPTS="$opts" fzf | cut -d' ' -f1 | xargs -I% git cherry-pick % end @@ -307,7 +316,6 @@ function forgit::fixup -d "git fixup" set graph "" end - set cmd "git log $graph --color=always --format='$forgit_log_format' $argv $forgit_emojify" set files (echo $argv | sed -nE 's/.* -- (.*)/\1/p') set preview "echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | $forgit_show_pager" @@ -321,10 +329,12 @@ function forgit::fixup -d "git fixup" $FORGIT_FZF_DEFAULT_OPTS +s +m --tiebreak=index --bind=\"ctrl-y:execute-silent(echo {} |grep -Eo '[a-f0-9]+' | head -1 | tr -d '[:space:]' |$copy_cmd)\" + --preview=\"$preview\" $FORGIT_FIXUP_FZF_OPTS " - set target_commit (eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" | grep -Eo '[a-f0-9]+' | head -1) + set cmd "git log $graph --color=always --format='$forgit_log_format' $argv $forgit_emojify" + set target_commit (eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf | grep -Eo '[a-f0-9]+' | head -1) if test -n "$target_commit" && git commit --fixup "$target_commit" # "$target_commit~" is invalid when the commit is the first commit, but we can use "--root" instead @@ -347,7 +357,7 @@ function forgit::rebase -d "git rebase" else set graph "" end - set cmd "git log $graph --color=always --format='$forgit_log_format' $argv $forgit_emojify" + set preview "git log $graph --color=always --format='$forgit_log_format' $argv $forgit_emojify" set files (echo $argv | sed -nE 's/.* -- (.*)/\1/p') set preview "echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | $forgit_show_pager" @@ -362,9 +372,10 @@ function forgit::rebase -d "git rebase" $FORGIT_FZF_DEFAULT_OPTS +s +m --tiebreak=index --bind=\"ctrl-y:execute-silent(echo {} |grep -Eo '[a-f0-9]+' | head -1 | tr -d '[:space:]' |$copy_cmd)\" + --preview=\"$preview\" $FORGIT_REBASE_FZF_OPTS " - set commit (eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" | + set commit (eval "$preview" | FZF_DEFAULT_OPTS="$opts" fzf | grep -Eo '[a-f0-9]+' | head -1) if test $commit @@ -394,10 +405,11 @@ function forgit::ignore -d "git ignore generator" forgit::ignore::update end - set cmd "$forgit_ignore_pager $FORGIT_GI_TEMPLATES/{2}{,.gitignore} 2>/dev/null" + set preview "$forgit_ignore_pager $FORGIT_GI_TEMPLATES/{2}{,.gitignore} 2>/dev/null" set opts " $FORGIT_FZF_DEFAULT_OPTS -m --preview-window='right:70%' + --preview=\"$preview\" $FORGIT_IGNORE_FZF_OPTS " set IFS '\n' @@ -405,7 +417,7 @@ function forgit::ignore -d "git ignore generator" set args $argv if not count $argv > /dev/null set args (forgit::ignore::list | nl -nrn -w4 -s' ' | - env FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd" |awk '{print $2}') + env FZF_DEFAULT_OPTS="$opts" fzf |awk '{print $2}') end if not count $args > /dev/null From e89f9f195e47649c21165f85a06b125e4b415243 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 08:05:39 -0700 Subject: [PATCH 02/14] Bad test commit to be reverted --- forgit.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 3cba1cb..4284f42 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -35,6 +35,7 @@ forgit::log() { FZF_DEFAULT_OPTS="$opts" fzf } + # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 From bdb04ecb84b27dbfabb6c74e3fdea16c618097c2 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 08:09:39 -0700 Subject: [PATCH 03/14] Revert "Bad test commit to be reverted" This reverts commit e89f9f195e47649c21165f85a06b125e4b415243. --- forgit.plugin.zsh | 1 - 1 file changed, 1 deletion(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 4284f42..3cba1cb 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -35,7 +35,6 @@ forgit::log() { FZF_DEFAULT_OPTS="$opts" fzf } - # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 From 37731d4da31d6e20c5b7d825c543647ae4fce231 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 08:22:15 -0700 Subject: [PATCH 04/14] Revert "Revert "Bad test commit to be reverted"" This reverts commit bdb04ecb84b27dbfabb6c74e3fdea16c618097c2. --- forgit.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 3cba1cb..4284f42 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -35,6 +35,7 @@ forgit::log() { FZF_DEFAULT_OPTS="$opts" fzf } + # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 From 0cde6852bcf26e9efa7f3119a51c09e5639524c4 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 08:29:44 -0700 Subject: [PATCH 05/14] Revert "Revert "Revert "Bad test commit to be reverted""" This reverts commit 37731d4da31d6e20c5b7d825c543647ae4fce231. --- forgit.plugin.zsh | 1 - 1 file changed, 1 deletion(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 4284f42..3cba1cb 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -35,7 +35,6 @@ forgit::log() { FZF_DEFAULT_OPTS="$opts" fzf } - # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 From fc9d031608422db43f9b229de864632d178f998a Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 08:30:50 -0700 Subject: [PATCH 06/14] Revert "Revert "Revert "Revert "Bad test commit to be reverted"""" This reverts commit 0cde6852bcf26e9efa7f3119a51c09e5639524c4. --- forgit.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 3cba1cb..4284f42 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -35,6 +35,7 @@ forgit::log() { FZF_DEFAULT_OPTS="$opts" fzf } + # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 From 63fdf99956f19e6a7c517a8d8f18d2da16d49178 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 08:30:53 -0700 Subject: [PATCH 07/14] Revert "Revert "Revert "Bad test commit to be reverted""" This reverts commit 37731d4da31d6e20c5b7d825c543647ae4fce231. --- forgit.plugin.zsh | 1 - 1 file changed, 1 deletion(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 4284f42..3cba1cb 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -35,7 +35,6 @@ forgit::log() { FZF_DEFAULT_OPTS="$opts" fzf } - # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 From 687710f2cd4b9b2d4123978749a907f9ece5dc82 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 08:30:57 -0700 Subject: [PATCH 08/14] Revert "Revert "Bad test commit to be reverted"" This reverts commit bdb04ecb84b27dbfabb6c74e3fdea16c618097c2. --- forgit.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 3cba1cb..4284f42 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -35,6 +35,7 @@ forgit::log() { FZF_DEFAULT_OPTS="$opts" fzf } + # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 From 2fc1436d1b8a7a3163f395fd76c489ccd0d1f38c Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 08:30:59 -0700 Subject: [PATCH 09/14] Revert "Bad test commit to be reverted" This reverts commit e89f9f195e47649c21165f85a06b125e4b415243. --- forgit.plugin.zsh | 1 - 1 file changed, 1 deletion(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 4284f42..3cba1cb 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -35,7 +35,6 @@ forgit::log() { FZF_DEFAULT_OPTS="$opts" fzf } - # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 From f8514beb264b8b552d4fc6a02828cdeb78ab33b3 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 08:31:40 -0700 Subject: [PATCH 10/14] Adding grc --- conf.d/forgit.plugin.fish | 44 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index 355dd24..2ea5215 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -427,6 +427,37 @@ function forgit::ignore -d "git ignore generator" forgit::ignore::get $args end +function forgit::revert::commit --argument-names 'commit_hash' + if test -n "$commit_hash" + git revert -- "$commit_hash" + set revert_status $status + git status --short + return $revert_status + end + + set preview "echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | $forgit_show_pager" + set opts " + $FORGIT_FZF_DEFAULT_OPTS + +s --tiebreak=index + --preview=\"$preview\" + $FORGIT_REVERT_COMMIT_OPTS + " + + set files (echo $argv | sed -nE 's/.* -- (.*)/\1/p') # extract files parameters for `git show` command + + set cmd "git log --graph --color=always --format='$forgit_log_format' $argv $forgit_emojify" + + set commits (eval $cmd | + FZF_DEFAULT_OPTS="$opts" fzf -m | + string match -r "[a-f0-9]+") + + if test -z "$commits" + return 1 + end + + git revert $commits +end + function forgit::ignore::update if test -d "$FORGIT_GI_REPO_LOCAL" forgit::info 'Updating gitignore repo...' @@ -451,12 +482,13 @@ function forgit::ignore::get end function forgit::ignore::list - find "$FORGIT_GI_TEMPLATES" -print |sed -e 's#.gitignore$##' -e 's#.*/##' | sort -fu + find "$FORGIT_GI_TEMPLATES" -print | sed -e 's#.gitignore$##' -e 's#.*/##' | sort -fu end function forgit::ignore::clean - setopt localoptions rmstarsilent - [[ -d "$FORGIT_GI_REPO_LOCAL" ]] && rm -rf "$FORGIT_GI_REPO_LOCAL" + if test -d "$FORGIT_GI_REPO_LOCAL" + rm -rf "$FORGIT_GI_REPO_LOCAL" + end end set -g FORGIT_FZF_DEFAULT_OPTS " @@ -554,4 +586,10 @@ if test -z "$FORGIT_NO_ALIASES" alias gco 'forgit::checkout::commit' end + if test -n "$forgit_revert_commit" + alias $forgit_revert_commit 'forgit::revert::commit' + else + alias grc 'forgit::revert::commit' + end + end From 5b31faf7e2ea7d8e688a83c16969b6c00dc05dba Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 09:33:55 -0700 Subject: [PATCH 11/14] Added multi diff support for gd --- README.md | 276 -------------------------------------- conf.d/forgit.plugin.fish | 21 ++- 2 files changed, 15 insertions(+), 282 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 6a9845e..0000000 --- a/README.md +++ /dev/null @@ -1,276 +0,0 @@ -

💤 forgit

-

- Utility tool for using git interactively. Powered by junegunn/fzf. -

- -

- - - - - - - - - - - - - - pre-commit - - - Contributors - -

- -This tool is designed to help you use git more efficiently. -It's **lightweight** and **easy to use**. - -### 📥 Installation - -*Make sure you have [`fzf`](https://github.com/junegunn/fzf) installed.* - -``` zsh -# for zplug -zplug 'wfxr/forgit' - -# for zgen -zgen load 'wfxr/forgit' - -# for antigen -antigen bundle 'wfxr/forgit' - -# for fisher -fisher install wfxr/forgit - -# for omf -omf install https://github.com/wfxr/forgit - -# for zinit -zinit load wfxr/forgit - -# manually -# Clone the repository and source it in your shell's rc file. -``` - -You can run the following command to try `forgit` without installing: - -``` bash -# for bash / zsh -source <(curl -sSL git.io/forgit) -# for fish -source (curl -sSL git.io/forgit-fish | psub) -``` - -### 📝 Features - -- **Interactive `git add` selector** (`ga`) - -![screenshot](https://raw.githubusercontent.com/wfxr/i/master/forgit-ga.png) - -- **Interactive `git log` viewer** (`glo`) - -![screenshot](https://raw.githubusercontent.com/wfxr/i/master/forgit-glo.png) - -*The log graph can be disabled by option `FORGIT_LOG_GRAPH_ENABLE` (see discuss in [issue #71](https://github.com/wfxr/forgit/issues/71)).* - -- **Interactive `.gitignore` generator** (`gi`) - -![screenshot](https://raw.githubusercontent.com/wfxr/i/master/forgit-gi.png) - -- **Interactive `git diff` viewer** (`gd`) - -- **Interactive `git reset HEAD ` selector** (`grh`) - -- **Interactive `git checkout ` selector** (`gcf`) - -- **Interactive `git checkout ` selector** (`gcb`) - -- **Interactive `git checkout ` selector** (`gct`) - -- **Interactive `git checkout ` selector** (`gco`) - -- **Interactive `git revert ` selector** (`grc`) - -- **Interactive `git stash` viewer** (`gss`) - -- **Interactive `git clean` selector** (`gclean`) - -- **Interactive `git cherry-pick` selector** (`gcp`) - -- **Interactive `git rebase -i` selector** (`grb`) - -- **Interactive `git commit --fixup && git rebase -i --autosquash` selector** (`gfu`) - -### ⌨ Keybinds - -| Key | Action | -| :-------------------------------------------: | ------------------------- | -| Enter | Confirm | -| Tab | Toggle mark and move up | -| Shift - Tab | Toggle mark and move down | -| ? | Toggle preview window | -| Alt - W | Toggle preview wrap | -| Ctrl - S | Toggle sort | -| Ctrl - R | Toggle selection | -| Ctrl - Y | Copy commit hash* | -| Ctrl - K / P | Selection move up | -| Ctrl - J / N | Selection move down | -| Alt - K / P | Preview move up | -| Alt - J / N | Preview move down | - -\* Available when the selection contains a commit hash. -For linux users `FORGIT_COPY_CMD` should be set to make copy work. Example: `FORGIT_COPY_CMD='xclip -selection clipboard'`. - -### ⚙ Options - -#### aliases - -##### shell - -You can change the default aliases by defining these variables below. -(To disable all aliases, Set the `FORGIT_NO_ALIASES` flag.) - -``` bash -forgit_log=glo -forgit_diff=gd -forgit_add=ga -forgit_reset_head=grh -forgit_ignore=gi -forgit_checkout_file=gcf -forgit_checkout_branch=gcb -forgit_checkout_tag=gct -forgit_checkout_commit=gco -forgit_revert_commit=grc -forgit_clean=gclean -forgit_stash_show=gss -forgit_cherry_pick=gcp -forgit_rebase=grb -forgit_fixup=gfu -``` - -#### git - -You can use git aliases by making `git-forgit` available in `$PATH`: - -```sh -# after `forgit` was loaded -export PATH="$PATH:$FORGIT_INSTALL_DIR/bin" -``` - -*Some plugin managers can help do this.* - -Then any forgit command will be a subcommand of git: - -``` -$ git forgit log -$ git forgit add -$ git forgit diff -``` - -Optionally you can add [aliases in git](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases): - -```sh -git config --global alias.cf 'forgit checkout_file' -``` - -And use the alias in git: - -```sh -git cf -``` - -#### pagers - -Forgit will use the default configured pager from git (`core.pager`, -`pager.show`, `pager.diff`) but can be altered with the following environment -variables: - -| Use case | Option | Fallbacks to | -| ------------ | ------------------- | -------------------------------------------- | -| common pager | `FORGIT_PAGER` | `git config core.pager` _or_ `cat` | -| pager on `git show` | `FORGIT_SHOW_PAGER` | `git config pager.show` _or_ `$FORGIT_PAGER` | -| pager on `git diff` | `FORGIT_DIFF_PAGER` | `git config pager.diff` _or_ `$FORGIT_PAGER` | -| pager on `gitignore` | `FORGIT_IGNORE_PAGER` | `bat -l gitignore --color always` _or_ `cat` | -| git log format | `FORGIT_GLO_FORMAT` | `%C(auto)%h%d %s %C(black)%C(bold)%cr%reset` | - -#### fzf options - -You can add default fzf options for `forgit`, including keybinds, layout, etc. -(No need to repeat the options already defined in `FZF_DEFAULT_OPTS`) - -``` bash -FORGIT_FZF_DEFAULT_OPTS=" ---exact ---border ---cycle ---reverse ---height '80%' -" -``` - -Customizing fzf options for each command individually is also supported: - -| Command | Option | -|----------|-----------------------------------| -| `ga` | `FORGIT_ADD_FZF_OPTS` | -| `glo` | `FORGIT_LOG_FZF_OPTS` | -| `gi` | `FORGIT_IGNORE_FZF_OPTS` | -| `gd` | `FORGIT_DIFF_FZF_OPTS` | -| `grh` | `FORGIT_RESET_HEAD_FZF_OPTS` | -| `gcf` | `FORGIT_CHECKOUT_FILE_FZF_OPTS` | -| `gcb` | `FORGIT_CHECKOUT_BRANCH_FZF_OPTS` | -| `gct` | `FORGIT_CHECKOUT_TAG_FZF_OPTS` | -| `gco` | `FORGIT_CHECKOUT_COMMIT_FZF_OPTS` | -| `grc` | `FORGIT_REVERT_COMMIT_OPTS` | -| `gss` | `FORGIT_STASH_FZF_OPTS` | -| `gclean` | `FORGIT_CLEAN_FZF_OPTS` | -| `grb` | `FORGIT_REBASE_FZF_OPTS` | -| `gfu` | `FORGIT_FIXUP_FZF_OPTS` | - -Complete loading order of fzf options is: - -1. `FZF_DEFAULT_OPTS` (fzf global) -2. `FORGIT_FZF_DEFAULT_OPTS` (forgit global) -3. `FORGIT_CMD_FZF_OPTS` (command specific) - -Examples: - -- `ctrl-d` to drop the selected stash but do not quit fzf (`gss` specific). -``` -FORGIT_STASH_FZF_OPTS=' ---bind="ctrl-d:reload(git stash drop $(cut -d: -f1 <<<{}) 1>/dev/null && git stash list)" -' -``` - -- `ctrl-e` to view the logs in a vim buffer (`glo` specific). -``` -FORGIT_LOG_FZF_OPTS=' ---bind="ctrl-e:execute(echo {} |grep -Eo [a-f0-9]+ |head -1 |xargs git show |vim -)" -' -``` -#### other options - -| Option | Description | Default | -|---------------------|----------------|----------------------------------------------| -| `FORGIT_LOG_FORMAT` | git log format | `%C(auto)%h%d %s %C(black)%C(bold)%cr%Creset` | - -### 📦 Optional dependencies - -- [`delta`](https://github.com/dandavison/delta) / [`diff-so-fancy`](https://github.com/so-fancy/diff-so-fancy): For better human readable diffs. - -- [`bat`](https://github.com/sharkdp/bat.git): Syntax highlighting for `gitignore`. - -- [`emoji-cli`](https://github.com/wfxr/emoji-cli): Emoji support for `git log`. - -### 💡 Tips - -- Most of the commands accept optional arguments (eg, `glo develop`, `glo f738479..188a849b -- main.go`, `gco master`). -- `gd` supports specifying revision(eg, `gd HEAD~`, `gd v1.0 README.md`). -- Call `gi` with arguments to get the wanted `.gitignore` contents directly(eg, `gi cmake c++`). -- You can use the commands as sub-commands of `git`, see [#147](https://github.com/wfxr/forgit/issues/147) for details. - -### 📃 License - -[MIT](https://wfxr.mit-license.org/2017) (c) Wenxuan Zhang diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index 2ea5215..4340745 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -62,18 +62,24 @@ function forgit::log -d "git commit viewer" end ## git diff viewer -function forgit::diff -d "git diff viewer" +function forgit::diff -d "git diff viewer" --argument-names arg1 arg2 forgit::inside_work_tree || return 1 - if count $argv > /dev/null - if git rev-parse "$argv[1]" > /dev/null 2>&1 - set commit "$argv[1]" && set files "$argv[2..]" + if test -n "$arg1" + # If this first arg is a commit hash + if git rev-parse "$arg1" > /dev/null 2>&1 + if git rev-parse "$arg2" > /dev/null 2>&1 + set commits "$arg1 $arg2" && set files "$argv[3..-1]" + else + set commits "$arg1" && set files "$argv[2..-1]" + end else set files "$argv" end end set repo (git rev-parse --show-toplevel) - set preview "echo {} |sed 's/.*] //' | xargs -I% git diff --color=always $commit -- '$repo/%' | $forgit_diff_pager" + set preview "echo {} | sed 's/.*] *//' | sed 's/ -> / /' | xargs -I% git diff --color=always $commits -- '$repo/%' | $forgit_diff_pager" + set opts " $FORGIT_FZF_DEFAULT_OPTS +m -0 --bind=\"enter:execute($preview |env LESS='-r' less)\" @@ -81,7 +87,10 @@ function forgit::diff -d "git diff viewer" $FORGIT_DIFF_FZF_OPTS " - eval "git diff --name-only $commit -- $files*| sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/'" | env FZF_DEFAULT_OPTS="$opts" fzf + eval git diff --name-only $commit -- $files* | + sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/' | + sed 's/\t/ -> /2' | expand -t 8 | + env FZF_DEFAULT_OPTS="$opts" fzf end # git add selector From b98722008c9e339e3c5a16f278fab90d94172162 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 09:35:51 -0700 Subject: [PATCH 12/14] Revert "Added multi diff support for gd" This reverts commit 5b31faf7e2ea7d8e688a83c16969b6c00dc05dba. --- README.md | 276 ++++++++++++++++++++++++++++++++++++++ conf.d/forgit.plugin.fish | 21 +-- 2 files changed, 282 insertions(+), 15 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a9845e --- /dev/null +++ b/README.md @@ -0,0 +1,276 @@ +

💤 forgit

+

+ Utility tool for using git interactively. Powered by junegunn/fzf. +

+ +

+ + + + + + + + + + + + + + pre-commit + + + Contributors + +

+ +This tool is designed to help you use git more efficiently. +It's **lightweight** and **easy to use**. + +### 📥 Installation + +*Make sure you have [`fzf`](https://github.com/junegunn/fzf) installed.* + +``` zsh +# for zplug +zplug 'wfxr/forgit' + +# for zgen +zgen load 'wfxr/forgit' + +# for antigen +antigen bundle 'wfxr/forgit' + +# for fisher +fisher install wfxr/forgit + +# for omf +omf install https://github.com/wfxr/forgit + +# for zinit +zinit load wfxr/forgit + +# manually +# Clone the repository and source it in your shell's rc file. +``` + +You can run the following command to try `forgit` without installing: + +``` bash +# for bash / zsh +source <(curl -sSL git.io/forgit) +# for fish +source (curl -sSL git.io/forgit-fish | psub) +``` + +### 📝 Features + +- **Interactive `git add` selector** (`ga`) + +![screenshot](https://raw.githubusercontent.com/wfxr/i/master/forgit-ga.png) + +- **Interactive `git log` viewer** (`glo`) + +![screenshot](https://raw.githubusercontent.com/wfxr/i/master/forgit-glo.png) + +*The log graph can be disabled by option `FORGIT_LOG_GRAPH_ENABLE` (see discuss in [issue #71](https://github.com/wfxr/forgit/issues/71)).* + +- **Interactive `.gitignore` generator** (`gi`) + +![screenshot](https://raw.githubusercontent.com/wfxr/i/master/forgit-gi.png) + +- **Interactive `git diff` viewer** (`gd`) + +- **Interactive `git reset HEAD ` selector** (`grh`) + +- **Interactive `git checkout ` selector** (`gcf`) + +- **Interactive `git checkout ` selector** (`gcb`) + +- **Interactive `git checkout ` selector** (`gct`) + +- **Interactive `git checkout ` selector** (`gco`) + +- **Interactive `git revert ` selector** (`grc`) + +- **Interactive `git stash` viewer** (`gss`) + +- **Interactive `git clean` selector** (`gclean`) + +- **Interactive `git cherry-pick` selector** (`gcp`) + +- **Interactive `git rebase -i` selector** (`grb`) + +- **Interactive `git commit --fixup && git rebase -i --autosquash` selector** (`gfu`) + +### ⌨ Keybinds + +| Key | Action | +| :-------------------------------------------: | ------------------------- | +| Enter | Confirm | +| Tab | Toggle mark and move up | +| Shift - Tab | Toggle mark and move down | +| ? | Toggle preview window | +| Alt - W | Toggle preview wrap | +| Ctrl - S | Toggle sort | +| Ctrl - R | Toggle selection | +| Ctrl - Y | Copy commit hash* | +| Ctrl - K / P | Selection move up | +| Ctrl - J / N | Selection move down | +| Alt - K / P | Preview move up | +| Alt - J / N | Preview move down | + +\* Available when the selection contains a commit hash. +For linux users `FORGIT_COPY_CMD` should be set to make copy work. Example: `FORGIT_COPY_CMD='xclip -selection clipboard'`. + +### ⚙ Options + +#### aliases + +##### shell + +You can change the default aliases by defining these variables below. +(To disable all aliases, Set the `FORGIT_NO_ALIASES` flag.) + +``` bash +forgit_log=glo +forgit_diff=gd +forgit_add=ga +forgit_reset_head=grh +forgit_ignore=gi +forgit_checkout_file=gcf +forgit_checkout_branch=gcb +forgit_checkout_tag=gct +forgit_checkout_commit=gco +forgit_revert_commit=grc +forgit_clean=gclean +forgit_stash_show=gss +forgit_cherry_pick=gcp +forgit_rebase=grb +forgit_fixup=gfu +``` + +#### git + +You can use git aliases by making `git-forgit` available in `$PATH`: + +```sh +# after `forgit` was loaded +export PATH="$PATH:$FORGIT_INSTALL_DIR/bin" +``` + +*Some plugin managers can help do this.* + +Then any forgit command will be a subcommand of git: + +``` +$ git forgit log +$ git forgit add +$ git forgit diff +``` + +Optionally you can add [aliases in git](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases): + +```sh +git config --global alias.cf 'forgit checkout_file' +``` + +And use the alias in git: + +```sh +git cf +``` + +#### pagers + +Forgit will use the default configured pager from git (`core.pager`, +`pager.show`, `pager.diff`) but can be altered with the following environment +variables: + +| Use case | Option | Fallbacks to | +| ------------ | ------------------- | -------------------------------------------- | +| common pager | `FORGIT_PAGER` | `git config core.pager` _or_ `cat` | +| pager on `git show` | `FORGIT_SHOW_PAGER` | `git config pager.show` _or_ `$FORGIT_PAGER` | +| pager on `git diff` | `FORGIT_DIFF_PAGER` | `git config pager.diff` _or_ `$FORGIT_PAGER` | +| pager on `gitignore` | `FORGIT_IGNORE_PAGER` | `bat -l gitignore --color always` _or_ `cat` | +| git log format | `FORGIT_GLO_FORMAT` | `%C(auto)%h%d %s %C(black)%C(bold)%cr%reset` | + +#### fzf options + +You can add default fzf options for `forgit`, including keybinds, layout, etc. +(No need to repeat the options already defined in `FZF_DEFAULT_OPTS`) + +``` bash +FORGIT_FZF_DEFAULT_OPTS=" +--exact +--border +--cycle +--reverse +--height '80%' +" +``` + +Customizing fzf options for each command individually is also supported: + +| Command | Option | +|----------|-----------------------------------| +| `ga` | `FORGIT_ADD_FZF_OPTS` | +| `glo` | `FORGIT_LOG_FZF_OPTS` | +| `gi` | `FORGIT_IGNORE_FZF_OPTS` | +| `gd` | `FORGIT_DIFF_FZF_OPTS` | +| `grh` | `FORGIT_RESET_HEAD_FZF_OPTS` | +| `gcf` | `FORGIT_CHECKOUT_FILE_FZF_OPTS` | +| `gcb` | `FORGIT_CHECKOUT_BRANCH_FZF_OPTS` | +| `gct` | `FORGIT_CHECKOUT_TAG_FZF_OPTS` | +| `gco` | `FORGIT_CHECKOUT_COMMIT_FZF_OPTS` | +| `grc` | `FORGIT_REVERT_COMMIT_OPTS` | +| `gss` | `FORGIT_STASH_FZF_OPTS` | +| `gclean` | `FORGIT_CLEAN_FZF_OPTS` | +| `grb` | `FORGIT_REBASE_FZF_OPTS` | +| `gfu` | `FORGIT_FIXUP_FZF_OPTS` | + +Complete loading order of fzf options is: + +1. `FZF_DEFAULT_OPTS` (fzf global) +2. `FORGIT_FZF_DEFAULT_OPTS` (forgit global) +3. `FORGIT_CMD_FZF_OPTS` (command specific) + +Examples: + +- `ctrl-d` to drop the selected stash but do not quit fzf (`gss` specific). +``` +FORGIT_STASH_FZF_OPTS=' +--bind="ctrl-d:reload(git stash drop $(cut -d: -f1 <<<{}) 1>/dev/null && git stash list)" +' +``` + +- `ctrl-e` to view the logs in a vim buffer (`glo` specific). +``` +FORGIT_LOG_FZF_OPTS=' +--bind="ctrl-e:execute(echo {} |grep -Eo [a-f0-9]+ |head -1 |xargs git show |vim -)" +' +``` +#### other options + +| Option | Description | Default | +|---------------------|----------------|----------------------------------------------| +| `FORGIT_LOG_FORMAT` | git log format | `%C(auto)%h%d %s %C(black)%C(bold)%cr%Creset` | + +### 📦 Optional dependencies + +- [`delta`](https://github.com/dandavison/delta) / [`diff-so-fancy`](https://github.com/so-fancy/diff-so-fancy): For better human readable diffs. + +- [`bat`](https://github.com/sharkdp/bat.git): Syntax highlighting for `gitignore`. + +- [`emoji-cli`](https://github.com/wfxr/emoji-cli): Emoji support for `git log`. + +### 💡 Tips + +- Most of the commands accept optional arguments (eg, `glo develop`, `glo f738479..188a849b -- main.go`, `gco master`). +- `gd` supports specifying revision(eg, `gd HEAD~`, `gd v1.0 README.md`). +- Call `gi` with arguments to get the wanted `.gitignore` contents directly(eg, `gi cmake c++`). +- You can use the commands as sub-commands of `git`, see [#147](https://github.com/wfxr/forgit/issues/147) for details. + +### 📃 License + +[MIT](https://wfxr.mit-license.org/2017) (c) Wenxuan Zhang diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index 4340745..2ea5215 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -62,24 +62,18 @@ function forgit::log -d "git commit viewer" end ## git diff viewer -function forgit::diff -d "git diff viewer" --argument-names arg1 arg2 +function forgit::diff -d "git diff viewer" forgit::inside_work_tree || return 1 - if test -n "$arg1" - # If this first arg is a commit hash - if git rev-parse "$arg1" > /dev/null 2>&1 - if git rev-parse "$arg2" > /dev/null 2>&1 - set commits "$arg1 $arg2" && set files "$argv[3..-1]" - else - set commits "$arg1" && set files "$argv[2..-1]" - end + if count $argv > /dev/null + if git rev-parse "$argv[1]" > /dev/null 2>&1 + set commit "$argv[1]" && set files "$argv[2..]" else set files "$argv" end end set repo (git rev-parse --show-toplevel) - set preview "echo {} | sed 's/.*] *//' | sed 's/ -> / /' | xargs -I% git diff --color=always $commits -- '$repo/%' | $forgit_diff_pager" - + set preview "echo {} |sed 's/.*] //' | xargs -I% git diff --color=always $commit -- '$repo/%' | $forgit_diff_pager" set opts " $FORGIT_FZF_DEFAULT_OPTS +m -0 --bind=\"enter:execute($preview |env LESS='-r' less)\" @@ -87,10 +81,7 @@ function forgit::diff -d "git diff viewer" --argument-names arg1 arg2 $FORGIT_DIFF_FZF_OPTS " - eval git diff --name-only $commit -- $files* | - sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/' | - sed 's/\t/ -> /2' | expand -t 8 | - env FZF_DEFAULT_OPTS="$opts" fzf + eval "git diff --name-only $commit -- $files*| sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/'" | env FZF_DEFAULT_OPTS="$opts" fzf end # git add selector From c096f2bbda26835cc133f2f0658ff7bba48c11df Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 09:36:11 -0700 Subject: [PATCH 13/14] Added multi diff support for gd --- conf.d/forgit.plugin.fish | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index 2ea5215..4340745 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -62,18 +62,24 @@ function forgit::log -d "git commit viewer" end ## git diff viewer -function forgit::diff -d "git diff viewer" +function forgit::diff -d "git diff viewer" --argument-names arg1 arg2 forgit::inside_work_tree || return 1 - if count $argv > /dev/null - if git rev-parse "$argv[1]" > /dev/null 2>&1 - set commit "$argv[1]" && set files "$argv[2..]" + if test -n "$arg1" + # If this first arg is a commit hash + if git rev-parse "$arg1" > /dev/null 2>&1 + if git rev-parse "$arg2" > /dev/null 2>&1 + set commits "$arg1 $arg2" && set files "$argv[3..-1]" + else + set commits "$arg1" && set files "$argv[2..-1]" + end else set files "$argv" end end set repo (git rev-parse --show-toplevel) - set preview "echo {} |sed 's/.*] //' | xargs -I% git diff --color=always $commit -- '$repo/%' | $forgit_diff_pager" + set preview "echo {} | sed 's/.*] *//' | sed 's/ -> / /' | xargs -I% git diff --color=always $commits -- '$repo/%' | $forgit_diff_pager" + set opts " $FORGIT_FZF_DEFAULT_OPTS +m -0 --bind=\"enter:execute($preview |env LESS='-r' less)\" @@ -81,7 +87,10 @@ function forgit::diff -d "git diff viewer" $FORGIT_DIFF_FZF_OPTS " - eval "git diff --name-only $commit -- $files*| sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/'" | env FZF_DEFAULT_OPTS="$opts" fzf + eval git diff --name-only $commit -- $files* | + sed -E 's/^(.)[[:space:]]+(.*)\$/[\1] \2/' | + sed 's/\t/ -> /2' | expand -t 8 | + env FZF_DEFAULT_OPTS="$opts" fzf end # git add selector From b61df0c2061d9db47cb6bce34a46fea460bb2605 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 21 Mar 2022 09:49:00 -0700 Subject: [PATCH 14/14] Added support for FORGIT_GLO_FORMAT --- conf.d/forgit.plugin.fish | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index 4340745..dbf13a5 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -51,13 +51,19 @@ function forgit::log -d "git commit viewer" $FORGIT_LOG_FZF_OPTS " + if test -n "$FORGIT_GLO_FORMAT" + set log_format "$FORGIT_GLO_FORMAT" + else + set log_format "$forgit_log_format" + end + if set -q FORGIT_LOG_GRAPH_ENABLE set graph "--graph" else set graph "" end - eval "git log $graph --color=always --format='$forgit_log_format' $argv $forgit_emojify" | + eval "git log $graph --color=always --format='$log_format' $argv $forgit_emojify" | env FZF_DEFAULT_OPTS="$opts" fzf end @@ -80,6 +86,7 @@ function forgit::diff -d "git diff viewer" --argument-names arg1 arg2 set repo (git rev-parse --show-toplevel) set preview "echo {} | sed 's/.*] *//' | sed 's/ -> / /' | xargs -I% git diff --color=always $commits -- '$repo/%' | $forgit_diff_pager" + set opts " $FORGIT_FZF_DEFAULT_OPTS +m -0 --bind=\"enter:execute($preview |env LESS='-r' less)\"