🔧 chore(fish): plugin updates

This commit is contained in:
Sergio Laín 2023-10-28 00:25:25 +02:00
parent 673373045b
commit fe88d487f9
No known key found for this signature in database
GPG key ID: 14C9B8080681777B
3 changed files with 485 additions and 513 deletions

View file

@ -4,3 +4,4 @@ abbr -a t --function projectdo_test
abbr -a p --function projectdo_tool
abbr -a y yadm
abbr -a pse pacseek
abbr -a g git

View file

@ -42,7 +42,7 @@ _forgit_warn() { printf "%b[Warn]%b %s\n" '\e[0;33m' '\e[0m' "$@" >&2; }
_forgit_info() { printf "%b[Info]%b %s\n" '\e[0;32m' '\e[0m' "$@" >&2; }
_forgit_inside_work_tree() { git rev-parse --is-inside-work-tree >/dev/null; }
# tac is not available on OSX, tail -r is not available on Linux, so we use either of them
_forgit_reverse_lines() { tac 2>/dev/null || tail -r; }
_forgit_reverse_lines() { tac 2> /dev/null || tail -r; }
_forgit_previous_commit() {
# "SHA~" is invalid when the commit is the first commit, but we can use "--root" instead
@ -88,17 +88,17 @@ _forgit_is_file_tracked="(git ls-files {} --error-unmatch) &> /dev/null"
_forgit_log() {
_forgit_inside_work_tree || return 1
local opts graph files log_format preview_cmd enter_cmd
files=$(sed -nE 's/.*-- (.*)/\1/p' <<<"$*") # extract files parameters for `git show` command
files=$(sed -nE 's/.*-- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command
preview_cmd="echo {} | $_forgit_extract_sha | xargs -I% git show --color=always -U$_forgit_preview_context % -- $files | $_forgit_show_pager"
enter_cmd="echo {} | $_forgit_extract_sha | xargs -I% ${FORGIT} diff %^! $files"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+s +m --tiebreak=index
--bind=\"enter:execute($enter_cmd)\"
--bind=\"ctrl-y:execute-silent(echo {} | $_forgit_extract_sha | ${FORGIT_COPY_CMD:-pbcopy})\"
--preview=\"$preview_cmd\"
$FORGIT_LOG_FZF_OPTS
"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+s +m --tiebreak=index
--bind=\"enter:execute($enter_cmd)\"
--bind=\"ctrl-y:execute-silent(echo {} | $_forgit_extract_sha | ${FORGIT_COPY_CMD:-pbcopy})\"
--preview=\"$preview_cmd\"
$FORGIT_LOG_FZF_OPTS
"
graph=--graph
[[ $FORGIT_LOG_GRAPH_ENABLE == false ]] && graph=
log_format=${FORGIT_GLO_FORMAT:-$_forgit_log_format}
@ -115,7 +115,7 @@ _forgit_diff() {
_forgit_inside_work_tree || return 1
local files opts commits repo get_files preview_cmd enter_cmd
[[ $# -ne 0 ]] && {
if git rev-parse "$1" -- &>/dev/null; then
if git rev-parse "$1" -- &>/dev/null ; then
if [[ $# -gt 1 ]] && git rev-parse "$2" -- &>/dev/null; then
commits="$1 $2" && files=("${@:3}")
else
@ -138,6 +138,9 @@ _forgit_diff() {
# We have to do a two-step sed -> tr pipe because OSX's sed implementation does
# not support the null-character directly.
get_files="echo {} | sed 's/.*] *//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'"
# Similar to the line above, but only gets a single file from a single line
# Gets the new name of renamed files
get_file="echo {} | sed 's/.*] *//' | sed 's/.*-> //'"
# Git stashes are named "stash@{x}", which contains the fzf placeholder "{x}".
# In order to support passing stashes as arguments to _forgit_diff, we have to
# prevent fzf from interpreting this substring by escaping the opening bracket.
@ -146,14 +149,14 @@ _forgit_diff() {
git_diff="git diff --color=always $FORGIT_DIFF_GIT_OPTS $escaped_commits"
preview_cmd="cd '$repo' && $get_files | xargs -0 $git_diff -U$_forgit_preview_context -- | $_forgit_diff_pager"
enter_cmd="cd '$repo' && $get_files | xargs -0 $git_diff -U$_forgit_fullscreen_context -- | $_forgit_diff_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+m -0 --bind=\"enter:execute($enter_cmd | $_forgit_enter_pager)\"
--preview=\"$preview_cmd\"
--bind=\"alt-e:execute-silent($EDITOR \$\($get_files\) >/dev/tty </dev/tty)+refresh-preview\"
$FORGIT_DIFF_FZF_OPTS
--prompt=\"$commits > \"
"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+m -0 --bind=\"enter:execute($enter_cmd | $_forgit_enter_pager)\"
--preview=\"$preview_cmd\"
--bind=\"alt-e:execute-silent($EDITOR \\\"\$\($get_file)\\\" >/dev/tty </dev/tty)+refresh-preview\"
$FORGIT_DIFF_FZF_OPTS
--prompt=\"$commits > \"
"
eval "git diff --name-status $FORGIT_DIFF_GIT_OPTS $commits -- ${files[*]} | sed -E 's/^([[:alnum:]]+)[[:space:]]+(.*)$/[\1] \2/'" |
sed 's/ / -> /2' | expand -t 8 |
FZF_DEFAULT_OPTS="$opts" fzf
@ -169,32 +172,29 @@ _forgit_add() {
local git_add changed unmerged untracked files opts preview extract
git_add="git add $FORGIT_ADD_GIT_OPTS"
# Add files if passed as arguments
[[ $# -ne 0 ]] && {
$git_add "$@" && git status -su
return $?
}
[[ $# -ne 0 ]] && { $git_add "$@" && git status -su; return $?; }
changed=$(git config --get-color color.status.changed red)
unmerged=$(git config --get-color color.status.unmerged red)
untracked=$(git config --get-color color.status.untracked red)
# NOTE: paths listed by 'git status -su' mixed with quoted and unquoted style
# remove indicators | remove original path for rename case | remove surrounding quotes
extract="
sed 's/^.*] //' |
sed 's/.* -> //' |
sed -e 's/^\\\"//' -e 's/\\\"\$//'"
preview="
file=\$(echo {} | $extract)
if (git status -s -- \\\"\$file\\\" | grep '^??') &>/dev/null; then # diff with /dev/null for untracked files
extract="
sed 's/^.*] //' |
sed 's/.* -> //' |
sed -e 's/^\\\"//' -e 's/\\\"\$//'"
preview="
file=\$(echo {} | $extract)
if (git status -s -- \\\"\$file\\\" | grep '^??') &>/dev/null; then # diff with /dev/null for untracked files
git diff --color=always --no-index -- /dev/null \\\"\$file\\\" | $_forgit_diff_pager | sed '2 s/added:/untracked:/'
else
else
git diff --color=always -- \\\"\$file\\\" | $_forgit_diff_pager
fi"
opts="
$FORGIT_FZF_DEFAULT_OPTS
-0 -m --nth 2..,..
--preview=\"$preview\"
--bind=\"alt-e:execute-silent($EDITOR \$\(echo {} | $extract\) >/dev/tty </dev/tty)+refresh-preview\"
--bind=\"alt-e:execute-silent($EDITOR \\\"\$\(echo {} | $extract\)\\\" >/dev/tty </dev/tty)+refresh-preview\"
$FORGIT_ADD_FZF_OPTS
"
files=$(git -c color.status=always -c status.relativePaths=true status -su |
@ -202,7 +202,7 @@ else
sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1] \2/' |
FZF_DEFAULT_OPTS="$opts" fzf |
sh -c "$extract")
[[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | $git_add --pathspec-file-nul --pathspec-from-file - && git status -su && return
[[ -n "$files" ]] && echo "$files"| tr '\n' '\0' | $git_add --pathspec-file-nul --pathspec-from-file - && git status -su && return
echo 'Nothing to add.'
}
@ -211,10 +211,7 @@ _forgit_reset_head() {
_forgit_inside_work_tree || return 1
local git_reset_head cmd files opts rootdir
git_reset_head="git reset -q $FORGIT_RESET_HEAD_GIT_OPTS HEAD"
[[ $# -ne 0 ]] && {
$git_reset_head "$@" && git status --short
return $?
}
[[ $# -ne 0 ]] && { $git_reset_head "$@" && git status --short; return $?; }
rootdir=$(git rev-parse --show-toplevel)
cmd="git diff --staged --color=always -- $rootdir/{} | $_forgit_diff_pager "
opts="
@ -234,10 +231,7 @@ _forgit_stash_show() {
_forgit_inside_work_tree || return 1
local git_stash_show git_stash_list cmd opts
git_stash_show="git stash show --color=always --ext-diff"
[[ $# -ne 0 ]] && {
$git_stash_show "$@"
return $?
}
[[ $# -ne 0 ]] && { $git_stash_show "$@"; return $?; }
git_stash_list="git stash list $FORGIT_STASH_SHOW_GIT_OPTS"
cmd="echo {} |cut -d: -f1 |xargs -I% $git_stash_show % |$_forgit_diff_pager"
opts="
@ -259,21 +253,18 @@ _forgit_stash_push() {
_forgit_inside_work_tree || return 1
local git_stash_push msg args
git_stash_push="git stash push $FORGIT_STASH_PUSH_GIT_OPTS"
args=("$@")
while (("$#")); do
args=( "$@" )
while (( "$#" )); do
case "$1" in
# allow message as argument
-m | --message)
-m|--message)
msg="$2"
shift 2
;;
# ignore -u as it's used implicitly
-u | --include-untracked) shift ;;
-u|--include-untracked) shift ;;
# pass to git directly when encountering anything else
*)
$git_stash_push "${args[@]}"
return $?
;;
*) $git_stash_push "${args[@]}"; return $?
esac
done
local opts preview files
@ -298,10 +289,7 @@ _forgit_stash_push() {
# git clean selector
_forgit_clean() {
_forgit_inside_work_tree || return 1
_forgit_contains_non_flags "$@" && {
git clean -q "$@"
return $?
}
_forgit_contains_non_flags "$@" && { git clean -q "$@"; return $?; }
local git_clean files opts
git_clean="git clean $FORGIT_CLEAN_GIT_OPTS"
opts="
@ -310,7 +298,7 @@ _forgit_clean() {
$FORGIT_CLEAN_FZF_OPTS
"
# Note: Postfix '/' in directory path should be removed. Otherwise the directory itself will not be removed.
files=$(git clean -xdffn "$@" | sed 's/^Would remove //' | FZF_DEFAULT_OPTS="$opts" fzf | sed 's#/$##')
files=$(git clean -xdffn "$@"| sed 's/^Would remove //' | FZF_DEFAULT_OPTS="$opts" fzf |sed 's#/$##')
# shellcheck disable=2086
[[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | xargs -0 -I% $git_clean -xdff '%' && git status --short && return
echo 'Nothing to clean.'
@ -378,7 +366,8 @@ _forgit_cherry_pick_from_branch() {
"
# loop until either the branch selector is closed or a commit to be cherry
# picked has been selected from within a branch
while true; do
while true
do
if [[ -z $input_branch ]]; then
branch="$(eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf | awk '{print $1}')"
else
@ -402,7 +391,7 @@ _forgit_rebase() {
graph=--graph
[[ $FORGIT_LOG_GRAPH_ENABLE == false ]] && graph=
cmd="git log $graph --color=always --format='$_forgit_log_format' $* $_forgit_emojify"
files=$(sed -nE 's/.* -- (.*)/\1/p' <<<"$*") # extract files parameters for `git show` command
files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command
preview="echo {} | $_forgit_extract_sha | xargs -I% git show --color=always % -- $files | $_forgit_show_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
@ -427,7 +416,7 @@ _forgit_fixup() {
graph=--graph
[[ $FORGIT_LOG_GRAPH_ENABLE == false ]] && graph=
cmd="git log $graph --color=always --format='$_forgit_log_format' $* $_forgit_emojify"
files=$(sed -nE 's/.* -- (.*)/\1/p' <<<"$*")
files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*")
preview="echo {} | $_forgit_extract_sha | xargs -I% git show --color=always % -- $files | $_forgit_show_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
@ -451,10 +440,7 @@ _forgit_checkout_file() {
_forgit_inside_work_tree || return 1
local git_checkout cmd files opts
git_checkout="git checkout $FORGIT_CHECKOUT_FILE_GIT_OPTS"
[[ $# -ne 0 ]] && {
$git_checkout -- "$@"
return $?
}
[[ $# -ne 0 ]] && { $git_checkout -- "$@"; return $?; }
cmd="git diff --color=always -- {} | $_forgit_diff_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
@ -462,7 +448,7 @@ _forgit_checkout_file() {
--preview=\"$cmd\"
$FORGIT_CHECKOUT_FILE_FZF_OPTS
"
files="$(git ls-files --modified "$(git rev-parse --show-toplevel)" | FZF_DEFAULT_OPTS="$opts" fzf)"
files="$(git ls-files --modified "$(git rev-parse --show-toplevel)"| FZF_DEFAULT_OPTS="$opts" fzf)"
[[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | $git_checkout --pathspec-file-nul --pathspec-from-file -
}
@ -512,10 +498,7 @@ _forgit_checkout_tag() {
_forgit_inside_work_tree || return 1
local git_checkout cmd opts preview
git_checkout="git checkout $FORGIT_CHECKOUT_TAG_GIT_OPTS"
[[ $# -ne 0 ]] && {
$git_checkout "$@"
return $?
}
[[ $# -ne 0 ]] && { $git_checkout "$@"; return $?; }
cmd="git tag -l --sort=-v:refname"
preview="git log {1} $_forgit_log_preview_options"
opts="
@ -534,10 +517,7 @@ _forgit_checkout_commit() {
_forgit_inside_work_tree || return 1
local git_checkout cmd opts graph
git_checkout="git checkout $FORGIT_CHECKOUT_COMMIT_GIT_OPTS"
[[ $# -ne 0 ]] && {
$git_checkout "$@"
return $?
}
[[ $# -ne 0 ]] && { $git_checkout "$@"; return $?; }
cmd="echo {} | $_forgit_extract_sha |xargs -I% git show --color=always % | $_forgit_show_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
@ -557,10 +537,7 @@ _forgit_branch_delete() {
_forgit_inside_work_tree || return 1
local git_branch preview opts cmd branches
git_branch="git branch $FORGIT_BRANCH_DELETE_GIT_OPTS"
[[ $# -ne 0 ]] && {
$git_branch -D "$@"
return $?
}
[[ $# -ne 0 ]] && { $git_branch -D "$@"; return $?; }
preview="git log {1} $_forgit_log_preview_options"
opts="
@ -581,10 +558,7 @@ _forgit_revert_commit() {
_forgit_inside_work_tree || return 1
local git_revert cmd opts files preview commits IFS
git_revert="git revert $FORGIT_REVERT_COMMIT_GIT_OPTS"
[[ $# -ne 0 ]] && {
$git_revert "$@"
return $?
}
[[ $# -ne 0 ]] && { $git_revert "$@"; return $?; }
cmd="git log --graph --color=always --format='$_forgit_log_format' $* $_forgit_emojify"
opts="
@ -599,7 +573,7 @@ _forgit_revert_commit() {
# The instances of "cut", "nl" and "sort" all serve this purpose
# Please see https://github.com/wfxr/forgit/issues/253 for more details
files=$(sed -nE 's/.* -- (.*)/\1/p' <<<"$*") # extract files parameters for `git show` command
files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command
preview="echo {} | cut -f2- | $_forgit_extract_sha | xargs -I% git show --color=always % -- $files | $_forgit_show_pager"
${IFS+"false"} && unset old_IFS || old_IFS="$IFS"
@ -623,10 +597,7 @@ _forgit_blame() {
_forgit_inside_work_tree || return 1
local git_blame opts flags preview file
git_blame="git blame $FORGIT_BLAME_GIT_OPTS"
_forgit_contains_non_flags "$@" && {
$git_blame "$@"
return $?
}
_forgit_contains_non_flags "$@" && { $git_blame "$@"; return $?; }
opts="
$FORGIT_FZF_DEFAULT_OPTS
$FORGIT_BLAME_FZF_OPTS
@ -690,7 +661,7 @@ _forgit_ignore_get() {
done
}
_forgit_ignore_list() {
find "$FORGIT_GI_TEMPLATES" -print | sed -e 's#.gitignore$##' -e 's#.*/##' | sort -fu
find "$FORGIT_GI_TEMPLATES" -print |sed -e 's#.gitignore$##' -e 's#.*/##' | sort -fu
}
_forgit_ignore_clean() {
setopt localoptions rmstarsilent

View file

@ -3,7 +3,7 @@ if not status is-interactive && test "$CI" != true
exit
end
# Because of scoping rules, to capture the shell variables ezactly as they are, we must read
# Because of scoping rules, to capture the shell variables exactly as they are, we must read
# them before even executing _fzf_search_variables. We use psub to store the
# variables' info in temporary files and pass in the filenames as arguments.
# This variable is global so that it can be referenced by fzf_configure_bindings and in tests