Arguments to z must be ordered.
E.g. 'z foo bar' matches /foo/bar but not /bar/foo.
This commit is contained in:
1 parent
8053deda75
commit
4932acafc7
3 files changed
+21
-16
No files matched your search
@@ -15,7 +15,10 @@ DESCRIPTION
|
||||
Tracks your most used directories, based on 'frecency'.
|
||||
|
||||
After a short learning phase, z will take you to the most 'frecent'
|
||||
directory that matches ALL of the regexes given on the command line.
|
||||
directory that matches ALL of the regexes given on the command line, in
|
||||
order.
|
||||
|
||||
For example, z foo bar would match /foo/bar but not /bar/foo.
|
||||
|
||||
OPTIONS
|
||||
-c restrict matches to subdirectories of the current directory
|
||||
@@ -33,7 +36,7 @@ OPTIONS
|
||||
EXAMPLES
|
||||
z foo cd to most frecent dir matching foo
|
||||
|
||||
z foo bar cd to most frecent dir matching foo and bar
|
||||
z foo bar cd to most frecent dir matching foo, then bar
|
||||
|
||||
z -r foo cd to highest ranked dir matching foo
|
||||
|
||||
|
||||
@@ -13,7 +13,9 @@ DESCRIPTION
|
||||
Tracks your most used directories, based on 'frecency'.
|
||||
.P
|
||||
After a short learning phase, \fBz\fR will take you to the most 'frecent'
|
||||
directory that matches ALL of the regexes given on the command line.
|
||||
directory that matches ALL of the regexes given on the command line, in order.
|
||||
|
||||
For example, \fBz foo bar\fR would match \fB/foo/bar\fR but not \fB/bar/foo\fR.
|
||||
.SH
|
||||
OPTIONS
|
||||
.TP
|
||||
@@ -40,7 +42,7 @@ remove the current directory from the datafile
|
||||
cd to most frecent dir matching foo
|
||||
.TP 14
|
||||
\fBz foo bar\fR
|
||||
cd to most frecent dir matching foo and bar
|
||||
cd to most frecent dir matching foo, then bar
|
||||
.TP 14
|
||||
\fBz -r foo\fR
|
||||
cd to highest ranked dir matching foo
|
||||
|
||||
@@ -88,15 +88,13 @@ _z() {
|
||||
done < "$datafile" | awk -v q="$2" -F"|" '
|
||||
BEGIN {
|
||||
if( q == tolower(q) ) imatch = 1
|
||||
split(substr(q, 3), fnd, " ")
|
||||
q = substr(q, 3)
|
||||
gsub(" ", ".*", q)
|
||||
}
|
||||
{
|
||||
if( imatch ) {
|
||||
for( x in fnd ) tolower($1) !~ tolower(fnd[x]) && $1 = ""
|
||||
} else {
|
||||
for( x in fnd ) $1 !~ fnd[x] && $1 = ""
|
||||
}
|
||||
if( $1 ) print $1
|
||||
if( tolower($1) ~ tolower(q) ) print $1
|
||||
} else if( $1 ~ q ) print $1
|
||||
}
|
||||
' 2>/dev/null
|
||||
|
||||
@@ -167,18 +165,20 @@ _z() {
|
||||
for( x in matches ) if( matches[x] && x !~ clean_short ) return
|
||||
return short
|
||||
}
|
||||
BEGIN { split(q, words, " "); hi_rank = ihi_rank = -9999999999 }
|
||||
BEGIN {
|
||||
q = substr(q, 2)
|
||||
gsub(" ", ".*", q)
|
||||
hi_rank = ihi_rank = -9999999999
|
||||
}
|
||||
{
|
||||
if( typ == "rank" ) {
|
||||
rank = $2
|
||||
} else if( typ == "recent" ) {
|
||||
rank = $3 - t
|
||||
} else rank = frecent($2, $3)
|
||||
matches[$1] = imatches[$1] = rank
|
||||
for( x in words ) {
|
||||
if( $1 !~ words[x] ) delete matches[$1]
|
||||
if( tolower($1) !~ tolower(words[x]) ) delete imatches[$1]
|
||||
}
|
||||
if( $1 ~ q ) {
|
||||
matches[$1] = rank
|
||||
} else if( tolower($1) ~ tolower(q) ) imatches[$1] = rank
|
||||
if( matches[$1] && matches[$1] > hi_rank ) {
|
||||
best_match = $1
|
||||
hi_rank = matches[$1]
|
||||
|
||||
Reference in new issue
Block a user