add bash support
This commit is contained in:
@@ -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=(\
|
||||
|
||||
Reference in New Issue
Block a user