From 958e26add5d9b94e10dc329810203ba00e75a0b1 Mon Sep 17 00:00:00 2001 From: sandroid Date: Thu, 2 Jun 2022 23:22:41 +0200 Subject: [PATCH 1/3] Added gb --- README.md | 19 ++++++++++++------- forgit.plugin.zsh | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9676ae1..817b9d9 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,8 @@ source (curl -sSL git.io/forgit-fish | psub) - **Interactive `git rebase -i` selector** (`grb`) +- **Interactive `git blame` selector** (`gb`) + - **Interactive `git commit --fixup && git rebase -i --autosquash` selector** (`gfu`) ### ⌨ Keybinds @@ -150,6 +152,7 @@ forgit_clean=gclean forgit_stash_show=gss forgit_cherry_pick=gcp forgit_rebase=grb +forgit_blame=gb forgit_fixup=gfu ``` @@ -190,13 +193,14 @@ 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` | +| 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 `git blame` | `FORGIT_BLAME_PAGER` | `git config pager.blame` _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 @@ -231,6 +235,7 @@ Customizing fzf options for each command individually is also supported: | `gss` | `FORGIT_STASH_FZF_OPTS` | | `gclean` | `FORGIT_CLEAN_FZF_OPTS` | | `grb` | `FORGIT_REBASE_FZF_OPTS` | +| `gb` | `FORGIT_BLAME_FZF_OPTS` | | `gfu` | `FORGIT_FIXUP_FZF_OPTS` | Complete loading order of fzf options is: diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 0c4876e..35e8913 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -11,6 +11,7 @@ forgit_pager=${FORGIT_PAGER:-$(git config core.pager || echo 'cat')} forgit_show_pager=${FORGIT_SHOW_PAGER:-$(git config pager.show || echo "$forgit_pager")} forgit_diff_pager=${FORGIT_DIFF_PAGER:-$(git config pager.diff || echo "$forgit_pager")} forgit_ignore_pager=${FORGIT_IGNORE_PAGER:-$(hash bat &>/dev/null && echo 'bat -l gitignore --color=always' || echo 'cat')} +forgit_blame_pager=${FORGIT_BLAME_PAGER:-$(git config pager.blame || echo "$forgit_pager")} forgit_log_format=${FORGIT_LOG_FORMAT:-%C(auto)%h%d %s %C(black)%C(bold)%cr%Creset} @@ -336,6 +337,22 @@ forgit::revert::commit() { done } +# git blame viewer +forgit::blame() { + forgit::inside_work_tree || return 1 + [[ $# -ne 0 ]] && git blame "$@" && return 0 + local opts flags preview file + opts=" + $FORGIT_FZF_DEFAULT_OPTS + $FORGIT_BLAME_FZF_OPTS + " + flags=$(git rev-parse --flags "$@") + preview="git blame {1} --date=short $flags | $forgit_blame_pager" + file=$(FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview") + [[ -z "$file" ]] && return 1 + eval git blame "$file" "$flags" +} + # 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}" @@ -419,6 +436,7 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then alias "${forgit_cherry_pick:-gcp}"='forgit::cherry::pick' alias "${forgit_rebase:-grb}"='forgit::rebase' alias "${forgit_fixup:-gfu}"='forgit::fixup' + alias "${forgit_blame:-gb}"='forgit::blame' fi # set installation path (for use by `bin/git-forgit`) From 2d3dd568bb4803d680089c53c524900da72e3069 Mon Sep 17 00:00:00 2001 From: sandroid Date: Fri, 3 Jun 2022 23:24:40 +0200 Subject: [PATCH 2/3] gb: handle untracked files --- forgit.plugin.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 35e8913..0967f5b 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -347,7 +347,13 @@ forgit::blame() { $FORGIT_BLAME_FZF_OPTS " flags=$(git rev-parse --flags "$@") - preview="git blame {1} --date=short $flags | $forgit_blame_pager" + preview=" + if (git ls-files {} --error-unmatch) &>/dev/null; then + git blame {} --date=short $flags | $forgit_blame_pager + else + echo File not tracked + fi + " file=$(FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview") [[ -z "$file" ]] && return 1 eval git blame "$file" "$flags" From f8b1fc85450e5b9fdd9e8de30c30b7a9fafde49e Mon Sep 17 00:00:00 2001 From: sandroid Date: Thu, 16 Jun 2022 22:34:13 +0200 Subject: [PATCH 3/3] Changed alias for forgit::blame to gbl --- README.md | 6 +++--- forgit.plugin.zsh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 817b9d9..f40afab 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ source (curl -sSL git.io/forgit-fish | psub) - **Interactive `git rebase -i` selector** (`grb`) -- **Interactive `git blame` selector** (`gb`) +- **Interactive `git blame` selector** (`gbl`) - **Interactive `git commit --fixup && git rebase -i --autosquash` selector** (`gfu`) @@ -152,7 +152,7 @@ forgit_clean=gclean forgit_stash_show=gss forgit_cherry_pick=gcp forgit_rebase=grb -forgit_blame=gb +forgit_blame=gbl forgit_fixup=gfu ``` @@ -235,7 +235,7 @@ Customizing fzf options for each command individually is also supported: | `gss` | `FORGIT_STASH_FZF_OPTS` | | `gclean` | `FORGIT_CLEAN_FZF_OPTS` | | `grb` | `FORGIT_REBASE_FZF_OPTS` | -| `gb` | `FORGIT_BLAME_FZF_OPTS` | +| `gbl` | `FORGIT_BLAME_FZF_OPTS` | | `gfu` | `FORGIT_FIXUP_FZF_OPTS` | Complete loading order of fzf options is: diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 0967f5b..694c0bd 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -442,7 +442,7 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then alias "${forgit_cherry_pick:-gcp}"='forgit::cherry::pick' alias "${forgit_rebase:-grb}"='forgit::rebase' alias "${forgit_fixup:-gfu}"='forgit::fixup' - alias "${forgit_blame:-gb}"='forgit::blame' + alias "${forgit_blame:-gbl}"='forgit::blame' fi # set installation path (for use by `bin/git-forgit`)