From 66715afbbe64f075fa1d4de5dad8bfe424544605 Mon Sep 17 00:00:00 2001 From: Donaldttt Date: Sat, 18 Jun 2022 03:38:32 -0400 Subject: [PATCH] add bash support --- bash_tools/fzf_file_seletor.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bash_tools/fzf_file_seletor.sh b/bash_tools/fzf_file_seletor.sh index 209c63a..b1b9ca8 100755 --- a/bash_tools/fzf_file_seletor.sh +++ b/bash_tools/fzf_file_seletor.sh @@ -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=(\