Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rupa/z into solaris-compa…
Browse files Browse the repository at this point in the history
…tibility
  • Loading branch information
agkozak committed Sep 11, 2018
2 parents 24c144e + 9d5a3fe commit 993746e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions z.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# * z -r foo # cd to highest ranked dir matching foo
# * z -t foo # cd to most recently accessed dir matching foo
# * z -l foo # list matches instead of cd
# * z -e foo # echo the best match, don't cd
# * z -c foo # restrict matches to subdirs of $PWD

[ -d "${_Z_DATA:-$HOME/.z}" ] && {
Expand Down Expand Up @@ -96,7 +97,7 @@ _z() {
if [ $? -ne 0 -a -f "$datafile" ]; then
env rm -f "$tempfile"
else
[ "$_Z_OWNER" ] && chown $_Z_OWNER:$(id -ng $_Z_OWNER) "$tempfile"
[ "$_Z_OWNER" ] && chown $_Z_OWNER:"$(id -ng $_Z_OWNER)" "$tempfile"
env mv -f "$tempfile" "$datafile" || env rm -f "$tempfile"
fi

Expand All @@ -117,25 +118,26 @@ _z() {

else
# list/go
local echo fnd last list opt typ
while [ "$1" ]; do case "$1" in
--) while [ "$1" ]; do shift; local fnd="$fnd${fnd:+ }$1";done;;
-*) local opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in
c) local fnd="^$PWD $fnd";;
e) local echo=echo;;
--) while [ "$1" ]; do shift; fnd="$fnd${fnd:+ }$1";done;;
-*) opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in
c) fnd="^$PWD $fnd";;
e) echo=1;;
h) echo "${_Z_CMD:-z} [-cehlrtx] args" >&2; return;;
l) local list=1;;
r) local typ="rank";;
t) local typ="recent";;
l) list=1;;
r) typ="rank";;
t) typ="recent";;
x)
local tempfile="$datafile.$RANDOM"
sed -e "\:^${PWD}|.*:d" "$datafile" > "$tempfile"
env mv -f "$tempfile" "$datafile" 2> /dev/null \
|| env rm -f "$tempfile"
;;
esac; opt=${opt:1}; done;;
*) local fnd="$fnd${fnd:+ }$1";;
esac; local last=$1; [ "$#" -gt 0 ] && shift; done
[ "$fnd" -a "$fnd" != "^$PWD " ] || local list=1
*) fnd="$fnd${fnd:+ }$1";;
esac; last=$1; [ "$#" -gt 0 ] && shift; done
[ "$fnd" -a "$fnd" != "^$PWD " ] || list=1

# if we hit enter on a completion just go there
case "$last" in
Expand Down

0 comments on commit 993746e

Please sign in to comment.