Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
6f48f586
Commit
6f48f586
authored
Nov 16, 2013
by
Markus Færevaag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added wd plugin
parent
7a7eda12
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
210 additions
and
0 deletions
+210
-0
wd.plugin.zsh
plugins/wd2/wd2/wd.plugin.zsh
+9
-0
wd.sh
plugins/wd2/wd2/wd.sh
+201
-0
No files found.
plugins/wd2/wd2/wd.plugin.zsh
0 → 100755
View file @
6f48f586
#!/bin/zsh
# WARP
# ====
# oh-my-zsh plugin
#
# @github.com/mfaerevaag/wd
alias
wd
=
'. ~/.oh-my-zsh/plugins/wd/wd.sh'
plugins/wd2/wd2/wd.sh
0 → 100755
View file @
6f48f586
#!/bin/zsh
# WARP
# ====
# Jump to custom directories in terminal
# because `cd` takes too long...
#
# @github.com/mfaerevaag/wd
## variables
CONFIG
=
$HOME
/.warprc
## colors
BLUE
=
"
\0
33[96m"
GREEN
=
"
\0
33[92m"
YELLOW
=
"
\0
33[93m"
RED
=
"
\0
33[91m"
NOC
=
"
\0
33[m"
## load warp points
typeset
-A
points
while
read
line
do
arr
=(
${
(s,
:,
)line
}
)
key
=
${
arr
[1]
}
val
=
${
arr
[2]
}
points[
$key
]=
$val
done
<
$CONFIG
## functions
# prepended wd_ to not conflict with your environment (no sub shell)
wd_warp
()
{
if
[[
$1
=
~
"^
\.
+$"
]]
then
if
[[
$#1
< 2
]]
then
wd_print_msg
$YELLOW
"Warping to current directory?"
else
((
n
=
$#1
- 1
))
wd_print_msg
$BLUE
"Warping..."
cd
-
$n
>
/dev/null
fi
elif
[[
${
points
[
$1
]
}
!=
""
]]
then
wd_print_msg
$BLUE
"Warping..."
cd
${
points
[
$1
]
}
else
wd_print_msg
$RED
"Unkown warp point '
$1
'"
fi
}
wd_add
()
{
if
[[
$1
=
~
"^
\.
+$"
]]
then
wd_print_msg
$RED
"Illeagal warp point (see README)."
elif
[[
${
points
[
$1
]
}
==
""
]]
||
$2
then
wd_remove
$1
>
/dev/null
print
"
$1
:
$PWD
"
>>
$CONFIG
wd_print_msg
$GREEN
"Warp point added"
else
wd_print_msg
$YELLOW
"Warp point '
$1
' alredy exists. Use 'add!' to overwrite."
fi
}
wd_remove
()
{
if
[[
${
points
[
$1
]
}
!=
""
]]
then
if
wd_tmp
=
`
sed
"/^
$1
:/d"
$CONFIG
`
then
echo
$wd_tmp
>
$CONFIG
wd_print_msg
$GREEN
"Warp point removed"
else
wd_print_msg
$RED
"Warp point unsuccessfully removed. Sorry!"
fi
else
wd_print_msg
$RED
"Warp point was not found"
fi
}
wd_show
()
{
wd_print_msg
$BLUE
"Warp points to current directory:"
wd_list_all |
grep
$PWD
$
}
wd_list_all
()
{
wd_print_msg
$BLUE
"All warp points:"
while
read
line
do
if
[[
$line
!=
""
]]
then
arr
=(
${
(s,
:,
)line
}
)
key
=
${
arr
[1]
}
val
=
${
arr
[2]
}
print
"
\t
"
$key
"
\t
->
\t
"
$val
fi
done
<
$CONFIG
}
wd_print_msg
()
{
if
[[
$1
==
""
||
$2
==
""
]]
then
print
"
$RED
*
$NOC
Could not print message. Sorry!"
else
print
"
$1
*
$NOC
$2
"
fi
}
wd_print_usage
()
{
print
"Usage: wd [add|-a|--add] [rm|-r|--remove] [ls|-l|--list] <point>"
print
"
\n
Commands:"
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
list
\t
Outputs all stored warp points"
print
"
\t
help
\t
Show this extremely helpful text"
}
## run
# get opts
args
=
`
getopt
-o
a:r:lhs
-l
add:,remove:,list,help,show
--
$*
`
if
[[
$?
-ne
0
||
$#*
-eq
0
]]
then
wd_print_usage
else
# can't exit, as this would exit the excecuting shell
# e.i. your terminal
#set -- $args # WTF
for
i
do
case
"
$i
"
in
-a
|
--add
|
add
)
wd_add
$2
false
shift
shift
break
;;
-a
!
|
--add
!
|
add!
)
wd_add
$2
true
shift
shift
break
;;
-r
|
--remove
|
rm
)
wd_remove
$2
shift
shift
break
;;
-l
|
--list
|
ls
)
wd_list_all
shift
break
;;
-h
|
--help
|
help
)
wd_print_usage
shift
break
;;
-s
|
--show
|
show
)
wd_show
shift
break
;;
*
)
wd_warp
$i
shift
break
;;
--
)
shift
;
break
;;
esac
done
fi
## garbage collection
# if not, next time warp will pick up variables from this run
# remember, there's no sub shell
points
=
""
args
=
""
unhash
-d
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