2013-11-20 01:29:36 +09:00
|
|
|
|
# ____ ____
|
|
|
|
|
|
# / __/___ / __/
|
|
|
|
|
|
# / /_/_ / / /_
|
|
|
|
|
|
# / __/ / /_/ __/
|
2020-03-31 22:18:09 +09:00
|
|
|
|
# /_/ /___/_/ completion.bash
|
2013-11-20 01:29:36 +09:00
|
|
|
|
#
|
2024-05-07 19:31:13 +09:00
|
|
|
|
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
|
|
|
|
|
# - $FZF_COMPLETION_OPTS (default: empty)
|
|
|
|
|
|
# - $FZF_COMPLETION_PATH_OPTS (default: empty)
|
|
|
|
|
|
# - $FZF_COMPLETION_DIR_OPTS (default: empty)
|
2013-11-20 01:29:36 +09:00
|
|
|
|
|
2024-04-10 00:46:09 +09:00
|
|
|
|
if [[ $- =~ i ]]; then
|
2023-10-08 18:19:28 +02:00
|
|
|
|
|
2019-02-28 16:13:59 +09:00
|
|
|
|
|
2016-01-20 01:09:58 +09:00
|
|
|
|
# To use custom commands instead of find, override _fzf_compgen_{path,dir}
|
2024-03-13 20:56:31 +09:00
|
|
|
|
#
|
|
|
|
|
|
# _fzf_compgen_path() {
|
|
|
|
|
|
# echo "$1"
|
|
|
|
|
|
# command find -L "$1" \
|
|
|
|
|
|
# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \
|
|
|
|
|
|
# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'
|
|
|
|
|
|
# }
|
|
|
|
|
|
#
|
|
|
|
|
|
# _fzf_compgen_dir() {
|
|
|
|
|
|
# command find -L "$1" \
|
|
|
|
|
|
# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \
|
|
|
|
|
|
# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'
|
|
|
|
|
|
# }
|
2016-01-20 01:09:58 +09:00
|
|
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
|
|
|
2025-09-24 20:47:22 +09:00
|
|
|
|
#----BEGIN shfmt
|
2025-06-06 20:08:03 +09:00
|
|
|
|
#----BEGIN INCLUDE common.sh
|
|
|
|
|
|
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
2025-09-24 20:47:22 +09:00
|
|
|
|
# To modify it, one can edit "common.sh" and run "./update.sh" to apply
|
2025-06-06 20:08:03 +09:00
|
|
|
|
# the changes. See code comments in "common.sh" for the implementation details.
|
|
|
|
|
|
|
2024-04-19 22:40:38 +09:00
|
|
|
|
__fzf_defaults() {
|
2026-03-01 10:13:16 +00:00
|
|
|
|
builtin printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"
|
2024-04-19 22:40:38 +09:00
|
|
|
|
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
2026-03-01 10:13:16 +00:00
|
|
|
|
builtin printf '%s\n' "${FZF_DEFAULT_OPTS-} $2"
|
2024-04-19 22:40:38 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-04 13:11:00 +09:00
|
|
|
|
__fzf_exec_awk() {
|
|
|
|
|
|
if [[ -z ${__fzf_awk-} ]]; then
|
|
|
|
|
|
__fzf_awk=awk
|
2025-06-04 14:07:01 +09:00
|
|
|
|
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
|
|
|
|
|
|
__fzf_awk=/usr/xpg4/bin/awk
|
2025-09-24 22:09:37 +09:00
|
|
|
|
elif command -v mawk > /dev/null 2>&1; then
|
2025-06-04 14:07:01 +09:00
|
|
|
|
local n x y z d
|
2025-07-25 10:33:18 +02:00
|
|
|
|
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
|
[bash,zsh] Fix the version check for mawk (#4574)
We have been checking the mawk version by extracting <x>, <y>, <z>,
and <d> part from "mawk <x>.<y>.<z> <d>" in the output of the "mawk -W
version" and testing <x>, <y>, <z>, and <d> using an arithmetic
evalaution. However, <d> is ensured to be an integer only in "x.y.z
>= 1.3.4". Otherwise, it may cause a syntax error in the arithmetic
evaluation. The mawk started to include the date as an integer in the
<d> position only from mawk-1.3.3-20090721. We should first check
that "x.y.z >= 1.3.4" and then check the value of "d". In case, "mawk
-W version" produces a completely different text, we should also
redirect stderr of the arithmetic commands to /dev/null.
2025-10-31 21:14:41 +09:00
|
|
|
|
[[ $n == mawk ]] &&
|
|
|
|
|
|
(((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&
|
|
|
|
|
|
((d >= 20230302)) 2> /dev/null &&
|
|
|
|
|
|
__fzf_awk=mawk
|
2025-06-04 14:07:01 +09:00
|
|
|
|
fi
|
2025-06-04 13:11:00 +09:00
|
|
|
|
fi
|
|
|
|
|
|
LC_ALL=C exec "$__fzf_awk" "$@"
|
|
|
|
|
|
}
|
2025-06-06 20:08:03 +09:00
|
|
|
|
#----END INCLUDE
|
2025-06-04 13:11:00 +09:00
|
|
|
|
|
2020-02-20 00:28:16 +09:00
|
|
|
|
__fzf_comprun() {
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ "$(type -t _fzf_comprun 2>&1)" == function ]]; then
|
2020-02-20 00:28:16 +09:00
|
|
|
|
_fzf_comprun "$@"
|
2025-09-24 22:09:37 +09:00
|
|
|
|
elif [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; }; then
|
2020-02-20 00:28:16 +09:00
|
|
|
|
shift
|
2020-03-31 22:18:09 +09:00
|
|
|
|
fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"
|
2020-02-20 00:28:16 +09:00
|
|
|
|
else
|
|
|
|
|
|
shift
|
|
|
|
|
|
fzf "$@"
|
|
|
|
|
|
fi
|
2017-01-08 01:30:31 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-11 14:44:47 +00:00
|
|
|
|
__fzf_orig_completion() {
|
|
|
|
|
|
local l comp f cmd
|
|
|
|
|
|
while read -r l; do
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ $l =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then
|
2020-11-11 14:44:47 +00:00
|
|
|
|
comp="${BASH_REMATCH[1]}"
|
|
|
|
|
|
f="${BASH_REMATCH[2]}"
|
|
|
|
|
|
cmd="${BASH_REMATCH[3]}"
|
2025-09-24 22:09:37 +09:00
|
|
|
|
[[ $f == _fzf_* ]] && continue
|
2026-03-01 10:13:16 +00:00
|
|
|
|
builtin printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ $l == *" -o nospace "* ]] && [[ ${__fzf_nospace_commands-} != *" $cmd "* ]]; then
|
2022-10-16 16:15:19 +08:00
|
|
|
|
__fzf_nospace_commands="${__fzf_nospace_commands-} $cmd "
|
2020-11-11 14:44:47 +00:00
|
|
|
|
fi
|
|
|
|
|
|
fi
|
|
|
|
|
|
done
|
2014-07-18 00:22:49 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
[bash] Refactor access to "_fzf_orig_complete_${cmd//[^A-Za-z0-9_]/_}"
In the current codebase, for the original completion settings, the
pieces of the codes to determine the variable name and to access the
stored data are scattered. In this patch, we define functions to
access these variables. Those functions will be used in a coming
patch.
* This patch also resolves an inconsistent escaping of "$cmd": $cmd is
escaped as ${...//[^A-Za-z0-9_]/_} in some places, but it is escaped
as ${...//[^A-Za-z0-9_=]/_} in some other places. The latter leaves
the character "=" in the command name, which causes an issue because
"=" cannot be a part of a variable name. For example, the following
test case produces an error message:
$ COMP_WORDBREAKS=${COMP_WORDBREAKS//=}
$ _test1() { COMPREPLY=(); }
$ complete -vF _test1 cmd.v=1.0
$ _fzf_setup_completion path cmd.v=1.0
$ cmd.v=1.0 [TAB]
bash: _fzf_orig_completion_cmd_v=1_0: invalid variable name
The behavior of leaving "=" was present from the beginning when
saving the original completion is introduced in commit 91401514, and
this does not seem to be a specific reasoning. In this patch, we
replace "=" as well as the other non-identifier characters.
* Note: In this patch, the variable REPLY is used to return values
from functions. This design is to make it useful with the value
substitutions, a new Bash feature of the next release 5.3, which is
taken from mksh.
2024-03-10 16:31:55 +09:00
|
|
|
|
# @param $1 cmd - Command name for which the original completion is searched
|
|
|
|
|
|
# @var[out] REPLY - Original function name is returned
|
|
|
|
|
|
__fzf_orig_completion_get_orig_func() {
|
|
|
|
|
|
local cmd orig_var orig
|
|
|
|
|
|
cmd=$1
|
|
|
|
|
|
orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"
|
|
|
|
|
|
orig="${!orig_var-}"
|
|
|
|
|
|
REPLY="${orig##*#}"
|
|
|
|
|
|
[[ $REPLY ]] && type "$REPLY" &> /dev/null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# @param $1 cmd - Command name for which the original completion is searched
|
|
|
|
|
|
# @param $2 func - Fzf's completion function to replace the original function
|
|
|
|
|
|
# @var[out] REPLY - Completion setting is returned as a string to "eval"
|
|
|
|
|
|
__fzf_orig_completion_instantiate() {
|
|
|
|
|
|
local cmd func orig_var orig
|
|
|
|
|
|
cmd=$1
|
|
|
|
|
|
func=$2
|
|
|
|
|
|
orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"
|
|
|
|
|
|
orig="${!orig_var-}"
|
|
|
|
|
|
orig="${orig%#*}"
|
|
|
|
|
|
[[ $orig == *' %s '* ]] || return 1
|
2026-03-01 10:13:16 +00:00
|
|
|
|
builtin printf -v REPLY "$orig" "$func"
|
[bash] Refactor access to "_fzf_orig_complete_${cmd//[^A-Za-z0-9_]/_}"
In the current codebase, for the original completion settings, the
pieces of the codes to determine the variable name and to access the
stored data are scattered. In this patch, we define functions to
access these variables. Those functions will be used in a coming
patch.
* This patch also resolves an inconsistent escaping of "$cmd": $cmd is
escaped as ${...//[^A-Za-z0-9_]/_} in some places, but it is escaped
as ${...//[^A-Za-z0-9_=]/_} in some other places. The latter leaves
the character "=" in the command name, which causes an issue because
"=" cannot be a part of a variable name. For example, the following
test case produces an error message:
$ COMP_WORDBREAKS=${COMP_WORDBREAKS//=}
$ _test1() { COMPREPLY=(); }
$ complete -vF _test1 cmd.v=1.0
$ _fzf_setup_completion path cmd.v=1.0
$ cmd.v=1.0 [TAB]
bash: _fzf_orig_completion_cmd_v=1_0: invalid variable name
The behavior of leaving "=" was present from the beginning when
saving the original completion is introduced in commit 91401514, and
this does not seem to be a specific reasoning. In this patch, we
replace "=" as well as the other non-identifier characters.
* Note: In this patch, the variable REPLY is used to return values
from functions. This design is to make it useful with the value
substitutions, a new Bash feature of the next release 5.3, which is
taken from mksh.
2024-03-10 16:31:55 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-20 01:29:36 +09:00
|
|
|
|
_fzf_opts_completion() {
|
2015-04-16 14:20:29 +09:00
|
|
|
|
local cur prev opts
|
2013-11-20 01:29:36 +09:00
|
|
|
|
COMPREPLY=()
|
|
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
2025-09-24 22:09:37 +09:00
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD - 1]}"
|
2014-07-14 12:48:31 +09:00
|
|
|
|
opts="
|
2024-06-03 09:44:36 +09:00
|
|
|
|
+c --no-color
|
|
|
|
|
|
+i --no-ignore-case
|
|
|
|
|
|
+s --no-sort
|
2023-10-11 03:54:50 +02:00
|
|
|
|
+x --no-extended
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--accept-nth
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--ansi
|
|
|
|
|
|
--bash
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--bind
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--border
|
|
|
|
|
|
--border-label
|
|
|
|
|
|
--border-label-pos
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--color
|
2017-01-08 01:30:31 +09:00
|
|
|
|
--cycle
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--disabled
|
|
|
|
|
|
--ellipsis
|
|
|
|
|
|
--expect
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--filepath-word
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--fish
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--footer
|
|
|
|
|
|
--footer-border
|
|
|
|
|
|
--footer-label
|
|
|
|
|
|
--footer-label-pos
|
|
|
|
|
|
--freeze-left
|
|
|
|
|
|
--freeze-right
|
|
|
|
|
|
--gap
|
|
|
|
|
|
--gap-line
|
|
|
|
|
|
--ghost
|
|
|
|
|
|
--gutter
|
|
|
|
|
|
--gutter-raw
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--header
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--header-border
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--header-first
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--header-label
|
|
|
|
|
|
--header-label-pos
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--header-lines
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--header-lines-border
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--height
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--highlight-line
|
|
|
|
|
|
--history
|
|
|
|
|
|
--history-size
|
|
|
|
|
|
--hscroll-off
|
2026-03-15 11:31:36 +09:00
|
|
|
|
--id-nth
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--info
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--info-command
|
|
|
|
|
|
--input-border
|
|
|
|
|
|
--input-label
|
|
|
|
|
|
--input-label-pos
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--jump-labels
|
|
|
|
|
|
--keep-right
|
|
|
|
|
|
--layout
|
|
|
|
|
|
--listen
|
|
|
|
|
|
--listen-unsafe
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--list-border
|
|
|
|
|
|
--list-label
|
|
|
|
|
|
--list-label-pos
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--literal
|
|
|
|
|
|
--man
|
|
|
|
|
|
--margin
|
|
|
|
|
|
--marker
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--marker-multi-line
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--min-height
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--no-bold
|
|
|
|
|
|
--no-hscroll
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--no-input
|
|
|
|
|
|
--no-multi-line
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--no-scrollbar
|
|
|
|
|
|
--no-separator
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--padding
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--pointer
|
|
|
|
|
|
--preview
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--preview-border
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--preview-label
|
|
|
|
|
|
--preview-label-pos
|
|
|
|
|
|
--preview-window
|
|
|
|
|
|
--print-query
|
|
|
|
|
|
--print0
|
|
|
|
|
|
--prompt
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--raw
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--read0
|
|
|
|
|
|
--scheme
|
|
|
|
|
|
--scroll-off
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--scrollbar
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--separator
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--smart-case
|
|
|
|
|
|
--style
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--sync
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--tabstop
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--tac
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--tail
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--tiebreak
|
|
|
|
|
|
--tmux
|
|
|
|
|
|
--track
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--version
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--walker
|
|
|
|
|
|
--walker-root
|
|
|
|
|
|
--walker-skip
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--with-nth
|
|
|
|
|
|
--with-shell
|
2024-07-06 10:20:00 +09:00
|
|
|
|
--wrap
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--wrap-sign
|
2026-02-19 21:29:03 +09:00
|
|
|
|
--preview-wrap-sign
|
2024-06-03 09:44:36 +09:00
|
|
|
|
--zsh
|
|
|
|
|
|
-0 --exit-0
|
|
|
|
|
|
-1 --select-1
|
|
|
|
|
|
-d --delimiter
|
|
|
|
|
|
-e --exact
|
|
|
|
|
|
-f --filter
|
|
|
|
|
|
-h --help
|
|
|
|
|
|
-i --ignore-case
|
|
|
|
|
|
-m --multi
|
|
|
|
|
|
-n --nth
|
|
|
|
|
|
-q --query
|
2023-10-11 03:54:50 +02:00
|
|
|
|
--"
|
2013-11-20 01:29:36 +09:00
|
|
|
|
|
2015-04-16 14:20:29 +09:00
|
|
|
|
case "${prev}" in
|
2025-09-24 22:09:37 +09:00
|
|
|
|
--scheme)
|
|
|
|
|
|
COMPREPLY=($(compgen -W "default path history" -- "$cur"))
|
|
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
|
|
|
|
|
--tiebreak)
|
2026-02-19 00:15:08 +09:00
|
|
|
|
COMPREPLY=($(compgen -W "length chunk pathname begin end index" -- "$cur"))
|
2025-09-24 22:09:37 +09:00
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
|
|
|
|
|
--color)
|
2026-02-19 00:15:08 +09:00
|
|
|
|
COMPREPLY=($(compgen -W "dark light base16 16 bw no" -- "$cur"))
|
2025-09-24 22:09:37 +09:00
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
|
|
|
|
|
--layout)
|
|
|
|
|
|
COMPREPLY=($(compgen -W "default reverse reverse-list" -- "$cur"))
|
|
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
|
|
|
|
|
--info)
|
|
|
|
|
|
COMPREPLY=($(compgen -W "default right hidden inline inline-right" -- "$cur"))
|
|
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--wrap)
|
|
|
|
|
|
COMPREPLY=($(compgen -W "char word" -- "$cur"))
|
|
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
|
|
|
|
|
--style)
|
|
|
|
|
|
COMPREPLY=($(compgen -W "default minimal full" -- "$cur"))
|
|
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
2025-09-24 22:09:37 +09:00
|
|
|
|
--preview-window)
|
|
|
|
|
|
COMPREPLY=($(compgen -W "
|
2023-10-11 03:54:50 +02:00
|
|
|
|
default
|
|
|
|
|
|
hidden
|
|
|
|
|
|
nohidden
|
|
|
|
|
|
wrap
|
2026-02-19 00:15:08 +09:00
|
|
|
|
wrap-word
|
2023-10-11 03:54:50 +02:00
|
|
|
|
nowrap
|
|
|
|
|
|
cycle
|
|
|
|
|
|
nocycle
|
|
|
|
|
|
up top
|
|
|
|
|
|
down bottom
|
|
|
|
|
|
left
|
|
|
|
|
|
right
|
|
|
|
|
|
rounded border border-rounded
|
2026-02-19 00:15:08 +09:00
|
|
|
|
border-line
|
2023-10-11 03:54:50 +02:00
|
|
|
|
sharp border-sharp
|
|
|
|
|
|
border-bold
|
|
|
|
|
|
border-block
|
|
|
|
|
|
border-thinblock
|
|
|
|
|
|
border-double
|
|
|
|
|
|
noborder border-none
|
|
|
|
|
|
border-horizontal
|
|
|
|
|
|
border-vertical
|
|
|
|
|
|
border-up border-top
|
|
|
|
|
|
border-down border-bottom
|
|
|
|
|
|
border-left
|
|
|
|
|
|
border-right
|
|
|
|
|
|
follow
|
2026-02-19 00:15:08 +09:00
|
|
|
|
nofollow
|
|
|
|
|
|
info
|
|
|
|
|
|
noinfo" -- "$cur"))
|
2025-09-24 22:09:37 +09:00
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--border | --list-border | --header-border | --header-lines-border | --footer-border | --input-border | --preview-border)
|
|
|
|
|
|
COMPREPLY=($(compgen -W "line rounded sharp bold block thinblock double horizontal vertical top bottom left right none" -- "$cur"))
|
2025-09-24 22:09:37 +09:00
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
2026-02-19 00:15:08 +09:00
|
|
|
|
--border-label-pos | --preview-label-pos | --list-label-pos | --header-label-pos | --footer-label-pos | --input-label-pos)
|
2025-09-24 22:09:37 +09:00
|
|
|
|
COMPREPLY=($(compgen -W "center bottom top" -- "$cur"))
|
|
|
|
|
|
return 0
|
|
|
|
|
|
;;
|
2015-04-16 14:20:29 +09:00
|
|
|
|
esac
|
|
|
|
|
|
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ $cur =~ ^-|\+ ]]; then
|
|
|
|
|
|
COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
|
2013-11-20 01:29:36 +09:00
|
|
|
|
return 0
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-12-05 00:15:14 +09:00
|
|
|
|
_fzf_handle_dynamic_completion() {
|
[bash] Refactor access to "_fzf_orig_complete_${cmd//[^A-Za-z0-9_]/_}"
In the current codebase, for the original completion settings, the
pieces of the codes to determine the variable name and to access the
stored data are scattered. In this patch, we define functions to
access these variables. Those functions will be used in a coming
patch.
* This patch also resolves an inconsistent escaping of "$cmd": $cmd is
escaped as ${...//[^A-Za-z0-9_]/_} in some places, but it is escaped
as ${...//[^A-Za-z0-9_=]/_} in some other places. The latter leaves
the character "=" in the command name, which causes an issue because
"=" cannot be a part of a variable name. For example, the following
test case produces an error message:
$ COMP_WORDBREAKS=${COMP_WORDBREAKS//=}
$ _test1() { COMPREPLY=(); }
$ complete -vF _test1 cmd.v=1.0
$ _fzf_setup_completion path cmd.v=1.0
$ cmd.v=1.0 [TAB]
bash: _fzf_orig_completion_cmd_v=1_0: invalid variable name
The behavior of leaving "=" was present from the beginning when
saving the original completion is introduced in commit 91401514, and
this does not seem to be a specific reasoning. In this patch, we
replace "=" as well as the other non-identifier characters.
* Note: In this patch, the variable REPLY is used to return values
from functions. This design is to make it useful with the value
substitutions, a new Bash feature of the next release 5.3, which is
taken from mksh.
2024-03-10 16:31:55 +09:00
|
|
|
|
local cmd ret REPLY orig_cmd orig_complete
|
2014-12-05 00:15:14 +09:00
|
|
|
|
cmd="$1"
|
|
|
|
|
|
shift
|
2015-07-03 23:47:10 +00:00
|
|
|
|
orig_cmd="$1"
|
[bash] Refactor access to "_fzf_orig_complete_${cmd//[^A-Za-z0-9_]/_}"
In the current codebase, for the original completion settings, the
pieces of the codes to determine the variable name and to access the
stored data are scattered. In this patch, we define functions to
access these variables. Those functions will be used in a coming
patch.
* This patch also resolves an inconsistent escaping of "$cmd": $cmd is
escaped as ${...//[^A-Za-z0-9_]/_} in some places, but it is escaped
as ${...//[^A-Za-z0-9_=]/_} in some other places. The latter leaves
the character "=" in the command name, which causes an issue because
"=" cannot be a part of a variable name. For example, the following
test case produces an error message:
$ COMP_WORDBREAKS=${COMP_WORDBREAKS//=}
$ _test1() { COMPREPLY=(); }
$ complete -vF _test1 cmd.v=1.0
$ _fzf_setup_completion path cmd.v=1.0
$ cmd.v=1.0 [TAB]
bash: _fzf_orig_completion_cmd_v=1_0: invalid variable name
The behavior of leaving "=" was present from the beginning when
saving the original completion is introduced in commit 91401514, and
this does not seem to be a specific reasoning. In this patch, we
replace "=" as well as the other non-identifier characters.
* Note: In this patch, the variable REPLY is used to return values
from functions. This design is to make it useful with the value
substitutions, a new Bash feature of the next release 5.3, which is
taken from mksh.
2024-03-10 16:31:55 +09:00
|
|
|
|
if __fzf_orig_completion_get_orig_func "$cmd"; then
|
|
|
|
|
|
"$REPLY" "$@"
|
2025-09-24 22:09:37 +09:00
|
|
|
|
elif [[ -n ${_fzf_completion_loader-} ]]; then
|
2019-04-30 18:35:51 +01:00
|
|
|
|
orig_complete=$(complete -p "$orig_cmd" 2> /dev/null)
|
2024-03-17 15:36:33 +09:00
|
|
|
|
$_fzf_completion_loader "$@"
|
2014-12-05 00:15:14 +09:00
|
|
|
|
ret=$?
|
2017-12-03 03:06:10 +09:00
|
|
|
|
# _completion_loader may not have updated completion for the command
|
2021-08-14 11:33:21 +00:00
|
|
|
|
if [[ "$(complete -p "$orig_cmd" 2> /dev/null)" != "$orig_complete" ]]; then
|
2020-11-11 14:44:47 +00:00
|
|
|
|
__fzf_orig_completion < <(complete -p "$orig_cmd" 2> /dev/null)
|
2024-09-23 19:16:59 +09:00
|
|
|
|
__fzf_orig_completion_get_orig_func "$cmd" || ret=1
|
2024-03-10 16:32:25 +09:00
|
|
|
|
|
|
|
|
|
|
# Update orig_complete by _fzf_orig_completion entry
|
|
|
|
|
|
[[ $orig_complete =~ ' -F '(_fzf_[^ ]+)' ' ]] &&
|
|
|
|
|
|
__fzf_orig_completion_instantiate "$cmd" "${BASH_REMATCH[1]}" &&
|
|
|
|
|
|
orig_complete=$REPLY
|
|
|
|
|
|
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ ${__fzf_nospace_commands-} == *" $orig_cmd "* ]]; then
|
2018-02-15 11:56:07 +09:00
|
|
|
|
eval "${orig_complete/ -F / -o nospace -F }"
|
|
|
|
|
|
else
|
|
|
|
|
|
eval "$orig_complete"
|
|
|
|
|
|
fi
|
2017-12-03 03:06:10 +09:00
|
|
|
|
fi
|
2024-03-29 16:20:50 +09:00
|
|
|
|
[[ $ret -eq 0 ]] && return 124
|
2014-12-05 00:15:14 +09:00
|
|
|
|
return $ret
|
|
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-05 19:34:38 +09:00
|
|
|
|
__fzf_generic_path_completion() {
|
2020-02-20 00:28:16 +09:00
|
|
|
|
local cur base dir leftover matches trigger cmd
|
2022-07-29 08:50:59 -04:00
|
|
|
|
cmd="${COMP_WORDS[0]}"
|
|
|
|
|
|
if [[ $cmd == \\* ]]; then
|
|
|
|
|
|
cmd="${cmd:1}"
|
|
|
|
|
|
fi
|
2013-11-20 01:29:36 +09:00
|
|
|
|
COMPREPLY=()
|
2015-05-11 10:17:33 +09:00
|
|
|
|
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
2024-08-11 14:22:21 +09:00
|
|
|
|
[[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}"
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then
|
2013-12-23 23:16:07 +09:00
|
|
|
|
base=${cur:0:${#cur}-${#trigger}}
|
2023-10-03 20:04:56 +09:00
|
|
|
|
eval "base=$base" 2> /dev/null || return
|
2013-11-20 01:29:36 +09:00
|
|
|
|
|
2022-10-16 16:15:19 +08:00
|
|
|
|
dir=
|
2025-09-24 22:09:37 +09:00
|
|
|
|
[[ $base == *"/"* ]] && dir="$base"
|
2016-03-02 23:59:42 +09:00
|
|
|
|
while true; do
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ -z $dir ]] || [[ -d $dir ]]; then
|
|
|
|
|
|
leftover=${base/#"$dir"/}
|
|
|
|
|
|
leftover=${leftover/#\//}
|
|
|
|
|
|
[[ -z $dir ]] && dir='.'
|
|
|
|
|
|
[[ $dir != "/" ]] && dir="${dir/%\//}"
|
2024-03-13 20:56:31 +09:00
|
|
|
|
matches=$(
|
2024-04-19 22:40:38 +09:00
|
|
|
|
export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2")
|
|
|
|
|
|
unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
|
2026-02-20 02:59:43 +01:00
|
|
|
|
if [[ $1 =~ dir ]]; then
|
|
|
|
|
|
eval "rest=(${FZF_COMPLETION_DIR_OPTS-})"
|
|
|
|
|
|
else
|
|
|
|
|
|
eval "rest=(${FZF_COMPLETION_PATH_OPTS-})"
|
|
|
|
|
|
fi
|
2024-03-13 20:56:31 +09:00
|
|
|
|
if declare -F "$1" > /dev/null; then
|
2026-03-01 10:13:16 +00:00
|
|
|
|
eval "$1 $(builtin printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover" "${rest[@]}"
|
2024-03-13 20:56:31 +09:00
|
|
|
|
else
|
2024-05-07 19:31:13 +09:00
|
|
|
|
if [[ $1 =~ dir ]]; then
|
|
|
|
|
|
walker=dir,follow
|
|
|
|
|
|
else
|
|
|
|
|
|
walker=file,dir,follow,hidden
|
|
|
|
|
|
fi
|
2025-03-17 18:12:26 +09:00
|
|
|
|
__fzf_comprun "$4" -q "$leftover" --walker "$walker" --walker-root="$dir" "${rest[@]}"
|
2024-03-13 20:56:31 +09:00
|
|
|
|
fi | while read -r item; do
|
2026-03-01 10:13:16 +00:00
|
|
|
|
builtin printf "%q " "${item%$3}$3"
|
2024-03-13 20:56:31 +09:00
|
|
|
|
done
|
|
|
|
|
|
)
|
2017-07-31 14:08:17 +09:00
|
|
|
|
matches=${matches% }
|
2025-09-24 22:09:37 +09:00
|
|
|
|
[[ -z $3 ]] && [[ ${__fzf_nospace_commands-} == *" ${COMP_WORDS[0]} "* ]] && matches="$matches "
|
|
|
|
|
|
if [[ -n $matches ]]; then
|
|
|
|
|
|
COMPREPLY=("$matches")
|
2013-11-20 01:29:36 +09:00
|
|
|
|
else
|
2025-09-24 22:09:37 +09:00
|
|
|
|
COMPREPLY=("$cur")
|
2013-11-20 01:29:36 +09:00
|
|
|
|
fi
|
2026-03-01 10:13:16 +00:00
|
|
|
|
# To redraw line after fzf closes (builtin printf '\e[5n')
|
2025-05-09 23:29:27 -07:00
|
|
|
|
bind '"\e[0n": redraw-current-line' 2> /dev/null
|
2026-03-01 10:13:16 +00:00
|
|
|
|
builtin printf '\e[5n'
|
2013-11-23 20:16:46 +09:00
|
|
|
|
return 0
|
2013-11-20 01:29:36 +09:00
|
|
|
|
fi
|
2023-10-11 06:07:47 +02:00
|
|
|
|
dir=$(command dirname "$dir")
|
2025-09-24 22:09:37 +09:00
|
|
|
|
[[ $dir =~ /$ ]] || dir="$dir"/
|
2013-11-23 20:09:56 +09:00
|
|
|
|
done
|
2014-07-04 00:08:37 +09:00
|
|
|
|
else
|
2015-03-04 12:59:23 +09:00
|
|
|
|
shift
|
2014-07-04 00:08:37 +09:00
|
|
|
|
shift
|
|
|
|
|
|
shift
|
2014-12-05 00:15:14 +09:00
|
|
|
|
_fzf_handle_dynamic_completion "$cmd" "$@"
|
2013-11-20 01:29:36 +09:00
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-05 19:34:38 +09:00
|
|
|
|
_fzf_complete() {
|
2020-03-11 18:29:39 +09:00
|
|
|
|
# Split arguments around --
|
|
|
|
|
|
local args rest str_arg i sep
|
|
|
|
|
|
args=("$@")
|
|
|
|
|
|
sep=
|
|
|
|
|
|
for i in "${!args[@]}"; do
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ ${args[$i]} == -- ]]; then
|
2020-03-11 18:29:39 +09:00
|
|
|
|
sep=$i
|
|
|
|
|
|
break
|
|
|
|
|
|
fi
|
|
|
|
|
|
done
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ -n $sep ]]; then
|
2020-03-11 18:29:39 +09:00
|
|
|
|
str_arg=
|
|
|
|
|
|
rest=("${args[@]:$((sep + 1)):${#args[@]}}")
|
2025-09-24 22:09:37 +09:00
|
|
|
|
args=("${args[@]:0:sep}")
|
2020-03-11 18:29:39 +09:00
|
|
|
|
else
|
|
|
|
|
|
str_arg=$1
|
|
|
|
|
|
args=()
|
|
|
|
|
|
shift
|
|
|
|
|
|
rest=("$@")
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
2020-02-20 00:28:16 +09:00
|
|
|
|
local cur selected trigger cmd post
|
2025-06-04 13:11:00 +09:00
|
|
|
|
post="$(caller 0 | __fzf_exec_awk '{print $2}')_post"
|
2023-10-11 06:07:47 +02:00
|
|
|
|
type -t "$post" > /dev/null 2>&1 || post='command cat'
|
2015-10-05 19:34:38 +09:00
|
|
|
|
|
2015-05-11 10:17:33 +09:00
|
|
|
|
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
2024-03-13 08:31:14 +09:00
|
|
|
|
cmd="${COMP_WORDS[0]}"
|
2014-07-14 12:48:31 +09:00
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then
|
2014-07-14 12:48:31 +09:00
|
|
|
|
cur=${cur:0:${#cur}-${#trigger}}
|
|
|
|
|
|
|
2024-04-19 22:40:38 +09:00
|
|
|
|
selected=$(
|
|
|
|
|
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \
|
|
|
|
|
|
FZF_DEFAULT_OPTS_FILE='' \
|
2025-09-24 22:09:37 +09:00
|
|
|
|
__fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | eval "$post" | command tr '\n' ' '
|
|
|
|
|
|
)
|
2015-10-05 19:34:38 +09:00
|
|
|
|
selected=${selected% } # Strip trailing space not to repeat "-o nospace"
|
2025-09-24 22:09:37 +09:00
|
|
|
|
if [[ -n $selected ]]; then
|
2014-07-14 12:48:31 +09:00
|
|
|
|
COMPREPLY=("$selected")
|
2019-09-29 14:45:58 +09:00
|
|
|
|
else
|
|
|
|
|
|
COMPREPLY=("$cur")
|
2014-07-14 12:48:31 +09:00
|
|
|
|
fi
|
2025-05-09 23:29:27 -07:00
|
|
|
|
bind '"\e[0n": redraw-current-line' 2> /dev/null
|
2026-03-01 10:13:16 +00:00
|
|
|
|
builtin printf '\e[5n'
|
2019-09-29 14:45:58 +09:00
|
|
|
|
return 0
|
2014-07-14 12:48:31 +09:00
|
|
|
|
else
|
2020-03-11 18:29:39 +09:00
|
|
|
|
_fzf_handle_dynamic_completion "$cmd" "${rest[@]}"
|
2014-07-14 12:48:31 +09:00
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-05 19:34:38 +09:00
|
|
|
|
_fzf_path_completion() {
|
2017-07-31 14:08:17 +09:00
|
|
|
|
__fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"
|
2013-11-20 12:28:41 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-20 01:09:58 +09:00
|
|
|
|
# Deprecated. No file only completion.
|
2013-11-20 12:28:41 +09:00
|
|
|
|
_fzf_file_completion() {
|
2016-01-20 01:09:58 +09:00
|
|
|
|
_fzf_path_completion "$@"
|
2013-11-20 01:29:36 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_fzf_dir_completion() {
|
2017-07-31 14:08:17 +09:00
|
|
|
|
__fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"
|
2013-11-20 01:29:36 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-05 19:34:38 +09:00
|
|
|
|
_fzf_complete_kill() {
|
2020-04-18 00:51:06 +09:00
|
|
|
|
_fzf_proc_completion "$@"
|
|
|
|
|
|
}
|
2013-11-29 17:49:48 +09:00
|
|
|
|
|
2020-04-18 00:51:06 +09:00
|
|
|
|
_fzf_proc_completion() {
|
2025-01-27 01:10:08 +09:00
|
|
|
|
local transformer
|
|
|
|
|
|
transformer='
|
|
|
|
|
|
if [[ $FZF_KEY =~ ctrl|alt|shift ]] && [[ -n $FZF_NTH ]]; then
|
2025-01-27 19:19:08 +09:00
|
|
|
|
nths=( ${FZF_NTH//,/ } )
|
2025-01-27 01:10:08 +09:00
|
|
|
|
new_nths=()
|
|
|
|
|
|
found=0
|
|
|
|
|
|
for nth in ${nths[@]}; do
|
|
|
|
|
|
if [[ $nth = $FZF_CLICK_HEADER_NTH ]]; then
|
|
|
|
|
|
found=1
|
|
|
|
|
|
else
|
|
|
|
|
|
new_nths+=($nth)
|
|
|
|
|
|
fi
|
|
|
|
|
|
done
|
|
|
|
|
|
[[ $found = 0 ]] && new_nths+=($FZF_CLICK_HEADER_NTH)
|
2025-01-27 19:19:08 +09:00
|
|
|
|
new_nths=${new_nths[*]}
|
|
|
|
|
|
new_nths=${new_nths// /,}
|
2025-01-27 01:10:08 +09:00
|
|
|
|
echo "change-nth($new_nths)+change-prompt($new_nths> )"
|
|
|
|
|
|
else
|
|
|
|
|
|
if [[ $FZF_NTH = $FZF_CLICK_HEADER_NTH ]]; then
|
|
|
|
|
|
echo "change-nth()+change-prompt(> )"
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "change-nth($FZF_CLICK_HEADER_NTH)+change-prompt($FZF_CLICK_HEADER_WORD> )"
|
|
|
|
|
|
fi
|
|
|
|
|
|
fi
|
|
|
|
|
|
'
|
2025-01-26 16:11:15 +09:00
|
|
|
|
_fzf_complete -m --header-lines=1 --no-preview --wrap --color fg:dim,nth:regular \
|
2025-01-27 01:10:08 +09:00
|
|
|
|
--bind "click-header:transform:$transformer" -- "$@" < <(
|
2025-09-24 22:09:37 +09:00
|
|
|
|
command ps -eo user,pid,ppid,start,time,command 2> /dev/null ||
|
|
|
|
|
|
command ps -eo user,pid,ppid,time,args 2> /dev/null || # For BusyBox
|
|
|
|
|
|
command ps --everyone --full --windows # For cygwin
|
|
|
|
|
|
)
|
2020-04-18 00:51:06 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_fzf_proc_completion_post() {
|
2025-06-04 13:11:00 +09:00
|
|
|
|
__fzf_exec_awk '{print $2}'
|
2013-11-29 17:49:48 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-26 20:37:04 +02:00
|
|
|
|
# To use custom hostname lists, override __fzf_list_hosts.
|
|
|
|
|
|
# The function is expected to print hostnames, one per line as well as in the
|
|
|
|
|
|
# desired sorting and with any duplicates removed, to standard output.
|
2023-10-13 01:00:43 +09:00
|
|
|
|
#
|
|
|
|
|
|
# e.g.
|
|
|
|
|
|
# # Use bash-completions’s _known_hosts_real() for getting the list of hosts
|
|
|
|
|
|
# __fzf_list_hosts() {
|
|
|
|
|
|
# # Set the local attribute for any non-local variable that is set by _known_hosts_real()
|
|
|
|
|
|
# local COMPREPLY=()
|
|
|
|
|
|
# _known_hosts_real ''
|
2026-03-01 10:13:16 +00:00
|
|
|
|
# builtin printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort
|
2023-10-13 01:00:43 +09:00
|
|
|
|
# }
|
2023-09-26 20:37:04 +02:00
|
|
|
|
if ! declare -F __fzf_list_hosts > /dev/null; then
|
2023-10-13 01:00:43 +09:00
|
|
|
|
__fzf_list_hosts() {
|
2025-06-03 20:25:19 +09:00
|
|
|
|
command sort -u \
|
2025-06-03 20:47:28 +09:00
|
|
|
|
<(
|
|
|
|
|
|
# Note: To make the pathname expansion of "~/.ssh/config.d/*" work
|
|
|
|
|
|
# properly, we need to adjust the related shell options. We need to
|
|
|
|
|
|
# unset "set -f" and "GLOBIGNORE", which disable the pathname expansion
|
|
|
|
|
|
# totally or partially. We need to unset "dotglob" and "nocaseglob" to
|
|
|
|
|
|
# avoid matching unwanted files. We need to unset "failglob" to avoid
|
|
|
|
|
|
# outputting the error messages to the terminal when no matching is
|
|
|
|
|
|
# found. We need to set "nullglob" to avoid attempting to read the
|
|
|
|
|
|
# literal filename '~/.ssh/config.d/*' when no matching is found.
|
|
|
|
|
|
set +f
|
|
|
|
|
|
GLOBIGNORE=
|
|
|
|
|
|
shopt -u dotglob nocaseglob failglob
|
|
|
|
|
|
shopt -s nullglob
|
|
|
|
|
|
|
2025-06-04 13:11:00 +09:00
|
|
|
|
__fzf_exec_awk '
|
2025-06-04 12:27:30 +09:00
|
|
|
|
# Note: mawk <= 1.3.3-20090705 does not support the POSIX brackets of
|
|
|
|
|
|
# the form [[:blank:]], and Ubuntu 18.04 LTS still uses this
|
|
|
|
|
|
# 16-year-old mawk unfortunately. We need to use [ \t] instead.
|
|
|
|
|
|
match(tolower($0), /^[ \t]*host(name)?[ \t]*[ \t=]/) {
|
|
|
|
|
|
$0 = substr($0, RLENGTH + 1) # Remove "Host(name)?=?"
|
2025-06-04 12:30:31 +09:00
|
|
|
|
sub(/#.*/, "")
|
2025-06-04 12:27:30 +09:00
|
|
|
|
for (i = 1; i <= NF; i++)
|
2025-06-03 20:25:19 +09:00
|
|
|
|
if ($i !~ /[*?%]/)
|
|
|
|
|
|
print $i
|
|
|
|
|
|
}
|
|
|
|
|
|
' ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null
|
2025-06-03 20:47:28 +09:00
|
|
|
|
) \
|
2025-06-03 20:25:19 +09:00
|
|
|
|
<(
|
2025-06-04 13:11:00 +09:00
|
|
|
|
__fzf_exec_awk -F ',' '
|
2025-06-03 21:30:56 +09:00
|
|
|
|
match($0, /^[][a-zA-Z0-9.,:-]+/) {
|
2025-06-03 20:25:19 +09:00
|
|
|
|
$0 = substr($0, 1, RLENGTH)
|
2025-06-03 21:30:56 +09:00
|
|
|
|
gsub(/[][]|:[^,]*/, "")
|
2025-06-03 20:25:19 +09:00
|
|
|
|
for (i = 1; i <= NF; i++)
|
|
|
|
|
|
print $i
|
|
|
|
|
|
}
|
|
|
|
|
|
' ~/.ssh/known_hosts 2> /dev/null
|
|
|
|
|
|
) \
|
|
|
|
|
|
<(
|
2025-06-04 13:11:00 +09:00
|
|
|
|
__fzf_exec_awk '
|
2025-06-03 20:25:19 +09:00
|
|
|
|
{
|
|
|
|
|
|
sub(/#.*/, "")
|
|
|
|
|
|
for (i = 2; i <= NF; i++)
|
2025-06-04 11:25:49 +09:00
|
|
|
|
if ($i != "0.0.0.0")
|
|
|
|
|
|
print $i
|
2025-06-03 20:25:19 +09:00
|
|
|
|
}
|
2025-07-25 10:33:18 +02:00
|
|
|
|
' /etc/hosts 2> /dev/null
|
2025-06-03 20:25:19 +09:00
|
|
|
|
)
|
2023-10-13 01:00:43 +09:00
|
|
|
|
}
|
2023-09-26 20:37:04 +02:00
|
|
|
|
fi
|
2023-09-17 18:15:04 +03:00
|
|
|
|
|
2019-12-20 18:39:22 +09:00
|
|
|
|
_fzf_host_completion() {
|
2023-09-26 20:21:09 +02:00
|
|
|
|
_fzf_complete +m -- "$@" < <(__fzf_list_hosts)
|
2023-09-17 18:15:04 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Values for $1 $2 $3 are described here
|
|
|
|
|
|
# https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html
|
|
|
|
|
|
# > the first argument ($1) is the name of the command whose arguments are being completed,
|
|
|
|
|
|
# > the second argument ($2) is the word being completed,
|
|
|
|
|
|
# > and the third argument ($3) is the word preceding the word being completed on the current command line.
|
|
|
|
|
|
_fzf_complete_ssh() {
|
|
|
|
|
|
case $3 in
|
2025-09-24 22:09:37 +09:00
|
|
|
|
-i | -F | -E)
|
2023-09-17 18:15:04 +03:00
|
|
|
|
_fzf_path_completion "$@"
|
|
|
|
|
|
;;
|
|
|
|
|
|
*)
|
|
|
|
|
|
local user=
|
2025-09-24 22:09:37 +09:00
|
|
|
|
[[ $2 =~ '@' ]] && user="${2%%@*}@"
|
2025-06-04 13:11:00 +09:00
|
|
|
|
_fzf_complete +m -- "$@" < <(__fzf_list_hosts | __fzf_exec_awk -v user="$user" '{print user $0}')
|
2023-09-17 18:15:04 +03:00
|
|
|
|
;;
|
|
|
|
|
|
esac
|
2015-10-05 19:34:38 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-20 18:39:22 +09:00
|
|
|
|
_fzf_var_completion() {
|
2020-03-11 18:29:39 +09:00
|
|
|
|
_fzf_complete -m -- "$@" < <(
|
2023-10-11 06:07:47 +02:00
|
|
|
|
declare -xp | command sed -En 's|^declare [^ ]+ ([^=]+).*|\1|p'
|
2015-10-05 19:34:38 +09:00
|
|
|
|
)
|
2014-07-14 12:48:31 +09:00
|
|
|
|
}
|
2013-12-22 20:42:11 +09:00
|
|
|
|
|
2019-12-20 18:39:22 +09:00
|
|
|
|
_fzf_alias_completion() {
|
2020-03-11 18:29:39 +09:00
|
|
|
|
_fzf_complete -m -- "$@" < <(
|
2023-10-11 06:07:47 +02:00
|
|
|
|
alias | command sed -En 's|^alias ([^=]+).*|\1|p'
|
2015-10-05 19:34:38 +09:00
|
|
|
|
)
|
2013-12-22 20:42:11 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-04 00:08:37 +09:00
|
|
|
|
# fzf options
|
2015-06-14 00:43:44 +09:00
|
|
|
|
complete -o default -F _fzf_opts_completion fzf
|
2022-07-15 01:53:23 -05:00
|
|
|
|
# fzf-tmux is a thin fzf wrapper that has only a few more options than fzf
|
|
|
|
|
|
# itself. As a quick improvement we take fzf's completion. Adding the few extra
|
|
|
|
|
|
# fzf-tmux specific options (like `-w WIDTH`) are left as a future patch.
|
|
|
|
|
|
complete -o default -F _fzf_opts_completion fzf-tmux
|
2013-11-20 01:29:36 +09:00
|
|
|
|
|
2024-08-11 14:22:21 +09:00
|
|
|
|
# Default path completion
|
|
|
|
|
|
__fzf_default_completion() {
|
|
|
|
|
|
__fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"
|
|
|
|
|
|
|
|
|
|
|
|
# Dynamic completion loader has updated the completion for the command
|
|
|
|
|
|
if [[ $? -eq 124 ]]; then
|
|
|
|
|
|
# We trigger _fzf_setup_completion so that fuzzy completion for the command
|
|
|
|
|
|
# still works. However, loader can update the completion for multiple
|
|
|
|
|
|
# commands at once, and fuzzy completion will no longer work for those
|
|
|
|
|
|
# other commands. e.g. pytest -> py.test, pytest-2, pytest-3, etc
|
|
|
|
|
|
_fzf_setup_completion path "$1"
|
|
|
|
|
|
return 124
|
|
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 19:39:22 +09:00
|
|
|
|
# Set fuzzy path completion as the default completion for all commands.
|
|
|
|
|
|
# We can't set up default completion,
|
|
|
|
|
|
# 1. if it's already set up by another script
|
|
|
|
|
|
# 2. or if the current version of bash doesn't support -D option
|
|
|
|
|
|
complete | command grep -q __fzf_default_completion ||
|
|
|
|
|
|
complete | command grep -- '-D$' | command grep -qv _comp_complete_load ||
|
|
|
|
|
|
complete -D -F __fzf_default_completion -o default -o bashdefault 2> /dev/null
|
2024-08-11 14:22:21 +09:00
|
|
|
|
|
2024-04-27 14:11:08 +09:00
|
|
|
|
d_cmds="${FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir}"
|
|
|
|
|
|
|
2024-08-22 19:39:22 +09:00
|
|
|
|
# NOTE: $FZF_COMPLETION_PATH_COMMANDS and $FZF_COMPLETION_VAR_COMMANDS are
|
|
|
|
|
|
# undocumented and subject to change in the future.
|
|
|
|
|
|
#
|
|
|
|
|
|
# NOTE: Although we have default completion, we still need to set up completion
|
|
|
|
|
|
# for each command in case they already have completion set up by another script.
|
|
|
|
|
|
a_cmds="${FZF_COMPLETION_PATH_COMMANDS-"
|
|
|
|
|
|
awk bat cat code diff diff3
|
|
|
|
|
|
emacs emacsclient ex file ftp g++ gcc gvim head hg hx java
|
|
|
|
|
|
javac ld less more mvim nvim patch perl python ruby
|
|
|
|
|
|
sed sftp sort source tail tee uniq vi view vim wc xdg-open
|
|
|
|
|
|
basename bunzip2 bzip2 chmod chown curl cp dirname du
|
|
|
|
|
|
find git grep gunzip gzip hg jar
|
|
|
|
|
|
ln ls mv open rm rsync scp
|
|
|
|
|
|
svn tar unzip zip"}"
|
2024-04-27 14:11:08 +09:00
|
|
|
|
v_cmds="${FZF_COMPLETION_VAR_COMMANDS-export unset printenv}"
|
2014-07-04 00:08:37 +09:00
|
|
|
|
|
|
|
|
|
|
# Preserve existing completion
|
2024-04-25 16:53:43 +09:00
|
|
|
|
__fzf_orig_completion < <(complete -p $d_cmds $a_cmds $v_cmds unalias kill ssh 2> /dev/null)
|
2014-07-18 00:22:49 +09:00
|
|
|
|
|
2024-03-17 15:36:33 +09:00
|
|
|
|
if type _comp_load > /dev/null 2>&1; then
|
|
|
|
|
|
# _comp_load was added in bash-completion 2.12 to replace _completion_loader.
|
|
|
|
|
|
# We use it without -D option so that it does not use _comp_complete_minimal as the fallback.
|
|
|
|
|
|
_fzf_completion_loader=_comp_load
|
|
|
|
|
|
elif type __load_completion > /dev/null 2>&1; then
|
|
|
|
|
|
# In bash-completion 2.11, _completion_loader internally calls __load_completion
|
|
|
|
|
|
# and if it returns a non-zero status, it sets the default 'minimal' completion.
|
|
|
|
|
|
_fzf_completion_loader=__load_completion
|
|
|
|
|
|
elif type _completion_loader > /dev/null 2>&1; then
|
|
|
|
|
|
_fzf_completion_loader=_completion_loader
|
2014-07-04 00:08:37 +09:00
|
|
|
|
fi
|
|
|
|
|
|
|
2019-08-09 11:11:29 +09:00
|
|
|
|
__fzf_defc() {
|
[bash] Refactor access to "_fzf_orig_complete_${cmd//[^A-Za-z0-9_]/_}"
In the current codebase, for the original completion settings, the
pieces of the codes to determine the variable name and to access the
stored data are scattered. In this patch, we define functions to
access these variables. Those functions will be used in a coming
patch.
* This patch also resolves an inconsistent escaping of "$cmd": $cmd is
escaped as ${...//[^A-Za-z0-9_]/_} in some places, but it is escaped
as ${...//[^A-Za-z0-9_=]/_} in some other places. The latter leaves
the character "=" in the command name, which causes an issue because
"=" cannot be a part of a variable name. For example, the following
test case produces an error message:
$ COMP_WORDBREAKS=${COMP_WORDBREAKS//=}
$ _test1() { COMPREPLY=(); }
$ complete -vF _test1 cmd.v=1.0
$ _fzf_setup_completion path cmd.v=1.0
$ cmd.v=1.0 [TAB]
bash: _fzf_orig_completion_cmd_v=1_0: invalid variable name
The behavior of leaving "=" was present from the beginning when
saving the original completion is introduced in commit 91401514, and
this does not seem to be a specific reasoning. In this patch, we
replace "=" as well as the other non-identifier characters.
* Note: In this patch, the variable REPLY is used to return values
from functions. This design is to make it useful with the value
substitutions, a new Bash feature of the next release 5.3, which is
taken from mksh.
2024-03-10 16:31:55 +09:00
|
|
|
|
local cmd func opts REPLY
|
2015-10-12 00:27:30 +09:00
|
|
|
|
cmd="$1"
|
|
|
|
|
|
func="$2"
|
|
|
|
|
|
opts="$3"
|
[bash] Refactor access to "_fzf_orig_complete_${cmd//[^A-Za-z0-9_]/_}"
In the current codebase, for the original completion settings, the
pieces of the codes to determine the variable name and to access the
stored data are scattered. In this patch, we define functions to
access these variables. Those functions will be used in a coming
patch.
* This patch also resolves an inconsistent escaping of "$cmd": $cmd is
escaped as ${...//[^A-Za-z0-9_]/_} in some places, but it is escaped
as ${...//[^A-Za-z0-9_=]/_} in some other places. The latter leaves
the character "=" in the command name, which causes an issue because
"=" cannot be a part of a variable name. For example, the following
test case produces an error message:
$ COMP_WORDBREAKS=${COMP_WORDBREAKS//=}
$ _test1() { COMPREPLY=(); }
$ complete -vF _test1 cmd.v=1.0
$ _fzf_setup_completion path cmd.v=1.0
$ cmd.v=1.0 [TAB]
bash: _fzf_orig_completion_cmd_v=1_0: invalid variable name
The behavior of leaving "=" was present from the beginning when
saving the original completion is introduced in commit 91401514, and
this does not seem to be a specific reasoning. In this patch, we
replace "=" as well as the other non-identifier characters.
* Note: In this patch, the variable REPLY is used to return values
from functions. This design is to make it useful with the value
substitutions, a new Bash feature of the next release 5.3, which is
taken from mksh.
2024-03-10 16:31:55 +09:00
|
|
|
|
if __fzf_orig_completion_instantiate "$cmd" "$func"; then
|
|
|
|
|
|
eval "$REPLY"
|
2015-10-12 00:27:30 +09:00
|
|
|
|
else
|
2025-05-30 20:38:20 +09:00
|
|
|
|
eval "complete -F \"$func\" $opts \"$cmd\""
|
2015-10-12 00:27:30 +09:00
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-20 12:28:41 +09:00
|
|
|
|
# Anything
|
2014-07-04 00:08:37 +09:00
|
|
|
|
for cmd in $a_cmds; do
|
2019-08-09 11:11:29 +09:00
|
|
|
|
__fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"
|
2013-11-20 12:28:41 +09:00
|
|
|
|
done
|
2013-11-20 01:29:36 +09:00
|
|
|
|
|
2016-01-20 01:09:58 +09:00
|
|
|
|
# Directory
|
|
|
|
|
|
for cmd in $d_cmds; do
|
2024-04-04 13:20:10 +09:00
|
|
|
|
__fzf_defc "$cmd" _fzf_dir_completion "-o bashdefault -o nospace -o dirnames"
|
2016-01-20 01:09:58 +09:00
|
|
|
|
done
|
|
|
|
|
|
|
2024-04-25 16:53:43 +09:00
|
|
|
|
# Variables
|
|
|
|
|
|
for cmd in $v_cmds; do
|
|
|
|
|
|
__fzf_defc "$cmd" _fzf_var_completion "-o default -o nospace -v"
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# Aliases
|
|
|
|
|
|
__fzf_defc unalias _fzf_alias_completion "-a"
|
|
|
|
|
|
|
|
|
|
|
|
# Processes
|
|
|
|
|
|
__fzf_defc kill _fzf_proc_completion "-o default -o bashdefault"
|
|
|
|
|
|
|
2023-09-17 18:15:04 +03:00
|
|
|
|
# ssh
|
|
|
|
|
|
__fzf_defc ssh _fzf_complete_ssh "-o default -o bashdefault"
|
|
|
|
|
|
|
2024-04-25 16:53:43 +09:00
|
|
|
|
unset cmd d_cmds a_cmds v_cmds
|
2019-02-28 16:13:59 +09:00
|
|
|
|
|
2019-08-08 15:35:52 +09:00
|
|
|
|
_fzf_setup_completion() {
|
2019-08-09 11:11:29 +09:00
|
|
|
|
local kind fn cmd
|
|
|
|
|
|
kind=$1
|
|
|
|
|
|
fn=_fzf_${1}_completion
|
|
|
|
|
|
if [[ $# -lt 2 ]] || ! type -t "$fn" > /dev/null; then
|
2020-04-18 00:51:06 +09:00
|
|
|
|
echo "usage: ${FUNCNAME[0]} path|dir|var|alias|host|proc COMMANDS..."
|
2019-08-08 15:35:52 +09:00
|
|
|
|
return 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
shift
|
2020-11-11 14:44:47 +00:00
|
|
|
|
__fzf_orig_completion < <(complete -p "$@" 2> /dev/null)
|
2019-08-08 15:35:52 +09:00
|
|
|
|
for cmd in "$@"; do
|
2019-08-09 11:11:29 +09:00
|
|
|
|
case "$kind" in
|
2025-09-24 22:09:37 +09:00
|
|
|
|
dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;
|
|
|
|
|
|
var) __fzf_defc "$cmd" "$fn" "-o default -o nospace -v" ;;
|
2019-12-20 18:39:22 +09:00
|
|
|
|
alias) __fzf_defc "$cmd" "$fn" "-a" ;;
|
2025-09-24 22:09:37 +09:00
|
|
|
|
*) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;
|
2019-08-09 11:11:29 +09:00
|
|
|
|
esac
|
2019-08-08 15:35:52 +09:00
|
|
|
|
done
|
|
|
|
|
|
}
|
2025-09-24 20:47:22 +09:00
|
|
|
|
#----END shfmt
|
2019-08-08 15:35:52 +09:00
|
|
|
|
|
2024-04-10 00:46:09 +09:00
|
|
|
|
fi
|