mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-25 15:20:08 +00:00
Merge pull request #2262 from mfaerevaag/master
Fixed and improved wd plugin
This commit is contained in:
commit
b764fad271
4 changed files with 106 additions and 5 deletions
38
plugins/wd/README.md
Normal file
38
plugins/wd/README.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
## wd
|
||||
|
||||
**Maintainer:** [mfaerevaag](https://github.com/mfaerevaag)
|
||||
|
||||
`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. [Source](https://github.com/mfaerevaag/wd)
|
||||
|
||||
### Usage
|
||||
|
||||
* Add warp point to current working directory:
|
||||
|
||||
wd add test
|
||||
|
||||
If a warp point with the same name exists, use `add!` to overwrite it.
|
||||
|
||||
* From an other directory, warp to test with:
|
||||
|
||||
wd test
|
||||
|
||||
* You can warp back to previous directory, and so on, with the puncticulation syntax:
|
||||
|
||||
wd ..
|
||||
wd ...
|
||||
|
||||
This is a wrapper for the zsh `dirs` function.
|
||||
|
||||
* Remove warp point test point:
|
||||
|
||||
wd rm test
|
||||
|
||||
* List warp points to current directory (stored in `~/.warprc`):
|
||||
|
||||
wd show
|
||||
|
||||
* List all warp points (stored in `~/.warprc`):
|
||||
|
||||
wd ls
|
||||
|
||||
* Print usage with no opts or the `help` argument.
|
48
plugins/wd/_wd.sh
Normal file
48
plugins/wd/_wd.sh
Normal file
|
@ -0,0 +1,48 @@
|
|||
#compdef wd.sh
|
||||
|
||||
zstyle ":completion:*:descriptions" format "%B%d%b"
|
||||
|
||||
CONFIG=$HOME/.warprc
|
||||
|
||||
local -a main_commands
|
||||
main_commands=(
|
||||
add:'Adds the current working directory to your warp points'
|
||||
#add'\!':'Overwrites existing warp point' # TODO: Fix
|
||||
rm:'Removes the given warp point'
|
||||
ls:'Outputs all stored warp points'
|
||||
show:'Outputs warp points to current directory'
|
||||
)
|
||||
|
||||
local -a points
|
||||
while read line
|
||||
do
|
||||
points+=$(awk "{ gsub(/\/Users\/$USER|\/home\/$USER/,\"~\"); print }" <<< $line)
|
||||
done < $CONFIG
|
||||
|
||||
_wd()
|
||||
{
|
||||
# init variables
|
||||
local curcontext="$curcontext" state line
|
||||
typeset -A opt_args
|
||||
|
||||
# init state
|
||||
_arguments \
|
||||
'1: :->command' \
|
||||
'2: :->argument'
|
||||
|
||||
case $state in
|
||||
command)
|
||||
compadd "$@" add rm ls show
|
||||
_describe -t warp-points 'Warp points:' points && ret=0
|
||||
;;
|
||||
argument)
|
||||
case $words[2] in
|
||||
rm|add!)
|
||||
_describe -t warp-points 'warp points' points && ret=0
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
esac
|
||||
}
|
||||
|
||||
_wd "$@"
|
|
@ -6,4 +6,4 @@
|
|||
#
|
||||
# @github.com/mfaerevaag/wd
|
||||
|
||||
alias wd='. ~/.oh-my-zsh/plugins/wd/wd.sh'
|
||||
alias wd='. $ZSH/plugins/wd/wd.sh'
|
|
@ -19,6 +19,13 @@ RED="\033[91m"
|
|||
NOC="\033[m"
|
||||
|
||||
|
||||
# check if config file exists
|
||||
if [[ ! -a $CONFIG ]]
|
||||
then
|
||||
# if not: create config file
|
||||
touch $CONFIG
|
||||
fi
|
||||
|
||||
## load warp points
|
||||
typeset -A points
|
||||
while read line
|
||||
|
@ -120,11 +127,12 @@ wd_print_msg()
|
|||
|
||||
wd_print_usage()
|
||||
{
|
||||
print "Usage: wd [add|-a|--add] [rm|-r|--remove] [ls|-l|--list] <point>"
|
||||
print "Usage: wd [add|-a|--add] [rm|-r|--remove] [ls|-l|--list] <point>"
|
||||
print "\nCommands:"
|
||||
print "\t add \t Adds the current working directory to your warp points"
|
||||
print "\t add! \t Overwrites existing warp point"
|
||||
print "\t remove Removes the given warp point"
|
||||
print "\t show \t Outputs warp points to current directory"
|
||||
print "\t list \t Outputs all stored warp points"
|
||||
print "\t help \t Show this extremely helpful text"
|
||||
}
|
||||
|
@ -135,13 +143,20 @@ wd_print_usage()
|
|||
# get opts
|
||||
args=`getopt -o a:r:lhs -l add:,remove:,list,help,show -- $*`
|
||||
|
||||
# check if no arguments were given
|
||||
if [[ $? -ne 0 || $#* -eq 0 ]]
|
||||
then
|
||||
wd_print_usage
|
||||
else
|
||||
# can't exit, as this would exit the excecuting shell
|
||||
# e.i. your terminal
|
||||
|
||||
# check if config file is writeable
|
||||
elif [[ ! -w $CONFIG ]]
|
||||
then
|
||||
wd_print_msg $RED "\'$CONFIG\' is not writeable."
|
||||
# do nothing => exit
|
||||
# can't run `exit`, as this would exit the executing shell
|
||||
# i.e. your terminal
|
||||
|
||||
else
|
||||
#set -- $args # WTF
|
||||
|
||||
for i
|
Loading…
Reference in a new issue