From 426fffe46b49358c69361f094ee22b7f480a90ac Mon Sep 17 00:00:00 2001 From: Donaldttt Date: Sat, 18 Jun 2022 17:16:52 -0400 Subject: [PATCH] make script more reliable --- bash_tools.sh | 12 ++++++------ bash_tools/fzf_file_seletor.sh | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bash_tools.sh b/bash_tools.sh index 29d0064..1392090 100644 --- a/bash_tools.sh +++ b/bash_tools.sh @@ -5,22 +5,22 @@ # If no argument supplied, the host machine's ip will # be used # doc for api: https://ip-api.com/docs/api -ipinfo(){ - api_str=http://ip-api.com/json/$1?fields=query,country,regionName,city,district,zip,isp,org,reverse,mobile,proxy,hosting +function ipinfo(){ + local api_str="http://ip-api.com/json/$1?fields=query,country,regionName,city,district,zip,isp,org,reverse,mobile,proxy,hosting" if ! hash python; then - curl $api_str + curl "$api_str" else - curl -s $api_str | python -m json.tool + curl -s "$api_str" | python -m json.tool fi } # find file contain certain text string($2) in certain directory($1) -fct(){ +function fct(){ grep -rnw $1 -e $2 } # online directory -odict(){ +function odict(){ curl dict://dict.org/d:"${1}" } diff --git a/bash_tools/fzf_file_seletor.sh b/bash_tools/fzf_file_seletor.sh index a3c8bc5..cd6068d 100755 --- a/bash_tools/fzf_file_seletor.sh +++ b/bash_tools/fzf_file_seletor.sh @@ -23,7 +23,7 @@ cd \ ) # in case above functions are broken -no_fzf(){ +function no_fzf(){ for c in "${fzf_command_list_all[@]}"; do unalias $c done @@ -35,7 +35,7 @@ no_fzf(){ done } -dp(){ +function dp(){ local debug=0 [ "$debug" = "1" ] && echo $1 } @@ -78,7 +78,7 @@ ret='' # 0: show all # 1: only show directories # 2: only show files -fzf_selector() { +function fzf_selector() { ret=$1 if [ "$1" = "." ] || [ "$1" = ".." ] || \ [[ "$1" == -* ]] || [[ "$1" == */* ]]; then @@ -130,7 +130,7 @@ fzf_selector() { # $1 command for fzf substuting(like ls) # $2 original args pass to function # $3 command require file type (file: 0 |directory: 1) -fzf_command_execute() { +function fzf_command_execute() { local args=($@) local len=${#args[@]}