88# @github.com/mfaerevaag/wd
99
1010# version
11- readonly WD_VERSION=0.9.1
11+ readonly WD_VERSION=0.9.2
1212
1313# colors
1414readonly WD_BLUE=" \033[96m"
@@ -145,14 +145,17 @@ wd_warp()
145145 else
146146 (( n = $# 1 - 1 ))
147147 cd -$n > /dev/null
148+ WD_EXIT_CODE=$?
148149 fi
149150 elif [[ ${points[$point]} != " " ]]
150151 then
151152 if [[ $sub != " " ]]
152153 then
153154 cd ${points[$point]/# \~ / $HOME } /$sub
155+ WD_EXIT_CODE=$?
154156 else
155157 cd ${points[$point]/# \~ / $HOME }
158+ WD_EXIT_CODE=$?
156159 fi
157160 else
158161 wd_exit_fail " Unknown warp point '${point} '"
@@ -185,11 +188,11 @@ wd_add()
185188 elif [[ ${points[$point]} == " " ]] || [ ! -z " $force " ]
186189 then
187190 wd_remove " $point " > /dev/null
188- printf " %q:%s\n" " ${point} " " ${PWD/# $HOME / ~} " >> " $WD_CONFIG "
191+ printf " %q:%s\n" " ${point} " " ${PWD/# $HOME / ~} " >> " $wd_config_file "
189192 if (whence sort > /dev/null); then
190193 local config_tmp=$( mktemp " ${TMPDIR:-/ tmp} /wd.XXXXXXXXXX" )
191- # use 'cat' below to ensure we respect $WD_CONFIG as a symlink
192- command sort -o " ${config_tmp} " " $WD_CONFIG " && command cat " ${config_tmp} " > | " $WD_CONFIG " && command rm " ${config_tmp} "
194+ # use 'cat' below to ensure we respect $wd_config_file as a symlink
195+ command sort -o " ${config_tmp} " " $wd_config_file " && command cat " ${config_tmp} " > | " $wd_config_file " && command rm " ${config_tmp} "
193196 fi
194197
195198 wd_export_static_named_directories
@@ -240,7 +243,7 @@ wd_remove()
240243 then
241244 local config_tmp=$( mktemp " ${TMPDIR:-/ tmp} /wd.XXXXXXXXXX" )
242245 # Copy and delete in two steps in order to preserve symlinks
243- if sed -n " /^${point_name} :.*$/!p" " $WD_CONFIG " > | " $config_tmp " && command cp " $config_tmp " " $WD_CONFIG " && command rm " $config_tmp "
246+ if sed -n " /^${point_name} :.*$/!p" " $wd_config_file " > | " $config_tmp " && command cp " $config_tmp " " $wd_config_file " && command rm " $config_tmp "
244247 then
245248 wd_print_msg " $WD_GREEN " " Warp point removed"
246249 else
@@ -257,7 +260,7 @@ wd_browse() {
257260 echo " This functionality requires fzf. Please install fzf first."
258261 return 1
259262 fi
260- local entries=(" ${(@ f)$(sed " s:${HOME} :~:g" " $WD_CONFIG " | awk -F ' :' ' {print $1 " -> " $2}' )} " )
263+ local entries=(" ${(@ f)$(sed " s:${HOME} :~:g" " $wd_config_file " | awk -F ' :' ' {print $1 " -> " $2}' )} " )
261264 local script_path=" ${${(% ):-% x} : h} "
262265 local wd_remove_output=$( mktemp " ${TMPDIR:-/ tmp} /wd.XXXXXXXXXX" )
263266 entries=(" All warp points:" " Press enter to select. Press delete to remove" " ${entries[@]} " )
@@ -275,7 +278,7 @@ wd_browse() {
275278}
276279
277280wd_browse_widget () {
278- if [[ -e $WD_CONFIG ]]; then
281+ if [[ -e $wd_config_file ]]; then
279282 wd_browse
280283 saved_buffer=$BUFFER
281284 saved_cursor=$CURSOR
@@ -298,7 +301,7 @@ wd_list_all()
298301{
299302 wd_print_msg " $WD_BLUE " " All warp points:"
300303
301- entries=$( sed " s:${HOME} :~:g" " $WD_CONFIG " )
304+ entries=$( sed " s:${HOME} :~:g" " $wd_config_file " )
302305
303306 max_warp_point_length=0
304307 while IFS= read -r line
@@ -398,15 +401,15 @@ wd_clean() {
398401 count=$(( count+ 1 ))
399402 fi
400403 fi
401- done < " $WD_CONFIG "
404+ done < " $wd_config_file "
402405
403406 if [[ $count -eq 0 ]]
404407 then
405408 wd_print_msg " $WD_BLUE " " No warp points to clean, carry on!"
406409 else
407410 if [ ! -z " $force " ] || wd_yesorno " Removing ${count} warp points. Continue? (y/n)"
408411 then
409- echo " $wd_tmp " > ! " $WD_CONFIG "
412+ echo " $wd_tmp " > ! " $wd_config_file "
410413 wd_print_msg " $WD_GREEN " " Cleanup complete. ${count} warp point(s) removed"
411414 else
412415 wd_print_msg " $WD_BLUE " " Cleanup aborted"
@@ -417,7 +420,7 @@ wd_clean() {
417420wd_export_static_named_directories () {
418421 if [[ ! -z $WD_EXPORT ]]
419422 then
420- command grep ' ^[0-9a-zA-Z_-]\+:' " $WD_CONFIG " | sed -e " s,~,$HOME ," -e ' s/:/=/' | while read -r warpdir ; do
423+ command grep ' ^[0-9a-zA-Z_-]\+:' " $wd_config_file " | sed -e " s,~,$HOME ," -e ' s/:/=/' | while read -r warpdir ; do
421424 hash -d " $warpdir "
422425 done
423426 fi
@@ -442,16 +445,19 @@ then
442445 echo " wd version $WD_VERSION "
443446fi
444447
448+ # set the config file from variable or default
449+ typeset wd_config_file=${WD_CONFIG:- $HOME / .warprc}
445450if [[ ! -z $wd_alt_config ]]
446451then
447- WD_CONFIG=$wd_alt_config [2]
452+ # prefer the flag if provided
453+ wd_config_file=$wd_alt_config [2]
448454fi
449455
450456# check if config file exists
451- if [ ! -e " $WD_CONFIG " ]
457+ if [ ! -e " $wd_config_file " ]
452458then
453459 # if not, create config file
454- touch " $WD_CONFIG "
460+ touch " $wd_config_file "
455461else
456462 wd_export_static_named_directories
457463fi
473479 val=${(j,: ,)arr[2,-1]}
474480
475481 points[$key ]=$val
476- done < " $WD_CONFIG "
482+ done < " $wd_config_file "
477483
478484# get opts
479485args=$( getopt -o a:r:c:lhs -l add:,rm:,clean,list,ls:,path:,help,show -- $* )
@@ -484,11 +490,11 @@ then
484490 wd_print_usage
485491
486492# check if config file is writeable
487- elif [ ! -w " $WD_CONFIG " ]
493+ elif [ ! -w " $wd_config_file " ]
488494then
489495 # do nothing
490496 # can't run `exit`, as this would exit the executing shell
491- wd_exit_fail " \'$WD_CONFIG \' is not writeable."
497+ wd_exit_fail " \'$wd_config_file \' is not writeable."
492498
493499else
494500 # parse rest of options
@@ -572,8 +578,10 @@ unset wd_print_msg
572578unset wd_yesorno
573579unset wd_print_usage
574580unset wd_alt_config
581+ unset wd_config_file
575582unset wd_quiet_mode
576583unset wd_print_version
584+ unset wd_force_mode
577585unset wd_export_static_named_directories
578586unset wd_o
579587
0 commit comments