add bash support

This commit is contained in:
Donaldttt
2022-06-18 03:38:32 -04:00
parent 2fbae37118
commit 66715afbbe
+16 -2
View File
@@ -3,6 +3,11 @@
# For any command require a file path, this function
# helps to select the correct file with key words
dp(){
local debug=0
[ "$debug" = "1" ] && echo $1
}
ret=''
# $1 keyword
@@ -11,16 +16,18 @@ ret=''
# 1: only show directory
fzf_selector() {
ret=$1
fchar=(${1[@]})
fchar=(${ret[@]})
if [ "$1" = "." ] || [ "$1" = ".." ] || [ $fchar = "-" ]; then
return 1
fi
shopt -s dotglob
if [ $2 = 0 ]; then
all_items=(*)
elif [ $2 = 1 ]; then
all_items=(*/)
fi
#shopt -u dotglob
files=()
for item in "${all_items[@]}"; do
@@ -46,16 +53,21 @@ fzf_selector() {
# $3 command require file type (file: 0 |directory: 1)
fzf_command_execute() {
local args=($@)
local len=${#args}
local len=${#args[@]}
dp "lens: $len"
# zsh shell's array starts with 1 rather than 0
if [ ! -z "$ZSH_NAME" ]; then
dp "zsh"
flag="${args[2]}"
unset 'args[2]'
else
dp "not zsh"
flag="${args[1]}"
unset 'args[1]'
fi
dp "flag: $flag"
if [ "$len" = "2" ]; then
$args
@@ -66,6 +78,7 @@ fzf_command_execute() {
keyword="${args[-1]}"
dp "keyword: $keyword"
# Delete last argument
# Here we assume it is a file path
unset 'args[-1]'
@@ -77,6 +90,7 @@ fzf_command_execute() {
fzf_command_list_file=(\
vim \
set_wallpaper \
)
fzf_command_list_dir=(\