Skip to content

Commit ea5ec78

Browse files
committed
pipe calls to _z_dirs, and a litle simplification
h/t @ericbn. Closes #217 and #196 maybe
1 parent 2ebe419 commit ea5ec78

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

z.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ _z() {
3838
[ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return
3939

4040
_z_dirs () {
41+
local line
4142
while read line; do
4243
# only count directories
43-
[ -d "${line%%\|*}" ] && echo $line
44+
[ -d "${line%%\|*}" ] && echo "$line"
4445
done < "$datafile"
4546
return 0
4647
}
@@ -60,7 +61,7 @@ _z() {
6061

6162
# maintain the data file
6263
local tempfile="$datafile.$RANDOM"
63-
awk < <(_z_dirs 2>/dev/null) -v path="$*" -v now="$(date +%s)" -F"|" '
64+
_z_dirs | awk -v path="$*" -v now="$(date +%s)" -F"|" '
6465
BEGIN {
6566
rank[path] = 1
6667
time[path] = now
@@ -93,17 +94,15 @@ _z() {
9394

9495
# tab completion
9596
elif [ "$1" = "--complete" -a -s "$datafile" ]; then
96-
while read line; do
97-
[ -d "${line%%\|*}" ] && echo $line
98-
done < "$datafile" | awk -v q="$2" -F"|" '
97+
_z_dirs | awk -v q="$2" -F"|" '
9998
BEGIN {
100-
if( q == tolower(q) ) imatch = 1
10199
q = substr(q, 3)
102-
gsub(" ", ".*", q)
100+
if( q == tolower(q) ) imatch = 1
101+
gsub(/ /, ".*", q)
103102
}
104103
{
105104
if( imatch ) {
106-
if( tolower($1) ~ tolower(q) ) print $1
105+
if( tolower($1) ~ q ) print $1
107106
} else if( $1 ~ q ) print $1
108107
}
109108
' 2>/dev/null

0 commit comments

Comments
 (0)