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