performance improvement from clvv
see https://github.com/clvv/z/commit/4f313ac39eb34ff08a41e5efafbf0d7a7ffcfcd1
This commit is contained in:
1 parent
cf4b1afd71
commit
f8a7cb0672
1 file changed
+24
-3
@@ -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" ) {
|
||||
|
||||
Reference in new issue
Block a user