From 0f7f16b22900252ba88fbdeb97bc449bd006f8c6 Mon Sep 17 00:00:00 2001 From: rupa Date: Mon, 15 Feb 2010 15:33:36 -0500 Subject: [PATCH] smartcase in completions - ie only case sensitive if there is an uppercase letter in search --- z.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/z.sh b/z.sh index af2b8f6..7bb6781 100644 --- a/z.sh +++ b/z.sh @@ -44,10 +44,19 @@ z() { elif [ "$1" = "--complete" ]; then # tab completion awk -v q="$2" -F"|" ' - BEGIN { split(substr(q,3),fnd," ") } + BEGIN { + if( q == tolower(q) ) nocase = 1 + split(substr(q,3),fnd," ") + } { if( system("test -d \"" $1 "\"") ) next - for( i in fnd ) tolower($1) !~ tolower(fnd[i]) && $1 = ""; if( $1 ) print $1 + if( nocase ) { + for( i in fnd ) tolower($1) !~ tolower(fnd[i]) && $1 = "" + if( $1 ) print $1 + } else { + for( i in fnd ) $1 !~ fnd[i] && $1 = "" + if( $1 ) print $1 + } } ' $datafile 2>/dev/null else