summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-03-13 20:56:31 +0900
committerGitHub <noreply@github.com>2024-03-13 20:56:31 +0900
commitd282a1649d7d953f028306f13d6616958f3fd1f3 (patch)
treeddab9c74f9afbf1d66f391064bb3fb8ee870cf53 /shell
parent6ce8d49d1b6a38a1a7cbb02e2726956b211f46be (diff)
Add walker options and replace 'find' with the built-in walker (#3649)
Diffstat (limited to 'shell')
-rw-r--r--shell/completion.bash44
-rw-r--r--shell/completion.zsh46
-rw-r--r--shell/key-bindings.bash21
-rw-r--r--shell/key-bindings.fish21
-rw-r--r--shell/key-bindings.zsh10
5 files changed, 67 insertions, 75 deletions
diff --git a/shell/completion.bash b/shell/completion.bash
index 6f60ecf0..7d34af2c 100644
--- a/shell/completion.bash
+++ b/shell/completion.bash
@@ -13,22 +13,19 @@
# To use custom commands instead of find, override _fzf_compgen_{path,dir}
-if ! declare -F _fzf_compgen_path > /dev/null; then
- _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@^\./@@'
- }
-fi
-
-if ! declare -F _fzf_compgen_dir > /dev/null; then
- _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@^\./@@'
- }
-fi
+#
+# _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@^\./@@'
+# }
###########################################################
@@ -336,9 +333,18 @@ __fzf_generic_path_completion() {
leftover=${leftover/#\/}
[[ -z "$dir" ]] && dir='.'
[[ "$dir" != "/" ]] && dir="${dir/%\//}"
- matches=$(eval "$1 $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $2" __fzf_comprun "$4" -q "$leftover" | while read -r item; do
- printf "%q " "${item%$3}$3"
- done)
+ matches=$(
+ unset FZF_DEFAULT_COMMAND
+ export FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $2"
+ if declare -F "$1" > /dev/null; then
+ eval "$1 $(printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover"
+ else
+ [[ $1 =~ dir ]] && walker=dir,follow || walker=file,dir,follow,hidden
+ __fzf_comprun "$4" -q "$leftover" --walker "$walker" --walker-root="$dir"
+ fi | while read -r item; do
+ printf "%q " "${item%$3}$3"
+ done
+ )
matches=${matches% }
[[ -z "$3" ]] && [[ "${__fzf_nospace_commands-}" = *" ${COMP_WORDS[0]} "* ]] && matches="$matches "
if [[ -n "$matches" ]]; then
diff --git a/shell/completion.zsh b/shell/completion.zsh
index c4ba2c75..163b0299 100644
--- a/shell/completion.zsh
+++ b/shell/completion.zsh
@@ -77,22 +77,19 @@ fi
{
# To use custom commands instead of find, override _fzf_compgen_{path,dir}
-if ! declare -f _fzf_compgen_path > /dev/null; then
- _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 | sed 's@^\./@@'
- }
-fi
-
-if ! declare -f _fzf_compgen_dir > /dev/null; then
- _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 | sed 's@^\./@@'
- }
-fi
+#
+# _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 | 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 | sed 's@^\./@@'
+# }
###########################################################
@@ -148,10 +145,19 @@ __fzf_generic_path_completion() {
leftover=${leftover/#\/}
[ -z "$dir" ] && dir='.'
[ "$dir" != "/" ] && dir="${dir/%\//}"
- matches=$(eval "$compgen $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-}" __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" | while read item; do
- item="${item%$suffix}$suffix"
- echo -n "${(q)item} "
- done)
+ matches=$(
+ unset FZF_DEFAULT_COMMAND
+ export FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-}"
+ if declare -f "$compgen" > /dev/null; then
+ eval "$compgen $(printf %q "$dir")" | __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover"
+ else
+ [[ $compgen =~ dir ]] && walker=dir,follow || walker=file,dir,follow,hidden
+ __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" --walker "$walker" --walker-root="$dir" < /dev/tty
+ fi | while read item; do
+ item="${item%$suffix}$suffix"
+ echo -n "${(q)item} "
+ done
+ )
matches=${matches% }
if [ -n "$matches" ]; then
LBUFFER="$lbuf$matches$tail"
diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash
index c4dce3ba..f6cd48f1 100644
--- a/shell/key-bindings.bash
+++ b/shell/key-bindings.bash
@@ -17,14 +17,9 @@
# Key bindings
# ------------
__fzf_select__() {
- local cmd opts
- cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
- -o -type f -print \
- -o -type d -print \
- -o -type l -print 2> /dev/null | command cut -b3-"}"
- opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_CTRL_T_OPTS-} -m"
- eval "$cmd" |
- FZF_DEFAULT_OPTS="$opts" $(__fzfcmd) "$@" |
+ local opts
+ opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --walker=file,dir,follow,hidden --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_CTRL_T_OPTS-} -m"
+ FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} FZF_DEFAULT_OPTS="$opts" $(__fzfcmd) "$@" |
while read -r item; do
printf '%q ' "$item" # escape special chars
done
@@ -42,11 +37,11 @@ fzf-file-widget() {
}
__fzf_cd__() {
- local cmd opts dir
- cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
- -o -type d -print 2> /dev/null | command cut -b3-"}"
- opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-} +m"
- dir=$(set +o pipefail; eval "$cmd" | FZF_DEFAULT_OPTS="$opts" $(__fzfcmd)) && printf 'builtin cd -- %q' "$dir"
+ local opts dir
+ opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --walker=dir,follow,hidden --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-} +m"
+ dir=$(
+ FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} FZF_DEFAULT_OPTS="$opts" $(__fzfcmd)
+ ) && printf 'builtin cd -- %q' "$dir"
}
if command -v perl > /dev/null; then
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
index 69f76970..51ddcc0d 100644
--- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -25,18 +25,11 @@ function fzf_key_bindings
set -l fzf_query $commandline[2]
set -l prefix $commandline[3]
- # "-path \$dir'*/.*'" matches hidden files/folders inside $dir but not
- # $dir itself, even if hidden.
- test -n "$FZF_CTRL_T_COMMAND"; or set -l FZF_CTRL_T_COMMAND "
- command find -L \$dir -mindepth 1 \\( -path \$dir'*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
- -o -type f -print \
- -o -type d -print \
- -o -type l -print 2> /dev/null | sed 's@^\./@@'"
-
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
begin
- set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --scheme=path --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS"
- eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end
+ set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --walker=file,dir,follow,hidden --scheme=path --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS"
+ set -lx FZF_DEFAULT_COMMAND "$FZF_CTRL_T_COMMAND"
+ eval (__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end
end
if [ -z "$result" ]
commandline -f repaint
@@ -81,13 +74,11 @@ function fzf_key_bindings
set -l fzf_query $commandline[2]
set -l prefix $commandline[3]
- test -n "$FZF_ALT_C_COMMAND"; or set -l FZF_ALT_C_COMMAND "
- command find -L \$dir -mindepth 1 \\( -path \$dir'*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
- -o -type d -print 2> /dev/null | sed 's@^\./@@'"
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
begin
- set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --scheme=path --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS"
- eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)' +m --query "'$fzf_query'"' | read -l result
+ set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --walker=dir,follow,hidden --scheme=path --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS"
+ set -lx FZF_DEFAULT_COMMAND "$FZF_ALT_C_COMMAND"
+ eval (__fzfcmd)' +m --query "'$fzf_query'"' | read -l result
if [ -n "$result" ]
cd -- $result
diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh
index 7d0a14d6..a3699add 100644
--- a/shell/key-bindings.zsh
+++ b/shell/key-bindings.zsh
@@ -41,13 +41,9 @@ fi
# CTRL-T - Paste the selected file path(s) into the command line
__fsel() {
- local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
- -o -type f -print \
- -o -type d -print \
- -o -type l -print 2> /dev/null | cut -b3-"}"
setopt localoptions pipefail no_aliases 2> /dev/null
local item
- eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_CTRL_T_OPTS-}" $(__fzfcmd) -m "$@" | while read item; do
+ FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --walker=file,dir,follow,hidden --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_CTRL_T_OPTS-}" $(__fzfcmd) -m "$@" < /dev/tty | while read item; do
echo -n "${(q)item} "
done
local ret=$?
@@ -73,10 +69,8 @@ bindkey -M viins '^T' fzf-file-widget
# ALT-C - cd into the selected directory
fzf-cd-widget() {
- local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
- -o -type d -print 2> /dev/null | cut -b3-"}"
setopt localoptions pipefail no_aliases 2> /dev/null
- local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-}" $(__fzfcmd) +m)"
+ local dir="$(FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --walker=dir,follow,hidden --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-}" $(__fzfcmd) +m < /dev/tty)"
if [[ -z "$dir" ]]; then
zle redisplay
return 0