stop rewriting the db file when z is used, remove useless code from

common()
This commit is contained in:
rupa committed 2011-08-03 17:17:56 -04:00
1 parent cd47da6e03
commit 366129af90
3 files changed
+8 -20

No files matched your search

+2 -2
View File
@@ -83,8 +83,8 @@ NOTES
When multiple directories match all queries, z will cd to the shortest When multiple directories match all queries, z will cd to the shortest
matching directory, without regard to priority. This has been in effect, matching directory, without regard to priority. This has been in effect,
if undocumented, for quite some time, and it is the opinion of the author if undocumented, for quite some time, but should probably be configurable
that it is intuitive behavior. or reconsidered.
Tab Completion Tab Completion
+2 -2
View File
@@ -86,8 +86,8 @@ Frecency is determined at runtime.
.P .P
When multiple directories match all queries, \fBz\fR will cd to the shortest When multiple directories match all queries, \fBz\fR will cd to the shortest
matching directory, without regard to priority. This has been in effect, if matching directory, without regard to priority. This has been in effect, if
undocumented, for quite some time, and it is the opinion of the author that it undocumented, for quite some time, but should probably be configurable or
is intuitive behavior. reconsidered.
.br .br
\fBTab Completion\fR \fBTab Completion\fR
+4 -16
View File
@@ -106,10 +106,8 @@ _z() {
# no file yet # no file yet
[ -f "$datafile" ] || return [ -f "$datafile" ] || return
local tempfile
tempfile="$(mktemp $datafile.XXXXXX)" || return
local cd local cd
cd="$(awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -v tmpfl="$tempfile" -F"|" ' cd="$(awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" '
function frecent(rank, time) { function frecent(rank, time) {
dx = t-time dx = t-time
if( dx < 3600 ) return rank*4 if( dx < 3600 ) return rank*4
@@ -134,17 +132,11 @@ _z() {
if( matches[i] && (!short || length(i) < length(short)) ) short = i if( matches[i] && (!short || length(i) < length(short)) ) short = i
} }
if( short == "/" ) return if( short == "/" ) return
for( i in matches ) if( matches[i] && i !~ short ) x = 1 return short
if( x ) return
if( nc ) {
for( i in fnd ) if( tolower(short) !~ tolower(fnd[i]) ) x = 1
} else for( i in fnd ) if( short !~ fnd[i] ) x = 1
if( !x ) return short
} }
BEGIN { split(q, a, " ") } BEGIN { split(q, a, " ") }
{ {
if( system("test -d \"" $1 "\"") ) next if( system("test -d \"" $1 "\"") ) next
print $0 >> tmpfl
if( typ == "rank" ) { if( typ == "rank" ) {
f = $2 f = $2
} else if( typ == "recent" ) { } else if( typ == "recent" ) {
@@ -169,12 +161,8 @@ _z() {
} else if( ncx ) output(nocase, ncx, common(nocase, a, 1)) } else if( ncx ) output(nocase, ncx, common(nocase, a, 1))
} }
' "$datafile")" ' "$datafile")"
if [ $? -gt 0 ]; then [ $? -gt 0 ] && return
env rm -f "$tempfile" [ "$cd" ] && cd "$cd"
else
env mv -f "$tempfile" "$datafile"
[ "$cd" ] && cd "$cd"
fi
fi fi
} }