AutoYADM commit: 2025-06-03 13:00:14
This commit is contained in:
parent
f4d51acdfb
commit
b81120710b
7 changed files with 75 additions and 15 deletions
|
@ -28,10 +28,6 @@ if [[ "$higher_fzf_version" != "$installed_fzf_version" ]]; then
|
|||
fi
|
||||
|
||||
# Set shell for fzf preview commands
|
||||
# Disable shellcheck for "which", because it suggests "command -v xxx" instead,
|
||||
# which is not a working replacement.
|
||||
# See https://github.com/koalaman/shellcheck/issues/1162
|
||||
# shellcheck disable=2230
|
||||
SHELL="$(which bash)"
|
||||
export SHELL
|
||||
|
||||
|
@ -759,25 +755,64 @@ _forgit_file_preview() {
|
|||
_forgit_fixup() {
|
||||
_forgit_inside_work_tree || return 1
|
||||
git diff --cached --quiet && echo 'Nothing to fixup: there are no staged changes.' && return 1
|
||||
local opts graph quoted_files target_commit prev_commit
|
||||
_forgit_edit_commit --fixup "$FORGIT_FIXUP_FZF_OPTS" "$FORGIT_FIXUP_GIT_OPTS"
|
||||
}
|
||||
|
||||
_forgit_squash() {
|
||||
_forgit_inside_work_tree || return 1
|
||||
git diff --cached --quiet && echo 'Nothing to squash: there are no staged changes.' && return 1
|
||||
_forgit_edit_commit --squash "$FORGIT_SQUASH_FZF_OPTS" "$FORGIT_SQUASH_GIT_OPTS"
|
||||
}
|
||||
|
||||
_forgit_edit_commit() {
|
||||
local action fzf_opts opts graph target_commit prev_commit
|
||||
action=$1
|
||||
fzf_opts=$2
|
||||
graph=()
|
||||
[[ $_forgit_log_graph_enable == true ]] && graph=(--graph)
|
||||
_forgit_fixup_git_opts=()
|
||||
_forgit_parse_array _forgit_fixup_git_opts "$FORGIT_FIXUP_GIT_OPTS"
|
||||
quoted_files=$(_forgit_quote_files "$@")
|
||||
git_opts=()
|
||||
_forgit_parse_array git_opts "$3"
|
||||
opts="
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
+s +m --tiebreak=index
|
||||
--bind=\"ctrl-y:execute-silent($FORGIT yank_sha {})\"
|
||||
--preview=\"$FORGIT file_preview {} $quoted_files\"
|
||||
$FORGIT_FIXUP_FZF_OPTS
|
||||
--preview=\"$FORGIT file_preview {}\"
|
||||
$fzf_opts
|
||||
"
|
||||
target_commit=$(
|
||||
git log "${graph[@]}" --color=always --format="$_forgit_log_format" "$@" |
|
||||
git log "${graph[@]}" --color=always --format="$_forgit_log_format" |
|
||||
_forgit_emojify |
|
||||
FZF_DEFAULT_OPTS="$opts" fzf |
|
||||
_forgit_extract_sha)
|
||||
if [[ -n "$target_commit" ]] && git commit "${_forgit_fixup_git_opts[@]}" --fixup "$target_commit"; then
|
||||
# GIT_EDITOR=: is needed to skip the editor
|
||||
if [[ -n "$target_commit" ]] && GIT_EDITOR=: git commit "${git_opts[@]}" "$action" "$target_commit"; then
|
||||
prev_commit=$(_forgit_previous_commit "$target_commit")
|
||||
# rebase will fail if there are unstaged changes so --autostash is needed to temporarily stash them
|
||||
# GIT_SEQUENCE_EDITOR=: is needed to skip the editor
|
||||
GIT_SEQUENCE_EDITOR=: git rebase --autostash -i --autosquash "$prev_commit"
|
||||
fi
|
||||
}
|
||||
|
||||
_forgit_reword() {
|
||||
_forgit_inside_work_tree || return 1
|
||||
local opts graph quoted_files target_commit prev_commit
|
||||
graph=()
|
||||
[[ $_forgit_log_graph_enable == true ]] && graph=(--graph)
|
||||
git_opts=()
|
||||
_forgit_parse_array _forgit_reword_git_opts "$FORGIT_REWORD_GIT_OPTS"
|
||||
opts="
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
+s +m --tiebreak=index
|
||||
--bind=\"ctrl-y:execute-silent($FORGIT yank_sha {})\"
|
||||
--preview=\"$FORGIT file_preview {}\"
|
||||
$FORGIT_REWORD_FZF_OPTS
|
||||
"
|
||||
target_commit=$(
|
||||
git log "${graph[@]}" --color=always --format="$_forgit_log_format" |
|
||||
_forgit_emojify |
|
||||
FZF_DEFAULT_OPTS="$opts" fzf |
|
||||
_forgit_extract_sha)
|
||||
if [[ -n "$target_commit" ]] && git commit "${git_opts[@]}" --fixup=reword:"$target_commit"; then
|
||||
prev_commit=$(_forgit_previous_commit "$target_commit")
|
||||
# rebase will fail if there are unstaged changes so --autostash is needed to temporarily stash them
|
||||
# GIT_SEQUENCE_EDITOR=: is needed to skip the editor
|
||||
|
@ -1152,6 +1187,8 @@ public_commands=(
|
|||
"clean"
|
||||
"diff"
|
||||
"fixup"
|
||||
"squash"
|
||||
"reword"
|
||||
"ignore"
|
||||
"log"
|
||||
"reflog"
|
||||
|
|
|
@ -49,6 +49,8 @@ if test -z "$FORGIT_NO_ALIASES"
|
|||
abbr -a -- (string collect $forgit_cherry_pick; or string collect "gcp") git-forgit cherry_pick_from_branch
|
||||
abbr -a -- (string collect $forgit_rebase; or string collect "grb") git-forgit rebase
|
||||
abbr -a -- (string collect $forgit_fixup; or string collect "gfu") git-forgit fixup
|
||||
abbr -a -- (string collect $forgit_squash; or string collect "gsq") git-forgit squash
|
||||
abbr -a -- (string collect $forgit_reword; or string collect "grw") git-forgit reword
|
||||
abbr -a -- (string collect $forgit_checkout_commit; or string collect "gco") git-forgit checkout_commit
|
||||
abbr -a -- (string collect $forgit_revert_commit; or string collect "grc") git-forgit revert_commit
|
||||
abbr -a -- (string collect $forgit_blame; or string collect "gbl") git-forgit blame
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue