1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-12 08:50:08 +00:00

wd: update to latest version (#8530)

This commit is contained in:
Marc Cornellà 2020-06-03 18:35:51 +02:00
parent 0fd11130a3
commit 82f02e80a6
4 changed files with 209 additions and 97 deletions

View file

@ -1,5 +1,4 @@
wd
==
# wd
[![Build Status](https://travis-ci.org/mfaerevaag/wd.png?branch=master)](https://travis-ci.org/mfaerevaag/wd)
@ -9,150 +8,232 @@ wd
*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
`wd` comes bundled with [oh-my-zshell](https://github.com/ohmyzsh/ohmyzsh)!
`wd` comes bundled with [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)!
Just add the plugin in your `~/.zshrc` file:
plugins=(... wd)
```zsh
plugins=(... wd)
```
### [Antigen](https://github.com/zsh-users/antigen)
#### Automatic
In your `.zshrc`:
```zsh
antigen bundle mfaerevaag/wd
```
### [Antibody](https://github.com/getantibody/antibody)
In your `.zshrc`:
```zsh
antibody bundle mfaerevaag/wd
```
### Arch ([AUR](https://aur.archlinux.org/packages/zsh-plugin-wd-git/))
```zsh
yay -S zsh-plugin-wd-git
# or use any other AUR helper
```
### [zplug](https://github.com/zplug/zplug)
```zsh
zplug "mfaerevaag/wd", as:command, use:"wd.sh", hook-load:"wd() { . $ZPLUG_REPOS/mfaerevaag/wd/wd.sh }"
```
### Automatic
Run either in terminal:
* `curl -L https://github.com/mfaerevaag/wd/raw/master/install.sh | sh`
```zsh
curl -L https://github.com/mfaerevaag/wd/raw/master/install.sh | sh
```
* `wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.sh -O - | sh`
or
##### Arch ([AUR](https://aur.archlinux.org/))
```zsh
wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.sh -O - | sh
```
# yaourt -S zsh-plugin-wd-git
### Manual
* Clone this repo to your liking
#### Manual
* Clone this repo to your liking
* Add `wd` function to `.zshrc` (or `.profile` etc.):
* Add `wd` function to `.zshrc` (or `.profile` etc.):
```zsh
wd() {
. ~/path/to/cloned/repo/wd/wd.sh
}
```
* Install manpage. From `wd`'s base directory (requires root permissions):
* Install manpage. From `wd`'s base directory (requires root permissions):
# cp wd.1 /usr/share/man/man1/wd.1
# chmod 644 /usr/share/man/man1/wd.1
```zsh
cp wd.1 /usr/share/man/man1/wd.1
chmod 644 /usr/share/man/man1/wd.1
```
Note, when pulling and updating `wd`, you'll need to do this again in case of changes to the manpage.
**Note:** when pulling and updating `wd`, you'll need to do this again in case of changes to the manpage.
## Completion
#### Completion
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`:
If you're NOT using [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) 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)
```zsh
fpath=(~/path/to/wd $fpath)
```
Also, you may have to force a rebuild of `zcompdump` by running:
$ rm -f ~/.zcompdump; compinit
```zsh
rm -f ~/.zcompdump; compinit
```
## Usage
* Add warp point to current working directory:
### Usage
```zsh
wd add foo
```
* Add warp point to current working directory:
If a warp point with the same name exists, use `wd add! foo` to overwrite it.
$ wd add foo
**Note:** a warp point cannot contain colons, or 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.
If a warp point with the same name exists, use `add!` to overwrite it.
You can omit point name to automatically use the current directory's name instead.
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.
* From any directory, warp to `foo` with:
```zsh
wd foo
```
* You can also warp to a directory within foo, with autocompletion:
```zsh
wd foo some/inner/path
```
* You can warp back to previous directory and higher, with this dot syntax:
```zsh
wd ..
wd ...
```
This is a wrapper for the zsh's `dirs` function.
_You might need to add `setopt AUTO_PUSHD` to your `.zshrc` if you are not using [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh))._
* Remove warp point:
```zsh
wd rm foo
```
You can omit point name to use the current directory's name instead.
* From an other directory (not necessarily), warp to `foo` with:
* List all warp points (stored in `~/.warprc`):
$ wd foo
```zsh
wd list
```
* You can warp back to previous directory, and so on, with this dot syntax:
* List files in given warp point:
$ wd ..
$ wd ...
```zsh
wd ls foo
```
This is a wrapper for the zsh `dirs` function.
(You might need `setopt AUTO_PUSHD` in your `.zshrc` if you hare not using [oh-my-zshell](https://github.com/ohmyzsh/ohmyzsh)).
* Show path of given warp point:
* Remove warp point test point:
```zsh
wd path foo
```
$ wd rm foo
* List warp points to current directory, or optionally, path to given warp point:
You can omit point name to use the current directory's name instead.
```zsh
wd show
```
* List all warp points (stored in `~/.warprc`):
* Remove warp points to non-existent directories.
$ wd list
```zsh
wd clean
```
* List files in given warp point:
Use `wd clean!` to not be prompted with confirmation (force).
$ wd ls foo
* Print usage info:
* Show path of given warp point:
```zsh
wd help
```
$ wd path foo
The usage will be printed also if you call `wd` with no command
* List warp points to current directory, or optionally, path to given warp point:
* Print the running version of `wd`:
$ wd show
```zsh
wd --version
```
* Remove warp points to non-existent directories.
* Specifically set the config file (default being `~/.warprc`), which is useful for testing:
$ wd clean
```zsh
wd --config ./file <command>
```
Use `clean!` to not be prompted with confirmation (force).
* Force `exit` with return code after running. This is not default, as it will *exit your terminal*, though required for testing/debugging.
* Print usage with no opts or the `help` argument:
```zsh
wd --debug <command>
```
$ wd help
* Silence all output:
* Print the running version of `wd`:
```zsh
wd --quiet <command>
```
$ wd --version
## Configuration
* Specifically set the config file (default `~/.warprc`), which is useful when testing:
You can configure `wd` with the following environment variables:
$ wd --config ./file <action>
### `WD_CONFIG`
* Force `exit` with return code after running. This is not default, as it will *exit your terminal*, though required when testing/debugging.
Defines the path where warp points get stored. Defaults to `$HOME/.warprc`.
$ wd --debug <action>
## Testing
* Silence all output:
$ wd --quiet <action>
### Testing
`wd` comes with a small test suite, run with [shunit2](https://code.google.com/p/shunit2/). This can be used to confirm that things are working as it should on your setup, or to demonstrate an issue.
`wd` comes with a small test suite, run with [shunit2](https://code.google.com/p/shunit2/). This can be used to confirm that things are working as they should on your setup, or to demonstrate an issue.
To run, simply `cd` into the `test` directory and run the `tests.sh`.
$ ./tests.sh
```zsh
cd ./test
./tests.sh
```
## License
### License
The project is licensed under the [MIT license](https://github.com/mfaerevaag/wd/blob/master/LICENSE).
The project is licensed under the [MIT-license](https://github.com/mfaerevaag/wd/blob/master/LICENSE).
## Contributing
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.
### 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`. For an explanation on how to run the tests, read the section "Testing" in this README.
----
Credit to [altschuler](https://github.com/altschuler) for an awesome idea.

View file

@ -1,6 +1,6 @@
#compdef wd
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion::complete:wd:*:descriptions' format '%B%d%b'
zstyle ':completion::complete:wd:*:commands' group-name commands
zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
zstyle ':completion::complete:wd::' list-grouped
@ -8,13 +8,13 @@ zstyle ':completion::complete:wd::' list-grouped
zmodload zsh/mapfile
function _wd() {
local CONFIG=$HOME/.warprc
local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc}
local ret=1
local -a commands
local -a warp_points
warp_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" )
warp_points=( "${(f)mapfile[$WD_CONFIG]//$HOME/~}" )
typeset -A points
while read -r line
@ -27,11 +27,12 @@ function _wd() {
target_path=${target_path/#\~/$HOME}
points[$name]=$target_path
done < $CONFIG
done < $WD_CONFIG
commands=(
'add:Adds the current working directory to your warp points'
'add!:Overwrites existing warp point'
'export:Export warp points as static named directories'
'rm:Removes the given warp point'
'list:Outputs all stored warp points'
'ls:Show files from given warp point'
@ -72,8 +73,12 @@ function _wd() {
_describe -t points "Warp points" warp_points && ret=0
;;
*)
if [[ -v points[$target] ]]; then
# complete sub directories from the warp point
_path_files -W "(${points[$target]})" -/ && ret=0
fi
# don't complete anything if warp point is not valid
;;
esac
;;

View file

@ -1,6 +1,9 @@
#!/bin/zsh
# WARP DIRECTORY
# ==============
# oh-my-zsh plugin
# Jump to custom directories in terminal
# because `cd` takes too long...
#
# @github.com/mfaerevaag/wd

View file

@ -36,11 +36,11 @@ wd_yesorno()
read -r answer
case ${answer:=${default}} in
Y|y|YES|yes|Yes )
"Y"|"y"|"YES"|"yes"|"Yes" )
RETVAL=${yes_RETVAL} && \
break
;;
N|n|NO|no|No )
"N"|"n"|"NO"|"no"|"No" )
RETVAL=${no_RETVAL} && \
break
;;
@ -75,6 +75,8 @@ wd_print_usage()
Usage: wd [command] [point]
Commands:
<point> Warps to the directory specified by the warp point
<point> <path> Warps to the directory specified by the warp point with path appended
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
@ -182,6 +184,8 @@ wd_add()
wd_remove $point > /dev/null
printf "%q:%s\n" "${point}" "${PWD/#$HOME/~}" >> $WD_CONFIG
wd_export_static_named_directories
wd_print_msg $WD_GREEN "Warp point added"
# override exit code in case wd_remove did not remove any points
@ -203,8 +207,9 @@ wd_remove()
if [[ ${points[$point]} != "" ]]
then
local config_tmp=$WD_CONFIG.tmp
if sed -n "/^${point}:.*$/!p" $WD_CONFIG > $config_tmp && mv $config_tmp $WD_CONFIG
local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX")
# Copy and delete in two steps in order to preserve symlinks
if sed -n "/^${point}:.*$/!p" $WD_CONFIG > $config_tmp && cp $config_tmp $WD_CONFIG && rm $config_tmp
then
wd_print_msg $WD_GREEN "Warp point removed"
else
@ -334,7 +339,16 @@ wd_clean() {
fi
}
local WD_CONFIG=$HOME/.warprc
wd_export_static_named_directories() {
if [[ -z $WD_SKIP_EXPORT ]]
then
grep '^[0-9a-zA-Z_-]\+:' "$WD_CONFIG" | sed -e "s,~,$HOME," -e 's/:/=/' | while read warpdir ; do
hash -d "$warpdir"
done
fi
}
local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc}
local WD_QUIET=0
local WD_EXIT_CODE=0
local WD_DEBUG=0
@ -364,6 +378,8 @@ if [ ! -e $WD_CONFIG ]
then
# if not, create config file
touch $WD_CONFIG
else
wd_export_static_named_directories
fi
# load warp points
@ -396,52 +412,57 @@ then
else
# parse rest of options
for o
local wd_o
for wd_o
do
case "$o"
case "$wd_o"
in
-a|--add|add)
"-a"|"--add"|"add")
wd_add false $2
break
;;
-a!|--add!|add!)
"-a!"|"--add!"|"add!")
wd_add true $2
break
;;
-r|--remove|rm)
"-e"|"export")
wd_export_static_named_directories
break
;;
"-r"|"--remove"|"rm")
wd_remove $2
break
;;
-l|list)
"-l"|"list")
wd_list_all
break
;;
-ls|ls)
"-ls"|"ls")
wd_ls $2
break
;;
-p|--path|path)
"-p"|"--path"|"path")
wd_path $2
break
;;
-h|--help|help)
"-h"|"--help"|"help")
wd_print_usage
break
;;
-s|--show|show)
"-s"|"--show"|"show")
wd_show $2
break
;;
-c|--clean|clean)
"-c"|"--clean"|"clean")
wd_clean false
break
;;
-c!|--clean!|clean!)
"-c!"|"--clean!"|"clean!")
wd_clean true
break
;;
*)
wd_warp $o $2
wd_warp $wd_o $2
break
;;
--)
@ -466,6 +487,8 @@ unset wd_print_usage
unset wd_alt_config
unset wd_quiet_mode
unset wd_print_version
unset wd_export_static_named_directories
unset wd_o
unset args
unset points