diff --git a/z.sh b/z.sh index 753a416..91a498f 100755 --- a/z.sh +++ b/z.sh @@ -70,12 +70,23 @@ _z() { # tab completion elif [ "$1" = "--complete" ]; then awk -v q="$2" -F"|" ' + function notdir(path, tmp) { + # faster than system() + n = gsub("/+", "/", path) + for( i = 0; i < n; i++ ) path = path "/.." + path = path datafile + if( ( getline tmp < path ) >= 0 ) { + close(path) + return 0 + } + return 1 + } BEGIN { if( q == tolower(q) ) nocase = 1 split(substr(q,3),fnd," ") } { - if( system("test -d \"" $1 "\"") ) next + if( notdir($1) ) next if( nocase ) { for( i in fnd ) tolower($1) !~ tolower(fnd[i]) && $1 = "" } else { @@ -107,7 +118,17 @@ _z() { [ -f "$datafile" ] || return local cd - cd="$(awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" ' + cd="$(awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -v datafile="$datafile" -F"|" ' + function notdir(path, tmp) { + n = gsub("/+", "/", path) + for( i = 0; i < n; i++ ) path = path "/.." + path = path datafile + if( ( getline tmp < path ) >= 0 ) { + close(path) + return 0 + } + return 1 + } function frecent(rank, time) { dx = t-time if( dx < 3600 ) return rank*4 @@ -139,7 +160,7 @@ _z() { } BEGIN { split(q, a, " ") } { - if( system("test -d \"" $1 "\"") ) next + if( notdir($1) ) next if( typ == "rank" ) { f = $2 } else if( typ == "recent" ) {