From 5306146aa10e7b3e9c7f8e419beff7989d7fd2cb Mon Sep 17 00:00:00 2001 From: sandroid Date: Tue, 9 Apr 2024 23:12:19 +0200 Subject: [PATCH 1/3] Add a preview to _forgit_clean --- bin/git-forgit | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/git-forgit b/bin/git-forgit index 237a5edb..d084ccb9 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -470,6 +470,12 @@ _forgit_stash_push() { _forgit_git_stash_push ${msg:+-m "$msg"} -u "${files[@]}" } +_forgit_clean_preview() { + local file + file=$1 + git diff --color=always /dev/null "$file" | _forgit_pager diff +} + # git clean selector _forgit_clean() { _forgit_inside_work_tree || return 1 @@ -479,6 +485,7 @@ _forgit_clean() { _forgit_parse_array _forgit_clean_git_opts "$FORGIT_CLEAN_GIT_OPTS" opts=" $FORGIT_FZF_DEFAULT_OPTS + --preview=\"$FORGIT clean_preview {}\" -m -0 $FORGIT_CLEAN_FZF_OPTS " @@ -975,6 +982,7 @@ private_commands=( "checkout_file_preview" "cherry_pick_from_branch_preview" "cherry_pick_preview" + "clean_preview" "diff_enter" "file_preview" "ignore_preview" From a5eaff2faaedd00005e0e99d62bfc90653559e25 Mon Sep 17 00:00:00 2001 From: sandroid Date: Wed, 10 Apr 2024 22:45:17 +0200 Subject: [PATCH 2/3] Fix gclean preview for directories --- bin/git-forgit | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index d084ccb9..48b02b32 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -471,9 +471,17 @@ _forgit_stash_push() { } _forgit_clean_preview() { - local file - file=$1 - git diff --color=always /dev/null "$file" | _forgit_pager diff + local path + path=$1 + if [[ -d "$path" ]]; then + if hash tree &> /dev/null; then + tree "$path" + else + find "$path" + fi + else + git diff --color=always /dev/null "$path" | _forgit_pager diff + fi } # git clean selector From e2b03ea7c0a54a2d820d6c1036a178b671f9d8e3 Mon Sep 17 00:00:00 2001 From: sandroid Date: Sat, 13 Apr 2024 21:21:38 +0200 Subject: [PATCH 3/3] Allow overriding dir view with a variable --- README.md | 1 + bin/git-forgit | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1da2af8f..a6437add 100644 --- a/README.md +++ b/README.md @@ -335,6 +335,7 @@ export FORGIT_LOG_FZF_OPTS=' | `FORGIT_LOG_FORMAT` | git log format | `%C(auto)%h%d %s %C(black)%C(bold)%cr%Creset` | | `FORGIT_PREVIEW_CONTEXT` | lines of diff context in preview mode | 3 | | `FORGIT_FULLSCREEN_CONTEXT` | lines of diff context in fullscreen mode | 10 | +| `FORGIT_DIR_VIEW` | command used to preview directories | `tree` if available, otherwise `find` | # 📦 Optional dependencies diff --git a/bin/git-forgit b/bin/git-forgit index 48b02b32..f229a04e 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -132,6 +132,7 @@ _forgit_log_format=${FORGIT_LOG_FORMAT:-%C(auto)%h%d %s %C(black)%C(bold)%cr%Cre _forgit_log_preview_options=("--graph" "--pretty=format:$_forgit_log_format" "--color=always" "--abbrev-commit" "--date=relative") _forgit_fullscreen_context=${FORGIT_FULLSCREEN_CONTEXT:-10} _forgit_preview_context=${FORGIT_PREVIEW_CONTEXT:-3} +_forgit_dir_view=${FORGIT_DIR_VIEW:-$(hash tree &> /dev/null && echo 'tree' || echo 'find')} _forgit_pager() { local pager @@ -474,11 +475,7 @@ _forgit_clean_preview() { local path path=$1 if [[ -d "$path" ]]; then - if hash tree &> /dev/null; then - tree "$path" - else - find "$path" - fi + eval "$_forgit_dir_view \"$path\"" else git diff --color=always /dev/null "$path" | _forgit_pager diff fi