diff options
Diffstat (limited to 'plugins/wd')
-rw-r--r-- | plugins/wd/README.md | 14 | ||||
-rw-r--r-- | plugins/wd/_wd.sh | 13 | ||||
-rwxr-xr-x | plugins/wd/wd.sh | 72 |
3 files changed, 86 insertions, 13 deletions
diff --git a/plugins/wd/README.md b/plugins/wd/README.md index bcfeab684..ed149eb3e 100644 --- a/plugins/wd/README.md +++ b/plugins/wd/README.md @@ -5,6 +5,8 @@ wd `wd` (*warp directory*) lets you jump to custom directories in zsh, without using `cd`. Why? Because `cd` seems ineffecient when the folder is frequently visited or has a long path. +*NOTE*: If you are not using zsh, check out the `ruby` branch which has `wd` implemented as a gem. + ### Setup @@ -33,7 +35,7 @@ Run either in terminal: * Add `wd` function to `.zshrc` (or `.profile` etc.): wd() { - . ~/paht/to/wd/wd.sh + . ~/path/to/cloned/repo/wd/wd.sh } * Install manpage. From `wd`'s base directory (requires root permissions): @@ -84,7 +86,15 @@ Also, you may have to force a rebuild of `zcompdump` by running: * List all warp points (stored in `~/.warprc`): - $ wd ls + $ wd list + + * List files in given warp point: + + $ wd ls foo + + * Show path of given warp point: + + $ wd path foo * List warp points to current directory, or optionally, path to given warp point: diff --git a/plugins/wd/_wd.sh b/plugins/wd/_wd.sh index 2bb58dd31..b67f4a1e2 100644 --- a/plugins/wd/_wd.sh +++ b/plugins/wd/_wd.sh @@ -20,10 +20,13 @@ function _wd() { 'add:Adds the current working directory to your warp points' 'add!:Overwrites existing warp point' 'rm:Removes the given warp point' - 'ls:Outputs all stored warp points' - 'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point' + 'list:Outputs all stored warp points' + 'ls:Show files from given warp point' + 'path:Show path to given warp point' 'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point' 'help:Show this extremely helpful text' + 'clean:Remove points warping to nonexistent directories' + 'clean!:Remove nonexistent directories without confirmation' '..:Go back to last directory' ) @@ -47,6 +50,12 @@ function _wd() { show) _describe -t points "Warp points" warp_points && ret=0 ;; + ls) + _describe -t points "Warp points" warp_points && ret=0 + ;; + path) + _describe -t points "Warp points" warp_points && ret=0 + ;; esac ;; esac diff --git a/plugins/wd/wd.sh b/plugins/wd/wd.sh index 5ecbdc503..cf54713bd 100755 --- a/plugins/wd/wd.sh +++ b/plugins/wd/wd.sh @@ -8,7 +8,7 @@ # @github.com/mfaerevaag/wd # version -readonly WD_VERSION=0.4 +readonly WD_VERSION=0.4.2 # colors readonly WD_BLUE="\033[96m" @@ -80,7 +80,9 @@ Commands: rm <point> Removes the given warp point show Print warp points to current directory show <point> Print path to given warp point - ls Print all stored warp points + list Print all stored warp points +ls <point> Show files from given warp point +path <point> Show the path to given warp point clean! Remove points warping to nonexistent directories -v | --version Print version @@ -96,7 +98,7 @@ wd_exit_fail() { local msg=$1 - wd_print_msg $WD_RED $1 + wd_print_msg $WD_RED $msg WD_EXIT_CODE=1 } @@ -108,6 +110,22 @@ wd_exit_warn() WD_EXIT_CODE=1 } +wd_getdir() +{ + local name_arg=$1 + + point=$(wd_show $name_arg) + dir=${point:28+$#name_arg+7} + + if [[ -z $name_arg ]]; then + wd_exit_fail "You must enter a warp point" + break + elif [[ -z $dir ]]; then + wd_exit_fail "Unknown warp point '${name_arg}'" + break + fi +} + # core wd_warp() @@ -125,7 +143,7 @@ wd_warp() fi elif [[ ${points[$point]} != "" ]] then - cd ${points[$point]} + cd ${points[$point]/#\~/$HOME} else wd_exit_fail "Unknown warp point '${point}'" fi @@ -151,7 +169,7 @@ wd_add() elif [[ ${points[$2]} == "" ]] || $force then wd_remove $point > /dev/null - printf "%q:%s\n" "${point}" "${PWD}" >> $WD_CONFIG + printf "%q:%s\n" "${point}" "${PWD/#$HOME/~}" >> $WD_CONFIG wd_print_msg $WD_GREEN "Warp point added" @@ -185,6 +203,21 @@ wd_list_all() { wd_print_msg $WD_BLUE "All warp points:" + entries=$(sed "s:${HOME}:~:g" $WD_CONFIG) + + max_warp_point_length=0 + while IFS= read -r line + do + arr=(${(s,:,)line}) + key=${arr[1]} + + length=${#key} + if [[ length -gt max_warp_point_length ]] + then + max_warp_point_length=$length + fi + done <<< $entries + while IFS= read -r line do if [[ $line != "" ]] @@ -195,10 +228,22 @@ wd_list_all() if [[ -z $wd_quiet_mode ]] then - printf "%20s -> %s\n" $key $val + printf "%${max_warp_point_length}s -> %s\n" $key $val fi fi - done <<< $(sed "s:${HOME}:~:g" $WD_CONFIG) + done <<< $entries +} + +wd_ls() +{ + wd_getdir $1 + ls ${dir/#\~/$HOME} +} + +wd_path() +{ + wd_getdir $1 + echo $(echo $dir | sed "s:${HOME}:~:g") } wd_show() @@ -218,6 +263,7 @@ wd_show() local wd_matches wd_matches=() # do a reverse lookup to check whether PWD is in $points + PWD="${PWD/$HOME/~}" if [[ ${points[(r)$PWD]} == $PWD ]] then for name in ${(k)points} @@ -316,7 +362,7 @@ do done < $WD_CONFIG # get opts -args=$(getopt -o a:r:c:lhs -l add:,rm:,clean\!,ls,help,show -- $*) +args=$(getopt -o a:r:c:lhs -l add:,rm:,clean\!,list,ls:,path:,help,show -- $*) # check if no arguments were given, and that version is not set if [[ ($? -ne 0 || $#* -eq 0) && -z $wd_print_version ]] @@ -349,10 +395,18 @@ else wd_remove $2 break ;; - -l|--list|ls) + -l|list) wd_list_all break ;; + -ls|ls) + wd_ls $2 + break + ;; + -p|--path|path) + wd_path $2 + break + ;; -h|--help|help) wd_print_usage break |