mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-25 07:10:08 +00:00
wd: update to latest version (v0.5.0) (#9244)
This commit is contained in:
parent
a55a30ec39
commit
cbb83cbc31
2 changed files with 177 additions and 166 deletions
|
@ -2,19 +2,19 @@
|
||||||
|
|
||||||
[![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 inefficient 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.
|
||||||
|
|
||||||
![tty.gif](https://raw.githubusercontent.com/mfaerevaag/wd/master/tty.gif)
|
![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](https://github.com/ohmyzsh/ohmyzsh)
|
||||||
|
|
||||||
`wd` comes bundled with [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)!
|
`wd` comes bundled with oh-my-zsh!
|
||||||
|
|
||||||
Just add the plugin in your `~/.zshrc` file:
|
Just add the plugin in your `.zshrc` file:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
plugins=(... wd)
|
plugins=(... wd)
|
||||||
|
@ -38,11 +38,21 @@ antibody bundle mfaerevaag/wd
|
||||||
|
|
||||||
### Arch ([AUR](https://aur.archlinux.org/packages/zsh-plugin-wd-git/))
|
### Arch ([AUR](https://aur.archlinux.org/packages/zsh-plugin-wd-git/))
|
||||||
|
|
||||||
|
1. Install from the AUR
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
yay -S zsh-plugin-wd-git
|
yay -S zsh-plugin-wd-git
|
||||||
# or use any other AUR helper
|
# or use any other AUR helper
|
||||||
```
|
```
|
||||||
|
|
||||||
|
2. Then add to your `.zshrc`:
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
wd() {
|
||||||
|
. /usr/share/wd/wd.sh
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### [zplug](https://github.com/zplug/zplug)
|
### [zplug](https://github.com/zplug/zplug)
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
|
@ -51,7 +61,9 @@ zplug "mfaerevaag/wd", as:command, use:"wd.sh", hook-load:"wd() { . $ZPLUG_REPOS
|
||||||
|
|
||||||
### Automatic
|
### Automatic
|
||||||
|
|
||||||
Run either in terminal:
|
_Note: automatic install does not provide the manpage. It is also poor security practice to run remote code without first reviewing it, so you ought to look [here](https://github.com/mfaerevaag/wd/blob/master/install.sh)_
|
||||||
|
|
||||||
|
Run either command in your terminal:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
curl -L https://github.com/mfaerevaag/wd/raw/master/install.sh | sh
|
curl -L https://github.com/mfaerevaag/wd/raw/master/install.sh | sh
|
||||||
|
@ -65,28 +77,33 @@ wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.
|
||||||
|
|
||||||
### Manual
|
### Manual
|
||||||
|
|
||||||
* Clone this repo to your liking
|
1. Clone this repository on your local machine in a sensible location (if you know what you're doing of course all of this is up to you):
|
||||||
|
|
||||||
* Add `wd` function to `.zshrc` (or `.profile` etc.):
|
```zsh
|
||||||
|
git clone git@github.com:mfaerevaag/wd.git ~/.local/wd --depth 1
|
||||||
|
```
|
||||||
|
|
||||||
```zsh
|
2. Add `wd` function to `.zshrc` (or `.profile` etc.):
|
||||||
wd() {
|
|
||||||
. ~/path/to/cloned/repo/wd/wd.sh
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
* Install manpage. From `wd`'s base directory (requires root permissions):
|
```zsh
|
||||||
|
wd() {
|
||||||
|
. ~/.local/wd/wd.sh
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
```zsh
|
3. Install manpage (optional):
|
||||||
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.
|
```zsh
|
||||||
|
sudo cp ~/.local/wd/wd.1 /usr/share/man/man1/wd.1
|
||||||
|
sudo chmod 644 /usr/share/man/man1/wd.1
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** when pulling and updating `wd`, you'll need to repeat step 3 should the manpage change
|
||||||
|
|
||||||
## 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/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`:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
fpath=(~/path/to/wd $fpath)
|
fpath=(~/path/to/wd $fpath)
|
||||||
|
@ -102,109 +119,110 @@ rm -f ~/.zcompdump; compinit
|
||||||
|
|
||||||
* Add warp point to current working directory:
|
* Add warp point to current working directory:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd add foo
|
wd add foo
|
||||||
```
|
```
|
||||||
|
|
||||||
If a warp point with the same name exists, use `wd add! foo` to overwrite it.
|
If a warp point with the same name exists, use `wd add foo --force` to overwrite it.
|
||||||
|
|
||||||
**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.
|
**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.
|
||||||
|
|
||||||
You can omit point name to automatically use the current directory's name instead.
|
You can omit point name to automatically use the current directory's name instead.
|
||||||
|
|
||||||
* From any directory, warp to `foo` with:
|
* From any directory, warp to `foo` with:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd foo
|
wd foo
|
||||||
```
|
```
|
||||||
|
|
||||||
* You can also warp to a directory within foo, with autocompletion:
|
* You can also warp to a directory within `foo`, with autocompletion:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd foo some/inner/path
|
wd foo some/inner/path
|
||||||
```
|
```
|
||||||
|
|
||||||
* You can warp back to previous directory and higher, with this dot syntax:
|
* You can warp back to previous directory and higher, with this dot syntax:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd ..
|
wd ..
|
||||||
wd ...
|
wd ...
|
||||||
```
|
```
|
||||||
|
|
||||||
This is a wrapper for the zsh's `dirs` function.
|
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))._
|
_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:
|
* Remove warp point:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd rm foo
|
wd rm foo
|
||||||
```
|
```
|
||||||
|
|
||||||
You can omit point name to use the current directory's name instead.
|
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` by default):
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd list
|
wd list
|
||||||
```
|
```
|
||||||
|
|
||||||
* List files in given warp point:
|
* List files in given warp point:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd ls foo
|
wd ls foo
|
||||||
```
|
```
|
||||||
|
|
||||||
* Show path of given warp point:
|
* Show path of given warp point:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd path foo
|
wd path foo
|
||||||
```
|
```
|
||||||
|
|
||||||
* List warp points to current directory, or optionally, path to given warp point:
|
* List warp points to current directory, or optionally, path to given warp point:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd show
|
wd show
|
||||||
```
|
```
|
||||||
|
|
||||||
* Remove warp points to non-existent directories.
|
* Remove warp points to non-existent directories.
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd clean
|
wd clean
|
||||||
```
|
```
|
||||||
|
|
||||||
Use `wd clean!` to not be prompted with confirmation (force).
|
Use `wd clean --force` to not be prompted with confirmation.
|
||||||
|
|
||||||
* Print usage info:
|
* Print usage info:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd help
|
wd help
|
||||||
```
|
```
|
||||||
|
|
||||||
The usage will be printed also if you call `wd` with no command
|
The usage will be printed also if you call `wd` with no command
|
||||||
|
|
||||||
* Print the running version of `wd`:
|
* Print the running version of `wd`:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd --version
|
wd --version
|
||||||
```
|
```
|
||||||
|
|
||||||
* Specifically set the config file (default being `~/.warprc`), which is useful for testing:
|
* Specifically set the config file (default being `~/.warprc`), which is useful for testing:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd --config ./file <command>
|
wd --config ./file <command>
|
||||||
```
|
```
|
||||||
|
|
||||||
* Force `exit` with return code after running. This is not default, as it will *exit your terminal*, though required for testing/debugging.
|
* Force `exit` with return code after running. This is not default, as it will *exit your terminal*, though required for testing/debugging.
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd --debug <command>
|
wd --debug <command>
|
||||||
```
|
```
|
||||||
|
|
||||||
* Silence all output:
|
* Silence all output:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
wd --quiet <command>
|
wd --quiet <command>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
@ -216,7 +234,7 @@ Defines the path where warp points get stored. Defaults to `$HOME/.warprc`.
|
||||||
|
|
||||||
## Testing
|
## 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 they should on your setup, or to demonstrate an issue.
|
`wd` comes with a small test suite, run with [shunit2](https://github.com/kward/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`.
|
To run, simply `cd` into the `test` directory and run the `tests.sh`.
|
||||||
|
|
||||||
|
@ -225,15 +243,17 @@ cd ./test
|
||||||
./tests.sh
|
./tests.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## Maintainers
|
||||||
|
|
||||||
The project is licensed under the [MIT license](https://github.com/mfaerevaag/wd/blob/master/LICENSE).
|
Following @mfaerevaag stepping away from active maintainership of this repository, the following users now are also maintainers of the repo:
|
||||||
|
|
||||||
## Contributing
|
* @alpha-tango-kilo
|
||||||
|
|
||||||
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.
|
* @MattLewin
|
||||||
|
|
||||||
----
|
Anyone else contributing is greatly appreciated and will be mentioned in the release notes!
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
Credit to [altschuler](https://github.com/altschuler) for an awesome idea.
|
Credit to [altschuler](https://github.com/altschuler) for an awesome idea.
|
||||||
|
|
||||||
|
|
143
plugins/wd/wd.sh
143
plugins/wd/wd.sh
|
@ -8,7 +8,7 @@
|
||||||
# @github.com/mfaerevaag/wd
|
# @github.com/mfaerevaag/wd
|
||||||
|
|
||||||
# version
|
# version
|
||||||
readonly WD_VERSION=0.4.6
|
readonly WD_VERSION=0.5.0
|
||||||
|
|
||||||
# colors
|
# colors
|
||||||
readonly WD_BLUE="\033[96m"
|
readonly WD_BLUE="\033[96m"
|
||||||
|
@ -79,8 +79,6 @@ Commands:
|
||||||
<point> <path> Warps to the directory specified by the warp point with path appended
|
<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 <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 Adds the current working directory to your warp points with current directory's name
|
||||||
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
|
||||||
rm Removes the given warp point with current directory's name
|
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
|
||||||
|
@ -88,12 +86,13 @@ Commands:
|
||||||
list Print all stored warp points
|
list Print all stored warp points
|
||||||
ls <point> Show files from given warp point (ls)
|
ls <point> Show files from given warp point (ls)
|
||||||
path <point> Show the path to given warp point (pwd)
|
path <point> Show the path to given warp point (pwd)
|
||||||
clean! Remove points warping to nonexistent directories
|
clean Remove points warping to nonexistent directories (will prompt unless --force is used)
|
||||||
|
|
||||||
-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
|
||||||
|
-f | --force Allows overwriting without warning (for add & clean)
|
||||||
|
|
||||||
help Show this extremely helpful text
|
help Show this extremely helpful text
|
||||||
EOF
|
EOF
|
||||||
|
@ -103,7 +102,7 @@ wd_exit_fail()
|
||||||
{
|
{
|
||||||
local msg=$1
|
local msg=$1
|
||||||
|
|
||||||
wd_print_msg $WD_RED $msg
|
wd_print_msg "$WD_RED" "$msg"
|
||||||
WD_EXIT_CODE=1
|
WD_EXIT_CODE=1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +110,7 @@ wd_exit_warn()
|
||||||
{
|
{
|
||||||
local msg=$1
|
local msg=$1
|
||||||
|
|
||||||
wd_print_msg $WD_YELLOW $msg
|
wd_print_msg "$WD_YELLOW" "$msg"
|
||||||
WD_EXIT_CODE=1
|
WD_EXIT_CODE=1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +118,7 @@ wd_getdir()
|
||||||
{
|
{
|
||||||
local name_arg=$1
|
local name_arg=$1
|
||||||
|
|
||||||
point=$(wd_show $name_arg)
|
point=$(wd_show "$name_arg")
|
||||||
dir=${point:28+$#name_arg+7}
|
dir=${point:28+$#name_arg+7}
|
||||||
|
|
||||||
if [[ -z $name_arg ]]; then
|
if [[ -z $name_arg ]]; then
|
||||||
|
@ -162,12 +161,12 @@ wd_warp()
|
||||||
|
|
||||||
wd_add()
|
wd_add()
|
||||||
{
|
{
|
||||||
local force=$1
|
local point=$1
|
||||||
local point=$2
|
local force=$2
|
||||||
|
|
||||||
if [[ $point == "" ]]
|
if [[ $point == "" ]]
|
||||||
then
|
then
|
||||||
point=$(basename $PWD)
|
point=$(basename "$PWD")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $point =~ "^[\.]+$" ]]
|
if [[ $point =~ "^[\.]+$" ]]
|
||||||
|
@ -179,57 +178,59 @@ 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 [[ ${points[$point]} == "" ]] || $force
|
elif [[ ${points[$point]} == "" ]] || [ ! -z "$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"
|
||||||
if (whence sort >/dev/null); then
|
if (whence sort >/dev/null); then
|
||||||
local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX")
|
local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX")
|
||||||
# use 'cat' below to ensure we respect $WD_CONFIG as a symlink
|
# use 'cat' below to ensure we respect $WD_CONFIG as a symlink
|
||||||
sort -o "${config_tmp}" $WD_CONFIG && cat "${config_tmp}" > $WD_CONFIG && rm "${config_tmp}"
|
sort -o "${config_tmp}" "$WD_CONFIG" && cat "${config_tmp}" > "$WD_CONFIG" && rm "${config_tmp}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wd_export_static_named_directories
|
wd_export_static_named_directories
|
||||||
|
|
||||||
wd_print_msg $WD_GREEN "Warp point added"
|
wd_print_msg "$WD_GREEN" "Warp point added"
|
||||||
|
|
||||||
# override exit code in case wd_remove did not remove any points
|
# override exit code in case wd_remove did not remove any points
|
||||||
# TODO: we should handle this kind of logic better
|
# TODO: we should handle this kind of logic better
|
||||||
WD_EXIT_CODE=0
|
WD_EXIT_CODE=0
|
||||||
else
|
else
|
||||||
wd_exit_warn "Warp point '${point}' already exists. Use 'add!' to overwrite."
|
wd_exit_warn "Warp point '${point}' already exists. Use 'add --force' to overwrite."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
wd_remove()
|
wd_remove()
|
||||||
{
|
{
|
||||||
local point=$1
|
local point_list=$1
|
||||||
|
|
||||||
if [[ $point == "" ]]
|
if [[ "$point_list" == "" ]]
|
||||||
then
|
then
|
||||||
point=$(basename $PWD)
|
point_list=$(basename "$PWD")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${points[$point]} != "" ]]
|
for point_name in $point_list ; do
|
||||||
|
if [[ ${points[$point_name]} != "" ]]
|
||||||
then
|
then
|
||||||
local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX")
|
local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX")
|
||||||
# Copy and delete in two steps in order to preserve symlinks
|
# 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
|
if sed -n "/^${point_name}:.*$/!p" "$WD_CONFIG" > "$config_tmp" && command cp "$config_tmp" "$WD_CONFIG" && command rm "$config_tmp"
|
||||||
then
|
then
|
||||||
wd_print_msg $WD_GREEN "Warp point removed"
|
wd_print_msg "$WD_GREEN" "Warp point removed"
|
||||||
else
|
else
|
||||||
wd_exit_fail "Something bad happened! Sorry."
|
wd_exit_fail "Something bad happened! Sorry."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
wd_exit_fail "Warp point was not found"
|
wd_exit_fail "Warp point was not found"
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
wd_list_all()
|
wd_list_all()
|
||||||
{
|
{
|
||||||
wd_print_msg $WD_BLUE "All warp points:"
|
wd_print_msg "$WD_BLUE" "All warp points:"
|
||||||
|
|
||||||
entries=$(sed "s:${HOME}:~:g" $WD_CONFIG)
|
entries=$(sed "s:${HOME}:~:g" "$WD_CONFIG")
|
||||||
|
|
||||||
max_warp_point_length=0
|
max_warp_point_length=0
|
||||||
while IFS= read -r line
|
while IFS= read -r line
|
||||||
|
@ -242,7 +243,7 @@ wd_list_all()
|
||||||
then
|
then
|
||||||
max_warp_point_length=$length
|
max_warp_point_length=$length
|
||||||
fi
|
fi
|
||||||
done <<< $entries
|
done <<< "$entries"
|
||||||
|
|
||||||
while IFS= read -r line
|
while IFS= read -r line
|
||||||
do
|
do
|
||||||
|
@ -254,35 +255,35 @@ wd_list_all()
|
||||||
|
|
||||||
if [[ -z $wd_quiet_mode ]]
|
if [[ -z $wd_quiet_mode ]]
|
||||||
then
|
then
|
||||||
printf "%${max_warp_point_length}s -> %s\n" $key $val
|
printf "%${max_warp_point_length}s -> %s\n" "$key" "$val"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done <<< $entries
|
done <<< "$entries"
|
||||||
}
|
}
|
||||||
|
|
||||||
wd_ls()
|
wd_ls()
|
||||||
{
|
{
|
||||||
wd_getdir $1
|
wd_getdir "$1"
|
||||||
ls ${dir/#\~/$HOME}
|
ls "${dir/#\~/$HOME}"
|
||||||
}
|
}
|
||||||
|
|
||||||
wd_path()
|
wd_path()
|
||||||
{
|
{
|
||||||
wd_getdir $1
|
wd_getdir "$1"
|
||||||
echo $(echo $dir | sed "s:${HOME}:~:g")
|
echo "$(echo "$dir" | sed "s:${HOME}:~:g")"
|
||||||
}
|
}
|
||||||
|
|
||||||
wd_show()
|
wd_show()
|
||||||
{
|
{
|
||||||
local name_arg=$1
|
local name_arg=$1
|
||||||
# if there's an argument we look up the value
|
# if there's an argument we look up the value
|
||||||
if [[ ! -z $name_arg ]]
|
if [[ -n $name_arg ]]
|
||||||
then
|
then
|
||||||
if [[ -z $points[$name_arg] ]]
|
if [[ -z $points[$name_arg] ]]
|
||||||
then
|
then
|
||||||
wd_print_msg $WD_BLUE "No warp point named $name_arg"
|
wd_print_msg "$WD_BLUE" "No warp point named $name_arg"
|
||||||
else
|
else
|
||||||
wd_print_msg $WD_GREEN "Warp point: ${WD_GREEN}$name_arg${WD_NOC} -> $points[$name_arg]"
|
wd_print_msg "$WD_GREEN" "Warp point: ${WD_GREEN}$name_arg${WD_NOC} -> $points[$name_arg]"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# hax to create a local empty array
|
# hax to create a local empty array
|
||||||
|
@ -290,19 +291,19 @@ wd_show()
|
||||||
wd_matches=()
|
wd_matches=()
|
||||||
# do a reverse lookup to check whether PWD is in $points
|
# do a reverse lookup to check whether PWD is in $points
|
||||||
PWD="${PWD/$HOME/~}"
|
PWD="${PWD/$HOME/~}"
|
||||||
if [[ ${points[(r)$PWD]} == $PWD ]]
|
if [[ ${points[(r)$PWD]} == "$PWD" ]]
|
||||||
then
|
then
|
||||||
for name in ${(k)points}
|
for name in ${(k)points}
|
||||||
do
|
do
|
||||||
if [[ $points[$name] == $PWD ]]
|
if [[ $points[$name] == "$PWD" ]]
|
||||||
then
|
then
|
||||||
wd_matches[$(($#wd_matches+1))]=$name
|
wd_matches[$(($#wd_matches+1))]=$name
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
wd_print_msg $WD_BLUE "$#wd_matches warp point(s) to current directory: ${WD_GREEN}$wd_matches${WD_NOC}"
|
wd_print_msg "$WD_BLUE" "$#wd_matches warp point(s) to current directory: ${WD_GREEN}$wd_matches${WD_NOC}"
|
||||||
else
|
else
|
||||||
wd_print_msg $WD_YELLOW "No warp point to $(echo $PWD | sed "s:$HOME:~:")"
|
wd_print_msg "$WD_YELLOW" "No warp point to $(echo "$PWD" | sed "s:$HOME:~:")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -312,7 +313,7 @@ wd_clean() {
|
||||||
local count=0
|
local count=0
|
||||||
local wd_tmp=""
|
local wd_tmp=""
|
||||||
|
|
||||||
while read line
|
while read -r line
|
||||||
do
|
do
|
||||||
if [[ $line != "" ]]
|
if [[ $line != "" ]]
|
||||||
then
|
then
|
||||||
|
@ -322,32 +323,32 @@ wd_clean() {
|
||||||
|
|
||||||
if [ -d "${val/#\~/$HOME}" ]
|
if [ -d "${val/#\~/$HOME}" ]
|
||||||
then
|
then
|
||||||
wd_tmp=$wd_tmp"\n"`echo $line`
|
wd_tmp=$wd_tmp"\n"`echo "$line"`
|
||||||
else
|
else
|
||||||
wd_print_msg $WD_YELLOW "Nonexistent directory: ${key} -> ${val}"
|
wd_print_msg "$WD_YELLOW" "Nonexistent directory: ${key} -> ${val}"
|
||||||
count=$((count+1))
|
count=$((count+1))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done < $WD_CONFIG
|
done < "$WD_CONFIG"
|
||||||
|
|
||||||
if [[ $count -eq 0 ]]
|
if [[ $count -eq 0 ]]
|
||||||
then
|
then
|
||||||
wd_print_msg $WD_BLUE "No warp points to clean, carry on!"
|
wd_print_msg "$WD_BLUE" "No warp points to clean, carry on!"
|
||||||
else
|
else
|
||||||
if $force || wd_yesorno "Removing ${count} warp points. Continue? (Y/n)"
|
if [ ! -z "$force" ] || wd_yesorno "Removing ${count} warp points. Continue? (y/n)"
|
||||||
then
|
then
|
||||||
echo $wd_tmp >! $WD_CONFIG
|
echo "$wd_tmp" >! "$WD_CONFIG"
|
||||||
wd_print_msg $WD_GREEN "Cleanup complete. ${count} warp point(s) removed"
|
wd_print_msg "$WD_GREEN" "Cleanup complete. ${count} warp point(s) removed"
|
||||||
else
|
else
|
||||||
wd_print_msg $WD_BLUE "Cleanup aborted"
|
wd_print_msg "$WD_BLUE" "Cleanup aborted"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
wd_export_static_named_directories() {
|
wd_export_static_named_directories() {
|
||||||
if [[ -z $WD_SKIP_EXPORT ]]
|
if [[ ! -z $WD_EXPORT ]]
|
||||||
then
|
then
|
||||||
command grep '^[0-9a-zA-Z_-]\+:' "$WD_CONFIG" | sed -e "s,~,$HOME," -e 's/:/=/' | while read warpdir ; do
|
command grep '^[0-9a-zA-Z_-]\+:' "$WD_CONFIG" | sed -e "s,~,$HOME," -e 's/:/=/' | while read -r warpdir ; do
|
||||||
hash -d "$warpdir"
|
hash -d "$warpdir"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
@ -366,7 +367,8 @@ zparseopts -D -E \
|
||||||
c:=wd_alt_config -config:=wd_alt_config \
|
c:=wd_alt_config -config:=wd_alt_config \
|
||||||
q=wd_quiet_mode -quiet=wd_quiet_mode \
|
q=wd_quiet_mode -quiet=wd_quiet_mode \
|
||||||
v=wd_print_version -version=wd_print_version \
|
v=wd_print_version -version=wd_print_version \
|
||||||
d=wd_debug_mode -debug=wd_debug_mode
|
d=wd_debug_mode -debug=wd_debug_mode \
|
||||||
|
f=wd_force_mode -force=wd_force_mode
|
||||||
|
|
||||||
if [[ ! -z $wd_print_version ]]
|
if [[ ! -z $wd_print_version ]]
|
||||||
then
|
then
|
||||||
|
@ -379,10 +381,10 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if config file exists
|
# check if config file exists
|
||||||
if [ ! -e $WD_CONFIG ]
|
if [ ! -e "$WD_CONFIG" ]
|
||||||
then
|
then
|
||||||
# if not, create config file
|
# if not, create config file
|
||||||
touch $WD_CONFIG
|
touch "$WD_CONFIG"
|
||||||
else
|
else
|
||||||
wd_export_static_named_directories
|
wd_export_static_named_directories
|
||||||
fi
|
fi
|
||||||
|
@ -397,25 +399,24 @@ do
|
||||||
val=${(j,:,)arr[2,-1]}
|
val=${(j,:,)arr[2,-1]}
|
||||||
|
|
||||||
points[$key]=$val
|
points[$key]=$val
|
||||||
done < $WD_CONFIG
|
done < "$WD_CONFIG"
|
||||||
|
|
||||||
# get opts
|
# get opts
|
||||||
args=$(getopt -o a:r:c:lhs -l add:,rm:,clean\!,list,ls:,path:,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
|
# check if no arguments were given, and that version is not set
|
||||||
if [[ ($? -ne 0 || $#* -eq 0) && -z $wd_print_version ]]
|
if [[ ($? -ne 0 || $#* -eq 0) && -z $wd_print_version ]]
|
||||||
then
|
then
|
||||||
wd_print_usage
|
wd_print_usage
|
||||||
|
|
||||||
# check if config file is writeable
|
# check if config file is writeable
|
||||||
elif [ ! -w $WD_CONFIG ]
|
elif [ ! -w "$WD_CONFIG" ]
|
||||||
then
|
then
|
||||||
# do nothing
|
# do nothing
|
||||||
# can't run `exit`, as this would exit the executing shell
|
# can't run `exit`, as this would exit the executing shell
|
||||||
wd_exit_fail "\'$WD_CONFIG\' is not writeable."
|
wd_exit_fail "\'$WD_CONFIG\' is not writeable."
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
# parse rest of options
|
# parse rest of options
|
||||||
local wd_o
|
local wd_o
|
||||||
for wd_o
|
for wd_o
|
||||||
|
@ -423,11 +424,7 @@ else
|
||||||
case "$wd_o"
|
case "$wd_o"
|
||||||
in
|
in
|
||||||
"-a"|"--add"|"add")
|
"-a"|"--add"|"add")
|
||||||
wd_add false $2
|
wd_add "$2" "$wd_force_mode"
|
||||||
break
|
|
||||||
;;
|
|
||||||
"-a!"|"--add!"|"add!")
|
|
||||||
wd_add true $2
|
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"-e"|"export")
|
"-e"|"export")
|
||||||
|
@ -435,10 +432,8 @@ else
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"-r"|"--remove"|"rm")
|
"-r"|"--remove"|"rm")
|
||||||
# Loop over all arguments after "rm", separated by whitespace
|
# Passes all the arguments as a single string separated by whitespace to wd_remove
|
||||||
for pointname in "${@:2}" ; do
|
wd_remove "${@:2}"
|
||||||
wd_remove $pointname
|
|
||||||
done
|
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"-l"|"list")
|
"-l"|"list")
|
||||||
|
@ -446,11 +441,11 @@ else
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"-ls"|"ls")
|
"-ls"|"ls")
|
||||||
wd_ls $2
|
wd_ls "$2"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"-p"|"--path"|"path")
|
"-p"|"--path"|"path")
|
||||||
wd_path $2
|
wd_path "$2"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"-h"|"--help"|"help")
|
"-h"|"--help"|"help")
|
||||||
|
@ -458,19 +453,15 @@ else
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"-s"|"--show"|"show")
|
"-s"|"--show"|"show")
|
||||||
wd_show $2
|
wd_show "$2"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"-c"|"--clean"|"clean")
|
"-c"|"--clean"|"clean")
|
||||||
wd_clean false
|
wd_clean "$wd_force_mode"
|
||||||
break
|
|
||||||
;;
|
|
||||||
"-c!"|"--clean!"|"clean!")
|
|
||||||
wd_clean true
|
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
wd_warp $wd_o $2
|
wd_warp "$wd_o" "$2"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
|
@ -502,7 +493,7 @@ unset args
|
||||||
unset points
|
unset points
|
||||||
unset val &> /dev/null # fixes issue #1
|
unset val &> /dev/null # fixes issue #1
|
||||||
|
|
||||||
if [[ ! -z $wd_debug_mode ]]
|
if [[ -n $wd_debug_mode ]]
|
||||||
then
|
then
|
||||||
exit $WD_EXIT_CODE
|
exit $WD_EXIT_CODE
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue