mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-19 21:41:07 +01:00
[wd] Update wd plugin to latest version (#6371)
* [wd] Update wd plugin to v0.4.3 * [wd] Update wd plugin to v0.4.4
This commit is contained in:
parent
2e4539b0d4
commit
2102d10896
3 changed files with 78 additions and 33 deletions
|
@ -3,16 +3,17 @@ wd
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/mfaerevaag/wd.png?branch=master)](https://travis-ci.org/mfaerevaag/wd)
|
[![Build Status](https://travis-ci.org/mfaerevaag/wd.png?branch=master)](https://travis-ci.org/mfaerevaag/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.
|
`wd` (*warp directory*) lets you jump to custom directories in zsh, without using `cd`. Why? Because `cd` seems inefficient 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.
|
![tty.gif](https://raw.githubusercontent.com/mfaerevaag/wd/master/tty.gif)
|
||||||
|
|
||||||
|
*NEWS*: If you are not using zsh, check out the c-port, [wd-c](https://github.com/mfaerevaag/wd-c), which works with all shells using wrapper functions.
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
### oh-my-zsh
|
### oh-my-zsh
|
||||||
|
|
||||||
`wd` comes bundles with [oh-my-zshell](https://github.com/robbyrussell/oh-my-zsh)!
|
`wd` comes bundled with [oh-my-zshell](https://github.com/robbyrussell/oh-my-zsh)!
|
||||||
|
|
||||||
Just add the plugin in your `~/.zshrc` file:
|
Just add the plugin in your `~/.zshrc` file:
|
||||||
|
|
||||||
|
@ -27,6 +28,10 @@ Run either in terminal:
|
||||||
|
|
||||||
* `wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.sh -O - | sh`
|
* `wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.sh -O - | sh`
|
||||||
|
|
||||||
|
##### Arch ([AUR](https://aur.archlinux.org/))
|
||||||
|
|
||||||
|
# yaourt -S zsh-plugin-wd-git
|
||||||
|
|
||||||
|
|
||||||
#### Manual
|
#### Manual
|
||||||
|
|
||||||
|
@ -48,7 +53,7 @@ Run either in terminal:
|
||||||
|
|
||||||
#### Completion
|
#### Completion
|
||||||
|
|
||||||
If you're NOT using [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) and you want to utelize the zsh-completion feature, you will also need to add the path to your `wd` installation (`~/bin/wd` if you used the automatic installer) to your `fpath`. E.g. in your `~/.zshrc`:
|
If you're NOT using [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) and you want to utilize the zsh-completion feature, you will also need to add the path to your `wd` installation (`~/bin/wd` if you used the automatic installer) to your `fpath`. E.g. in your `~/.zshrc`:
|
||||||
|
|
||||||
fpath=(~/path/to/wd $fpath)
|
fpath=(~/path/to/wd $fpath)
|
||||||
|
|
||||||
|
@ -66,7 +71,9 @@ Also, you may have to force a rebuild of `zcompdump` by running:
|
||||||
|
|
||||||
If a warp point with the same name exists, use `add!` to overwrite it.
|
If a warp point with the same name exists, use `add!` to overwrite it.
|
||||||
|
|
||||||
Note, a warp point cannot contain colons, or only consist of only spaces and dots. The first will conflict in how `wd` stores the warp points, and the second will conflict other features, as below.
|
Note, a warp point cannot contain colons, or only consist of only spaces and dots. The first will conflict in how `wd` stores the warp points, and the second will conflict with other features, as below.
|
||||||
|
|
||||||
|
You can omit point name to use the current directory's name instead.
|
||||||
|
|
||||||
* From an other directory (not necessarily), warp to `foo` with:
|
* From an other directory (not necessarily), warp to `foo` with:
|
||||||
|
|
||||||
|
@ -84,6 +91,8 @@ Also, you may have to force a rebuild of `zcompdump` by running:
|
||||||
|
|
||||||
$ wd rm foo
|
$ wd rm foo
|
||||||
|
|
||||||
|
You can omit point name to use the current directory's name instead.
|
||||||
|
|
||||||
* List all warp points (stored in `~/.warprc`):
|
* List all warp points (stored in `~/.warprc`):
|
||||||
|
|
||||||
$ wd list
|
$ wd list
|
||||||
|
@ -143,8 +152,8 @@ The project is licensed under the [MIT-license](https://github.com/mfaerevaag/wd
|
||||||
|
|
||||||
### Finally
|
### Finally
|
||||||
|
|
||||||
If you have issues, feedback or improvements, don't hesitate to report it or submit a pull-request. In the case of an issue, we would much appreciate if you would include a failing test in `test/tests.sh`. Explanation on how to run the tests, read the section "Testing" in this README.
|
If you have issues, feedback or improvements, don't hesitate to report it or submit a pull-request. In the case of an issue, we would much appreciate if you would include a failing test in `test/tests.sh`. For an explanation on how to run the tests, read the section "Testing" in this README.
|
||||||
|
|
||||||
Credit to [altschuler](https://github.com/altschuler) for awesome idea.
|
Credit to [altschuler](https://github.com/altschuler) for an awesome idea.
|
||||||
|
|
||||||
Hope you enjoy!
|
Hope you enjoy!
|
||||||
|
|
|
@ -16,6 +16,19 @@ function _wd() {
|
||||||
|
|
||||||
warp_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" )
|
warp_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" )
|
||||||
|
|
||||||
|
typeset -A points
|
||||||
|
while read -r line
|
||||||
|
do
|
||||||
|
arr=(${(s,:,)line})
|
||||||
|
name=${arr[1]}
|
||||||
|
path=${arr[2]}
|
||||||
|
|
||||||
|
# replace ~ from path to fix completion (#17)
|
||||||
|
path=${path/#\~/$HOME}
|
||||||
|
|
||||||
|
points[$name]=$path
|
||||||
|
done < $CONFIG
|
||||||
|
|
||||||
commands=(
|
commands=(
|
||||||
'add:Adds the current working directory to your warp points'
|
'add:Adds the current working directory to your warp points'
|
||||||
'add!:Overwrites existing warp point'
|
'add!:Overwrites existing warp point'
|
||||||
|
@ -34,13 +47,15 @@ function _wd() {
|
||||||
'1: :->first_arg' \
|
'1: :->first_arg' \
|
||||||
'2: :->second_arg' && ret=0
|
'2: :->second_arg' && ret=0
|
||||||
|
|
||||||
|
local target=$words[2]
|
||||||
|
|
||||||
case $state in
|
case $state in
|
||||||
first_arg)
|
first_arg)
|
||||||
_describe -t warp_points "Warp points" warp_points && ret=0
|
_describe -t warp_points "Warp points" warp_points && ret=0
|
||||||
_describe -t commands "Commands" commands && ret=0
|
_describe -t commands "Commands" commands && ret=0
|
||||||
;;
|
;;
|
||||||
second_arg)
|
second_arg)
|
||||||
case $words[2] in
|
case $target in
|
||||||
add\!|rm)
|
add\!|rm)
|
||||||
_describe -t points "Warp points" warp_points && ret=0
|
_describe -t points "Warp points" warp_points && ret=0
|
||||||
;;
|
;;
|
||||||
|
@ -56,6 +71,10 @@ function _wd() {
|
||||||
path)
|
path)
|
||||||
_describe -t points "Warp points" warp_points && ret=0
|
_describe -t points "Warp points" warp_points && ret=0
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
# complete sub directories from the warp point
|
||||||
|
_path_files -W "(${points[$target]})" -/ && ret=0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
# @github.com/mfaerevaag/wd
|
# @github.com/mfaerevaag/wd
|
||||||
|
|
||||||
# version
|
# version
|
||||||
readonly WD_VERSION=0.4.2
|
readonly WD_VERSION=0.4.4
|
||||||
|
|
||||||
# colors
|
# colors
|
||||||
readonly WD_BLUE="\033[96m"
|
readonly WD_BLUE="\033[96m"
|
||||||
|
@ -72,25 +72,28 @@ 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! <point> Overwrites existing warp point
|
add Adds the current working directory to your warp points with current directory's name
|
||||||
rm <point> Removes the given warp point
|
add! <point> Overwrites existing warp point
|
||||||
show Print warp points to current directory
|
add! Overwrites existing warp point with current directory's name
|
||||||
show <point> Print path to given warp point
|
rm <point> Removes the given warp point
|
||||||
list Print all stored warp points
|
rm Removes the given warp point with current directory's name
|
||||||
ls <point> Show files from given warp point
|
show <point> Print path to given warp point
|
||||||
path <point> Show the path to given warp point
|
show Print warp points to current directory
|
||||||
clean! Remove points warping to nonexistent directories
|
list Print all stored warp points
|
||||||
|
ls <point> Show files from given warp point (ls)
|
||||||
|
path <point> Show the path to given warp point (pwd)
|
||||||
|
clean! Remove points warping to nonexistent directories
|
||||||
|
|
||||||
-v | --version Print version
|
-v | --version Print version
|
||||||
-d | --debug Exit after execution with exit codes (for testing)
|
-d | --debug Exit after execution with exit codes (for testing)
|
||||||
-c | --config Specify config file (default ~/.warprc)
|
-c | --config Specify config file (default ~/.warprc)
|
||||||
-q | --quiet Suppress all output
|
-q | --quiet Suppress all output
|
||||||
|
|
||||||
help Show this extremely helpful text
|
help Show this extremely helpful text
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +134,11 @@ wd_getdir()
|
||||||
wd_warp()
|
wd_warp()
|
||||||
{
|
{
|
||||||
local point=$1
|
local point=$1
|
||||||
|
local sub=$2
|
||||||
|
|
||||||
if [[ $point =~ "^\.+$" ]]
|
if [[ $point =~ "^\.+$" ]]
|
||||||
then
|
then
|
||||||
if [ $#1 < 2 ]
|
if [[ $#1 < 2 ]]
|
||||||
then
|
then
|
||||||
wd_exit_warn "Warping to current directory?"
|
wd_exit_warn "Warping to current directory?"
|
||||||
else
|
else
|
||||||
|
@ -143,7 +147,12 @@ wd_warp()
|
||||||
fi
|
fi
|
||||||
elif [[ ${points[$point]} != "" ]]
|
elif [[ ${points[$point]} != "" ]]
|
||||||
then
|
then
|
||||||
cd ${points[$point]/#\~/$HOME}
|
if [[ $sub != "" ]]
|
||||||
|
then
|
||||||
|
cd ${points[$point]/#\~/$HOME}/$sub
|
||||||
|
else
|
||||||
|
cd ${points[$point]/#\~/$HOME}
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
wd_exit_fail "Unknown warp point '${point}'"
|
wd_exit_fail "Unknown warp point '${point}'"
|
||||||
fi
|
fi
|
||||||
|
@ -154,6 +163,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,10 +177,7 @@ 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 == "" ]]
|
elif [[ ${points[$point]} == "" ]] || $force
|
||||||
then
|
|
||||||
wd_exit_fail "Warp point cannot be empty"
|
|
||||||
elif [[ ${points[$2]} == "" ]] || $force
|
|
||||||
then
|
then
|
||||||
wd_remove $point > /dev/null
|
wd_remove $point > /dev/null
|
||||||
printf "%q:%s\n" "${point}" "${PWD/#$HOME/~}" >> $WD_CONFIG
|
printf "%q:%s\n" "${point}" "${PWD/#$HOME/~}" >> $WD_CONFIG
|
||||||
|
@ -185,6 +196,11 @@ wd_remove()
|
||||||
{
|
{
|
||||||
local point=$1
|
local point=$1
|
||||||
|
|
||||||
|
if [[ $point == "" ]]
|
||||||
|
then
|
||||||
|
point=$(basename $PWD)
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ${points[$point]} != "" ]]
|
if [[ ${points[$point]} != "" ]]
|
||||||
then
|
then
|
||||||
local config_tmp=$WD_CONFIG.tmp
|
local config_tmp=$WD_CONFIG.tmp
|
||||||
|
@ -294,7 +310,7 @@ wd_clean() {
|
||||||
key=${arr[1]}
|
key=${arr[1]}
|
||||||
val=${arr[2]}
|
val=${arr[2]}
|
||||||
|
|
||||||
if [ -d "$val" ]
|
if [ -d "${val/#\~/$HOME}" ]
|
||||||
then
|
then
|
||||||
wd_tmp=$wd_tmp"\n"`echo $line`
|
wd_tmp=$wd_tmp"\n"`echo $line`
|
||||||
else
|
else
|
||||||
|
@ -356,7 +372,8 @@ while read -r line
|
||||||
do
|
do
|
||||||
arr=(${(s,:,)line})
|
arr=(${(s,:,)line})
|
||||||
key=${arr[1]}
|
key=${arr[1]}
|
||||||
val=${arr[2]}
|
# join the rest, in case the path contains colons
|
||||||
|
val=${(j,:,)arr[2,-1]}
|
||||||
|
|
||||||
points[$key]=$val
|
points[$key]=$val
|
||||||
done < $WD_CONFIG
|
done < $WD_CONFIG
|
||||||
|
@ -424,7 +441,7 @@ else
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
wd_warp $o
|
wd_warp $o $2
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
|
|
Loading…
Reference in a new issue