support just list files

This commit is contained in:
Donaldttt
2022-06-18 14:34:36 -04:00
parent b99efa340f
commit dc915e293f
+19 -9
View File
@@ -36,30 +36,34 @@ no_fzf(){
} }
dp(){ dp(){
local debug=1 local debug=0
[ "$debug" = "1" ] && echo $1 [ "$debug" = "1" ] && echo $1
} }
# SHELL specific setting # SHELL specific setting
if [ ! -z "$ZSH_NAME" ]; then if [ ! -z "$ZSH_NAME" ]; then
SHELL_NAME=zsh
dp "[bash_tools]: In ZSH shell" dp "[bash_tools]: In ZSH shell"
# disable error output when # disable error output when
# wildcard found 0 match # wildcard found 0 match
setopt +o nomatch setopt +o nomatch
#setopt extended_glob
# show hidden file when using wildcard # show hidden file when using wildcard
# use in fzf_selector # use in fzf_selector
# only for zsh # only for zsh
setopt dotglob setopt dotglob
setopt glob_dots setopt glob_dots
else else
# temporary
SHELL_NAME=bash
dp "[bash_tools]: In non-ZSH shell" dp "[bash_tools]: In non-ZSH shell"
# only for bash # only for bash
shopt -s dotglob shopt -s dotglob
# allow reverse wildcard exp. !(b*) # allow reverse wildcard exp. !(b*)
# shopt -u extglob # shopt -s extglob
# allows filename patterns which match no # allows filename patterns which match no
# files to expand to a null string, rather # files to expand to a null string, rather
@@ -88,13 +92,19 @@ fzf_selector() {
all_items=(*/) all_items=(*/)
elif [ $2 = 2 ]; then elif [ $2 = 2 ]; then
dp "try to find files" dp "try to find files"
all=(*) if [ "$SHELL_NAME" = "zsh" ]; then
all_items=() eval "all_items=(*(^/))"
for item in "${all[@]}"; do elif [ "$SHELL_NAME" = "bash" ]; then
grep -P *$1*[^/]$ <<< $item > /dev/null 2>&1 && \ # no easy way to list just regular files
all_items+=("$item") # in bash???
done all=(*)
all_items=()
for item in "${all[@]}"; do
[ -f "$item" ] && all_items+=("$item")
done
fi
fi fi
dp "${all_items[@]}" dp "${all_items[@]}"
#shopt -u dotglob #shopt -u dotglob