1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-01-26 01:57:26 +08:00

Compare commits

..

No commits in common. "3667f94538c24ebaa9abd46e797a2610f3b67c5e" and "708ea42384d378343a590fc34a3dee536a1651df" have entirely different histories.

4 changed files with 167 additions and 182 deletions

View File

@ -29,7 +29,7 @@ if [[ $FOUND_PYENV -ne 1 ]]; then
fi
if [[ $FOUND_PYENV -eq 1 ]]; then
eval "$(pyenv init - --no-rehash zsh)"
eval "$(pyenv init - zsh)"
if (( $+commands[pyenv-virtualenv-init] )); then
eval "$(pyenv virtualenv-init - zsh)"
fi

View File

@ -2,19 +2,19 @@
[![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)
*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
### [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)
### oh-my-zsh
`wd` comes bundled with oh-my-zsh!
`wd` comes bundled with [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)!
Just add the plugin in your `.zshrc` file:
Just add the plugin in your `~/.zshrc` file:
```zsh
plugins=(... wd)
@ -38,21 +38,11 @@ antibody bundle mfaerevaag/wd
### Arch ([AUR](https://aur.archlinux.org/packages/zsh-plugin-wd-git/))
1. Install from the AUR
```zsh
yay -S zsh-plugin-wd-git
# 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)
```zsh
@ -61,9 +51,7 @@ zplug "mfaerevaag/wd", as:command, use:"wd.sh", hook-load:"wd() { . $ZPLUG_REPOS
### Automatic
_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:
Run either in terminal:
```zsh
curl -L https://github.com/mfaerevaag/wd/raw/master/install.sh | sh
@ -77,33 +65,28 @@ wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.
### Manual
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):
* Clone this repo to your liking
```zsh
git clone git@github.com:mfaerevaag/wd.git ~/.local/wd --depth 1
```
2. Add `wd` function to `.zshrc` (or `.profile` etc.):
* Add `wd` function to `.zshrc` (or `.profile` etc.):
```zsh
wd() {
. ~/.local/wd/wd.sh
. ~/path/to/cloned/repo/wd/wd.sh
}
```
3. Install manpage (optional):
* Install manpage. From `wd`'s base directory (requires root permissions):
```zsh
sudo cp ~/.local/wd/wd.1 /usr/share/man/man1/wd.1
sudo chmod 644 /usr/share/man/man1/wd.1
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 repeat step 3 should the manpage change
**Note:** when pulling and updating `wd`, you'll need to do this again in case of changes to the manpage.
## 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
fpath=(~/path/to/wd $fpath)
@ -123,10 +106,9 @@ rm -f ~/.zcompdump; compinit
wd add foo
```
If a warp point with the same name exists, use `wd add foo --force` to overwrite it.
If a warp point with the same name exists, use `wd add! foo` 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.
@ -136,7 +118,7 @@ You can omit point name to automatically use the current directory's name instea
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
wd foo some/inner/path
@ -150,7 +132,7 @@ 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)._
_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:
@ -160,7 +142,7 @@ wd rm foo
You can omit point name to use the current directory's name instead.
* List all warp points (stored in `~/.warprc` by default):
* List all warp points (stored in `~/.warprc`):
```zsh
wd list
@ -190,7 +172,7 @@ wd show
wd clean
```
Use `wd clean --force` to not be prompted with confirmation.
Use `wd clean!` to not be prompted with confirmation (force).
* Print usage info:
@ -234,7 +216,7 @@ Defines the path where warp points get stored. Defaults to `$HOME/.warprc`.
## Testing
`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.
`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`.
@ -243,17 +225,15 @@ cd ./test
./tests.sh
```
## Maintainers
## License
Following @mfaerevaag stepping away from active maintainership of this repository, the following users now are also maintainers of the repo:
The project is licensed under the [MIT license](https://github.com/mfaerevaag/wd/blob/master/LICENSE).
* @alpha-tango-kilo
## Contributing
* @MattLewin
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.
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.

View File

@ -8,7 +8,7 @@
# @github.com/mfaerevaag/wd
# version
readonly WD_VERSION=0.5.0
readonly WD_VERSION=0.4.6
# colors
readonly WD_BLUE="\033[96m"
@ -79,6 +79,8 @@ Commands:
<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
add! Overwrites existing warp point with current directory's name
rm <point> Removes the given warp point
rm Removes the given warp point with current directory's name
show <point> Print path to given warp point
@ -86,13 +88,12 @@ Commands:
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 (will prompt unless --force is used)
clean! Remove points warping to nonexistent directories
-v | --version Print version
-d | --debug Exit after execution with exit codes (for testing)
-c | --config Specify config file (default ~/.warprc)
-q | --quiet Suppress all output
-f | --force Allows overwriting without warning (for add & clean)
help Show this extremely helpful text
EOF
@ -102,7 +103,7 @@ wd_exit_fail()
{
local msg=$1
wd_print_msg "$WD_RED" "$msg"
wd_print_msg $WD_RED $msg
WD_EXIT_CODE=1
}
@ -110,7 +111,7 @@ wd_exit_warn()
{
local msg=$1
wd_print_msg "$WD_YELLOW" "$msg"
wd_print_msg $WD_YELLOW $msg
WD_EXIT_CODE=1
}
@ -118,7 +119,7 @@ wd_getdir()
{
local name_arg=$1
point=$(wd_show "$name_arg")
point=$(wd_show $name_arg)
dir=${point:28+$#name_arg+7}
if [[ -z $name_arg ]]; then
@ -161,12 +162,12 @@ wd_warp()
wd_add()
{
local point=$1
local force=$2
local force=$1
local point=$2
if [[ $point == "" ]]
then
point=$(basename "$PWD")
point=$(basename $PWD)
fi
if [[ $point =~ "^[\.]+$" ]]
@ -178,59 +179,57 @@ wd_add()
elif [[ $point == *:* ]]
then
wd_exit_fail "Warp point cannot contain colons"
elif [[ ${points[$point]} == "" ]] || [ ! -z "$force" ]
elif [[ ${points[$point]} == "" ]] || $force
then
wd_remove "$point" > /dev/null
printf "%q:%s\n" "${point}" "${PWD/#$HOME/~}" >> "$WD_CONFIG"
wd_remove $point > /dev/null
printf "%q:%s\n" "${point}" "${PWD/#$HOME/~}" >> $WD_CONFIG
if (whence sort >/dev/null); then
local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX")
# 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
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
# TODO: we should handle this kind of logic better
WD_EXIT_CODE=0
else
wd_exit_warn "Warp point '${point}' already exists. Use 'add --force' to overwrite."
wd_exit_warn "Warp point '${point}' already exists. Use 'add!' to overwrite."
fi
}
wd_remove()
{
local point_list=$1
local point=$1
if [[ "$point_list" == "" ]]
if [[ $point == "" ]]
then
point_list=$(basename "$PWD")
point=$(basename $PWD)
fi
for point_name in $point_list ; do
if [[ ${points[$point_name]} != "" ]]
if [[ ${points[$point]} != "" ]]
then
local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX")
# Copy and delete in two steps in order to preserve symlinks
if sed -n "/^${point_name}:.*$/!p" "$WD_CONFIG" > "$config_tmp" && command cp "$config_tmp" "$WD_CONFIG" && command rm "$config_tmp"
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"
wd_print_msg $WD_GREEN "Warp point removed"
else
wd_exit_fail "Something bad happened! Sorry."
fi
else
wd_exit_fail "Warp point was not found"
fi
done
}
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
while IFS= read -r line
@ -243,7 +242,7 @@ wd_list_all()
then
max_warp_point_length=$length
fi
done <<< "$entries"
done <<< $entries
while IFS= read -r line
do
@ -255,35 +254,35 @@ wd_list_all()
if [[ -z $wd_quiet_mode ]]
then
printf "%${max_warp_point_length}s -> %s\n" "$key" "$val"
printf "%${max_warp_point_length}s -> %s\n" $key $val
fi
fi
done <<< "$entries"
done <<< $entries
}
wd_ls()
{
wd_getdir "$1"
ls "${dir/#\~/$HOME}"
wd_getdir $1
ls ${dir/#\~/$HOME}
}
wd_path()
{
wd_getdir "$1"
echo "$(echo "$dir" | sed "s:${HOME}:~:g")"
wd_getdir $1
echo $(echo $dir | sed "s:${HOME}:~:g")
}
wd_show()
{
local name_arg=$1
# if there's an argument we look up the value
if [[ -n $name_arg ]]
if [[ ! -z $name_arg ]]
then
if [[ -z $points[$name_arg] ]]
then
wd_print_msg "$WD_BLUE" "No warp point named $name_arg"
wd_print_msg $WD_BLUE "No warp point named $name_arg"
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
else
# hax to create a local empty array
@ -291,19 +290,19 @@ wd_show()
wd_matches=()
# do a reverse lookup to check whether PWD is in $points
PWD="${PWD/$HOME/~}"
if [[ ${points[(r)$PWD]} == "$PWD" ]]
if [[ ${points[(r)$PWD]} == $PWD ]]
then
for name in ${(k)points}
do
if [[ $points[$name] == "$PWD" ]]
if [[ $points[$name] == $PWD ]]
then
wd_matches[$(($#wd_matches+1))]=$name
fi
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
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
}
@ -313,7 +312,7 @@ wd_clean() {
local count=0
local wd_tmp=""
while read -r line
while read line
do
if [[ $line != "" ]]
then
@ -323,32 +322,32 @@ wd_clean() {
if [ -d "${val/#\~/$HOME}" ]
then
wd_tmp=$wd_tmp"\n"`echo "$line"`
wd_tmp=$wd_tmp"\n"`echo $line`
else
wd_print_msg "$WD_YELLOW" "Nonexistent directory: ${key} -> ${val}"
wd_print_msg $WD_YELLOW "Nonexistent directory: ${key} -> ${val}"
count=$((count+1))
fi
fi
done < "$WD_CONFIG"
done < $WD_CONFIG
if [[ $count -eq 0 ]]
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
if [ ! -z "$force" ] || wd_yesorno "Removing ${count} warp points. Continue? (y/n)"
if $force || wd_yesorno "Removing ${count} warp points. Continue? (Y/n)"
then
echo "$wd_tmp" >! "$WD_CONFIG"
wd_print_msg "$WD_GREEN" "Cleanup complete. ${count} warp point(s) removed"
echo $wd_tmp >! $WD_CONFIG
wd_print_msg $WD_GREEN "Cleanup complete. ${count} warp point(s) removed"
else
wd_print_msg "$WD_BLUE" "Cleanup aborted"
wd_print_msg $WD_BLUE "Cleanup aborted"
fi
fi
}
wd_export_static_named_directories() {
if [[ ! -z $WD_EXPORT ]]
if [[ -z $WD_SKIP_EXPORT ]]
then
command grep '^[0-9a-zA-Z_-]\+:' "$WD_CONFIG" | sed -e "s,~,$HOME," -e 's/:/=/' | while read -r warpdir ; do
command grep '^[0-9a-zA-Z_-]\+:' "$WD_CONFIG" | sed -e "s,~,$HOME," -e 's/:/=/' | while read warpdir ; do
hash -d "$warpdir"
done
fi
@ -367,8 +366,7 @@ zparseopts -D -E \
c:=wd_alt_config -config:=wd_alt_config \
q=wd_quiet_mode -quiet=wd_quiet_mode \
v=wd_print_version -version=wd_print_version \
d=wd_debug_mode -debug=wd_debug_mode \
f=wd_force_mode -force=wd_force_mode
d=wd_debug_mode -debug=wd_debug_mode
if [[ ! -z $wd_print_version ]]
then
@ -381,10 +379,10 @@ then
fi
# check if config file exists
if [ ! -e "$WD_CONFIG" ]
if [ ! -e $WD_CONFIG ]
then
# if not, create config file
touch "$WD_CONFIG"
touch $WD_CONFIG
else
wd_export_static_named_directories
fi
@ -399,10 +397,10 @@ do
val=${(j,:,)arr[2,-1]}
points[$key]=$val
done < "$WD_CONFIG"
done < $WD_CONFIG
# 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
if [[ ($? -ne 0 || $#* -eq 0) && -z $wd_print_version ]]
@ -410,13 +408,14 @@ then
wd_print_usage
# check if config file is writeable
elif [ ! -w "$WD_CONFIG" ]
elif [ ! -w $WD_CONFIG ]
then
# do nothing
# can't run `exit`, as this would exit the executing shell
wd_exit_fail "\'$WD_CONFIG\' is not writeable."
else
# parse rest of options
local wd_o
for wd_o
@ -424,7 +423,11 @@ else
case "$wd_o"
in
"-a"|"--add"|"add")
wd_add "$2" "$wd_force_mode"
wd_add false $2
break
;;
"-a!"|"--add!"|"add!")
wd_add true $2
break
;;
"-e"|"export")
@ -432,8 +435,10 @@ else
break
;;
"-r"|"--remove"|"rm")
# Passes all the arguments as a single string separated by whitespace to wd_remove
wd_remove "${@:2}"
# Loop over all arguments after "rm", separated by whitespace
for pointname in "${@:2}" ; do
wd_remove $pointname
done
break
;;
"-l"|"list")
@ -441,11 +446,11 @@ else
break
;;
"-ls"|"ls")
wd_ls "$2"
wd_ls $2
break
;;
"-p"|"--path"|"path")
wd_path "$2"
wd_path $2
break
;;
"-h"|"--help"|"help")
@ -453,15 +458,19 @@ else
break
;;
"-s"|"--show"|"show")
wd_show "$2"
wd_show $2
break
;;
"-c"|"--clean"|"clean")
wd_clean "$wd_force_mode"
wd_clean false
break
;;
"-c!"|"--clean!"|"clean!")
wd_clean true
break
;;
*)
wd_warp "$wd_o" "$2"
wd_warp $wd_o $2
break
;;
--)
@ -493,7 +502,7 @@ unset args
unset points
unset val &> /dev/null # fixes issue #1
if [[ -n $wd_debug_mode ]]
if [[ ! -z $wd_debug_mode ]]
then
exit $WD_EXIT_CODE
else

View File

@ -68,7 +68,6 @@ then
printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Want to get involved in the community? Join our Discord:" "https://discord.gg/ohmyzsh"
printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Get your Oh My Zsh swag at:" "https://shop.planetargon.com/collections/oh-my-zsh"
else
status=$?
printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?'
fi
@ -77,6 +76,3 @@ case "$resetAutoStash" in
"") git config --unset rebase.autoStash ;;
*) git config rebase.autoStash "$resetAutoStash" ;;
esac
# Exit with `1` if the update failed
exit $status