Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Oh My Zsh
Commits
d41ac7fe
Commit
d41ac7fe
authored
Mar 04, 2014
by
Markus Faerevaag
Browse files
Updated wd plugin to v0.3.0
parent
6b3c9537
Changes
3
Show whitespace changes
Inline
Side-by-side
plugins/wd/_wd.sh
View file @
d41ac7fe
#compdef wd.sh
#compdef wd
zstyle
":completion:*:descriptions"
format
"%B%d%b"
zstyle
':completion:*:descriptions'
format
'%B%d%b'
zstyle
':completion::complete:wd:*:commands'
group-name commands
CONFIG
=
$HOME
/.warprc
zstyle
':completion::complete:wd:*:warp_points'
group-name warp_points
zstyle
':completion::complete:wd::'
list-grouped
local
-a
main_commands
main_commands
=(
# Call `_wd()` when when trying to complete the command `wd`
add:
'Adds the current working directory to your warp points'
#add'\!':'Overwrites existing warp point' # TODO: Fix
zmodload zsh/mapfile
rm
:
'Removes the given warp point'
function
_wd
()
{
ls
:
'Outputs all stored warp points'
local
ret
=
1
show:
'Outputs warp points to current directory'
local
CONFIG
=
$HOME
/.warprc
)
# Stolen from
local
-a
points
# http://stackoverflow.com/questions/9000698/completion-when-program-has-sub-commands
while
read
line
do
# local curcontext="$curcontext" state line
points+
=
$(
awk
"{ gsub(/
\/
Users
\/
$USER
|
\/
home
\/
$USER
/,
\"
~
\"
); print }"
<<<
$line
)
# typeset -A opt_args
done
<
$CONFIG
local
-a
commands
_wd
()
local
-a
warp_points
{
warp_points
=(
"
${
(f)mapfile[
$CONFIG
]
}
"
)
# init variables
# LIST="${mapfile[$FNAME]}" # Not required unless stuff uses it
local
curcontext
=
"
$curcontext
"
state line
typeset
-A
opt_args
commands
=(
'add:Adds the current working directory to your warp points'
# init state
'add!:Overwrites existing warp point'
_arguments
\
'rm:Removes the given warp point'
'1: :->command'
\
'ls:Outputs all stored warp points'
'2: :->argument'
'show:Outputs all warp points that point to the current directory'
'help:Show this extremely helpful text'
'..:Go back to last directory'
)
_arguments
-C
\
'1: :->first_arg'
\
'2: :->second_arg'
&&
ret
=
0
case
$state
in
case
$state
in
command
)
first_arg
)
compadd
"
$@
"
add
rm ls
show
_describe
-t
warp_points
"Warp points"
warp_points
&&
ret
=
0
_describe
-t
warp-points
'Warp points:'
point
s
&&
ret
=
0
_describe
-t
commands
"Commands"
command
s
&&
ret
=
0
;;
;;
argument
)
second_arg
)
case
$words
[
2]
in
case
$words
[
2]
in
rm
|
add!
)
add
\!
|
rm
)
_describe
-t
warp-points
'warp points'
points
&&
ret
=
0
_describe
-t
points
"Warp points"
warp_points
&&
ret
=
0
;;
add
)
_message
'Write the name of your warp point'
&&
ret
=
0
;;
;;
*
)
esac
esac
;;
esac
esac
return
$ret
}
}
_wd
"
$@
"
_wd
"
$@
"
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et
plugins/wd/wd.plugin.zsh
View file @
d41ac7fe
...
@@ -6,4 +6,6 @@
...
@@ -6,4 +6,6 @@
#
#
# @github.com/mfaerevaag/wd
# @github.com/mfaerevaag/wd
alias
wd
=
'. $ZSH/plugins/wd/wd.sh'
wd
()
{
.
$ZSH
/plugins/wd/wd.sh
}
plugins/wd/wd.sh
View file @
d41ac7fe
...
@@ -50,12 +50,12 @@ wd_warp()
...
@@ -50,12 +50,12 @@ wd_warp()
wd_print_msg
$YELLOW
"Warping to current directory?"
wd_print_msg
$YELLOW
"Warping to current directory?"
else
else
((
n
=
$#1
- 1
))
((
n
=
$#1
- 1
))
wd_print_msg
$BLUE
"Warping..."
#
wd_print_msg $BLUE "Warping..."
cd
-
$n
>
/dev/null
cd
-
$n
>
/dev/null
fi
fi
elif
[[
${
points
[
$1
]
}
!=
""
]]
elif
[[
${
points
[
$1
]
}
!=
""
]]
then
then
wd_print_msg
$BLUE
"Warping..."
#
wd_print_msg $BLUE "Warping..."
cd
${
points
[
$1
]
}
cd
${
points
[
$1
]
}
else
else
wd_print_msg
$RED
"Unkown warp point '
$1
'"
wd_print_msg
$RED
"Unkown warp point '
$1
'"
...
@@ -64,16 +64,16 @@ wd_warp()
...
@@ -64,16 +64,16 @@ wd_warp()
wd_add
()
wd_add
()
{
{
if
[[
$
1
=
~
"^
\.
+$"
]]
if
[[
$
2
=
~
"^
\.
+$"
||
$2
=
~
"^
\s
*$"
]]
then
then
wd_print_msg
$RED
"Ille
a
gal warp point (see README)."
wd_print_msg
$RED
"Illegal warp point (see README)."
elif
[[
${
points
[
$
1
]
}
==
""
]]
||
$
2
elif
[[
${
points
[
$
2
]
}
==
""
]]
||
$
1
then
then
wd_remove
$
1
>
/dev/null
wd_remove
$
2
>
/dev/null
print
"
$
1
:
$PWD
"
>>
$CONFIG
print
"
$
2
:
$PWD
"
>>
$CONFIG
wd_print_msg
$GREEN
"Warp point added"
wd_print_msg
$GREEN
"Warp point added"
else
else
wd_print_msg
$YELLOW
"Warp point '
$
1
' alredy exists. Use 'add!' to overwrite."
wd_print_msg
$YELLOW
"Warp point '
$
2
' alre
a
dy exists. Use 'add!' to overwrite."
fi
fi
}
}
...
@@ -83,7 +83,9 @@ wd_remove()
...
@@ -83,7 +83,9 @@ wd_remove()
then
then
if
wd_tmp
=
`
sed
"/^
$1
:/d"
$CONFIG
`
if
wd_tmp
=
`
sed
"/^
$1
:/d"
$CONFIG
`
then
then
echo
$wd_tmp
>
$CONFIG
# `>!` forces overwrite
# we need this if people use `setopt NO_CLOBBER`
echo
$wd_tmp
>!
$CONFIG
wd_print_msg
$GREEN
"Warp point removed"
wd_print_msg
$GREEN
"Warp point removed"
else
else
wd_print_msg
$RED
"Warp point unsuccessfully removed. Sorry!"
wd_print_msg
$RED
"Warp point unsuccessfully removed. Sorry!"
...
@@ -131,9 +133,9 @@ wd_print_usage()
...
@@ -131,9 +133,9 @@ wd_print_usage()
print
"
\n
Commands:"
print
"
\n
Commands:"
print
"
\t
add
\t
Adds the current working directory to your warp points"
print
"
\t
add
\t
Adds the current working directory to your warp points"
print
"
\t
add!
\t
Overwrites existing warp point"
print
"
\t
add!
\t
Overwrites existing warp point"
print
"
\t
r
emove
Removes the given warp point"
print
"
\t
r
m
\t
Removes the given warp point"
print
"
\t
show
\t
Outputs warp points to current directory"
print
"
\t
show
\t
Outputs warp points to current directory"
print
"
\t
l
ist
\t
Outputs all stored warp points"
print
"
\t
l
s
\t
Outputs all stored warp points"
print
"
\t
help
\t
Show this extremely helpful text"
print
"
\t
help
\t
Show this extremely helpful text"
}
}
...
@@ -141,7 +143,7 @@ wd_print_usage()
...
@@ -141,7 +143,7 @@ wd_print_usage()
## run
## run
# get opts
# get opts
args
=
`
getopt
-o
a:r:lhs
-l
add:,r
emove:,list
,help,show
--
$*
`
args
=
`
getopt
-o
a:r:lhs
-l
add:,r
m:,ls
,help,show
--
$*
`
# check if no arguments were given
# check if no arguments were given
if
[[
$?
-ne
0
||
$#*
-eq
0
]]
if
[[
$?
-ne
0
||
$#*
-eq
0
]]
...
@@ -164,45 +166,36 @@ else
...
@@ -164,45 +166,36 @@ else
case
"
$i
"
case
"
$i
"
in
in
-a
|
--add
|
add
)
-a
|
--add
|
add
)
wd_add
$2
false
wd_add
false
$2
shift
shift
break
break
;;
;;
-a
!
|
--add
!
|
add!
)
-a
!
|
--add
!
|
add!
)
wd_add
$2
true
wd_add
true
$2
shift
shift
break
break
;;
;;
-r
|
--remove
|
rm
)
-r
|
--remove
|
rm
)
wd_remove
$2
wd_remove
$2
shift
shift
break
break
;;
;;
-l
|
--list
|
ls
)
-l
|
--list
|
ls
)
wd_list_all
wd_list_all
shift
break
break
;;
;;
-h
|
--help
|
help
)
-h
|
--help
|
help
)
wd_print_usage
wd_print_usage
shift
break
break
;;
;;
-s
|
--show
|
show
)
-s
|
--show
|
show
)
wd_show
wd_show
shift
break
break
;;
;;
*
)
*
)
wd_warp
$i
wd_warp
$i
shift
break
break
;;
;;
--
)
--
)
shift
;
break
;;
break
;;
esac
esac
done
done
fi
fi
...
@@ -211,6 +204,6 @@ fi
...
@@ -211,6 +204,6 @@ fi
## garbage collection
## garbage collection
# if not, next time warp will pick up variables from this run
# if not, next time warp will pick up variables from this run
# remember, there's no sub shell
# remember, there's no sub shell
points
=
""
unset
points
args
=
""
unset
args
un
hash
-d
val &> /dev/null
# fixes issue #1
un
set
val &> /dev/null
# fixes issue #1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment