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

Move fzf options into $opts variables #384

Merged
merged 1 commit into from
Apr 19, 2024
Merged
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
19 changes: 11 additions & 8 deletions bin/git-forgit
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,15 @@ _forgit_stash_push() {
opts="
$FORGIT_FZF_DEFAULT_OPTS
-m
--preview=\"$FORGIT stash_push_preview {}\"
$FORGIT_STASH_PUSH_FZF_OPTS
"
# Show both modified and untracked files
files=()
while IFS='' read -r file; do
files+=("$file")
done < <(git ls-files --exclude-standard --modified --others |
FZF_DEFAULT_OPTS="$opts" fzf --preview="$FORGIT stash_push_preview {}")
FZF_DEFAULT_OPTS="$opts" fzf)
[[ "${#files[@]}" -eq 0 ]] && return 1
_forgit_git_stash_push ${msg:+-m "$msg"} -u "${files[@]}"
}
Expand Down Expand Up @@ -820,8 +821,9 @@ _forgit_revert_commit() {

opts="
$FORGIT_FZF_DEFAULT_OPTS
+s --tiebreak=index
-m +s --tiebreak=index
--ansi --with-nth 2..
--preview=\"$FORGIT revert_preview {}\"
$FORGIT_REVERT_COMMIT_FZF_OPTS
"

Expand All @@ -837,7 +839,7 @@ _forgit_revert_commit() {
git log --graph --color=always --format="$_forgit_log_format" |
_forgit_emojify |
nl |
FZF_DEFAULT_OPTS="$opts" fzf --preview="$FORGIT revert_preview {}" -m |
FZF_DEFAULT_OPTS="$opts" fzf |
sort -n -k 1 |
cut -f2- |
sed 's/^[^a-f^0-9]*\([a-f0-9]*\).*/\1/')
Expand Down Expand Up @@ -868,17 +870,18 @@ _forgit_blame() {
_forgit_inside_work_tree || return 1
local opts flags file
_forgit_contains_non_flags "$@" && { _forgit_git_blame "$@"; return $?; }
opts="
$FORGIT_FZF_DEFAULT_OPTS
$FORGIT_BLAME_FZF_OPTS
"
flags=()
while IFS='' read -r flag; do
flags+=("$flag")
done < <(git rev-parse --flags "$@")
opts="
$FORGIT_FZF_DEFAULT_OPTS
--preview=\"$FORGIT blame_preview {} ${flags[*]}\"
$FORGIT_BLAME_FZF_OPTS
"
# flags is not quoted here, which is fine given that they are retrieved
# with git rev-parse and can only contain flags
file=$(FZF_DEFAULT_OPTS="$opts" fzf --preview="$FORGIT blame_preview {} ${flags[*]}")
file=$(FZF_DEFAULT_OPTS="$opts" fzf)
[[ -z "$file" ]] && return 1
_forgit_git_blame "$file" "${flags[@]}"
}
Expand Down