Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a preview to _forgit_clean #383

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions bin/git-forgit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -470,6 +471,16 @@ _forgit_stash_push() {
_forgit_git_stash_push ${msg:+-m "$msg"} -u "${files[@]}"
}

_forgit_clean_preview() {
local path
path=$1
if [[ -d "$path" ]]; then
eval "$_forgit_dir_view \"$path\""
else
git diff --color=always /dev/null "$path" | _forgit_pager diff
fi
}

# git clean selector
_forgit_clean() {
_forgit_inside_work_tree || return 1
Expand All @@ -479,6 +490,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
"
Expand Down Expand Up @@ -975,6 +987,7 @@ private_commands=(
"checkout_file_preview"
"cherry_pick_from_branch_preview"
"cherry_pick_preview"
"clean_preview"
"diff_enter"
"file_preview"
"ignore_preview"
Expand Down