wd: Make warp point name optional

This commit is contained in:
Charles Crete 2016-10-31 23:49:16 -04:00
commit 36f8345649

View file

@ -72,17 +72,20 @@ wd_print_msg()
wd_print_usage() wd_print_usage()
{ {
cat <<- EOF cat <<- EOF
Usage: wd [command] <point> Usage: wd [command] [point]
Commands: Commands:
add <point> Adds the current working directory to your warp points add <point> Adds the current working directory to your warp points
add Adds the current working directory to your warp points with current directory's name
add! <point> Overwrites existing warp point add! <point> Overwrites existing warp point
add! Overwrites existing warp point with current directory's name
rm <point> Removes the given warp point rm <point> Removes the given warp point
show Print warp points to current directory rm Removes the given warp point with current directory's name
show <point> Print path to given warp point show <point> Print path to given warp point
show Print warp points to current directory
list Print all stored warp points list Print all stored warp points
ls <point> Show files from given warp point ls <point> Show files from given warp point (ls)
path <point> Show the path to given warp point path <point> Show the path to given warp point (pwd)
clean! Remove points warping to nonexistent directories clean! Remove points warping to nonexistent directories
-v | --version Print version -v | --version Print version
@ -154,6 +157,11 @@ wd_add()
local force=$1 local force=$1
local point=$2 local point=$2
if [[ $point == "" ]]
then
point=$(basename $(pwd))
fi
if [[ $point =~ "^[\.]+$" ]] if [[ $point =~ "^[\.]+$" ]]
then then
wd_exit_fail "Warp point cannot be just dots" wd_exit_fail "Warp point cannot be just dots"
@ -163,9 +171,6 @@ wd_add()
elif [[ $point == *:* ]] elif [[ $point == *:* ]]
then then
wd_exit_fail "Warp point cannot contain colons" wd_exit_fail "Warp point cannot contain colons"
elif [[ $point == "" ]]
then
wd_exit_fail "Warp point cannot be empty"
elif [[ ${points[$2]} == "" ]] || $force elif [[ ${points[$2]} == "" ]] || $force
then then
wd_remove $point > /dev/null wd_remove $point > /dev/null
@ -183,7 +188,12 @@ wd_add()
wd_remove() wd_remove()
{ {
local point=$1 local point=$2
if [[ $point == "" ]]
then
point=$(basename $(pwd))
fi
if [[ ${points[$point]} != "" ]] if [[ ${points[$point]} != "" ]]
then then