add -e flag to echo best match only (no cd)
-l lists and does not cd, but has enough extra stuff going on to make it a bit of a pain if you want to parse out just the best match for your own nefarious purposes - therefore this. h/t @synthetiv. Closes #161
This commit is contained in:
1 parent
5dc2a863cc
commit
d0cf5282df
3 files changed
+14
-3
No files matched your search
@@ -23,6 +23,8 @@ DESCRIPTION
|
||||
OPTIONS
|
||||
-c restrict matches to subdirectories of the current directory
|
||||
|
||||
-e echo the best match, don't cd
|
||||
|
||||
-h show a brief help message
|
||||
|
||||
-l list only
|
||||
|
||||
@@ -22,6 +22,9 @@ OPTIONS
|
||||
\fB\-c\fR
|
||||
restrict matches to subdirectories of the current directory
|
||||
.TP
|
||||
\fB\-e\fR
|
||||
echo the best match, don't cd
|
||||
.TP
|
||||
\fB\-h\fR
|
||||
show a brief help message
|
||||
.TP
|
||||
|
||||
@@ -106,11 +106,12 @@ _z() {
|
||||
--) 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";;
|
||||
h) echo "${_Z_CMD:-z} [-chlrtx] args" >&2; return;;
|
||||
x) sed -i -e "\:^${PWD}|.*:d" "$datafile";;
|
||||
e) local nocd=1;;
|
||||
h) echo "${_Z_CMD:-z} [-cehlrtx] args" >&2; return;;
|
||||
l) local list=1;;
|
||||
r) local typ="rank";;
|
||||
t) local typ="recent";;
|
||||
x) sed -i -e "\:^${PWD}|.*:d" "$datafile";;
|
||||
esac; opt=${opt:1}; done;;
|
||||
*) local fnd="$fnd${fnd:+ }$1";;
|
||||
esac; local last=$1; [ "$#" -gt 0 ] && shift; done
|
||||
@@ -198,7 +199,12 @@ _z() {
|
||||
}
|
||||
')"
|
||||
[ $? -gt 0 ] && return
|
||||
[ "$cd" ] && cd "$cd"
|
||||
[ "$cd" ] || return
|
||||
if [ "$nocd" ]; then
|
||||
echo "$cd"
|
||||
else
|
||||
cd "$cd"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user