From bef0cb2624fdaeda14af07768cafd926f80a485b Mon Sep 17 00:00:00 2001 From: ptzz Date: Wed, 8 Nov 2017 05:37:00 +0100 Subject: [PATCH] Add commandline option for case insensitive matching --- z.1 | 3 +++ z.sh | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/z.1 b/z.1 index d4cac1a..d1b6799 100644 --- a/z.1 +++ b/z.1 @@ -39,6 +39,9 @@ match by recent access only .TP \fB\-x\fR remove the current directory from the datafile +.TP +\fB\-i\fR +perform case insensitive matching .SH EXAMPLES .TP 14 \fBz foo\fR diff --git a/z.sh b/z.sh index c2036c6..2b831ba 100644 --- a/z.sh +++ b/z.sh @@ -120,6 +120,7 @@ _z() { r) local typ="rank";; t) local typ="recent";; x) sed -i -e "\:^${PWD}|.*:d" "$datafile";; + i) local icase=1;; esac; opt=${opt:1}; done;; *) local fnd="$fnd${fnd:+ }$1";; esac; local last=$1; [ "$#" -gt 0 ] && shift; done @@ -135,7 +136,7 @@ _z() { [ -f "$datafile" ] || return local cd - cd="$( < <( _z_dirs ) awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" ' + cd="$( < <( _z_dirs ) awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v icase="$icase" -v q="$fnd" -F"|" ' function frecent(rank, time) { # relate frequency and time dx = t - time @@ -184,7 +185,7 @@ _z() { } else if( typ == "recent" ) { rank = $3 - t } else rank = frecent($2, $3) - if( $1 ~ q ) { + if( $1 ~ q && !icase ) { matches[$1] = rank } else if( tolower($1) ~ tolower(q) ) imatches[$1] = rank if( matches[$1] && matches[$1] > hi_rank ) {