Skip to content

Instantly share code, notes, and snippets.

@guyzmo
Created September 7, 2012 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guyzmo/3666086 to your computer and use it in GitHub Desktop.
Save guyzmo/3666086 to your computer and use it in GitHub Desktop.
z.sh patch for multiline quotes
From 14916bac1a4bd4aa7382f84269852b626f09f98f Mon Sep 17 00:00:00 2001
From: Guyzmo <guyzmo....net>
Date: Fri, 7 Sep 2012 15:00:13 +0200
Subject: [PATCH] added quotes to multiline strings
---
z.sh | 70 ++++++++++++++++++++++++++++++++---------------------------------
1 files changed, 34 insertions(+), 36 deletions(-)
diff --git a/z.sh b/z.sh
index db5dab3..6f5fee5 100755
--- a/z.sh
+++ b/z.sh
@@ -39,27 +39,26 @@ _z() {
tempfile="$(mktemp $datafile.XXXXXX)" || return
while read line; do
[ -d "${line%%\|*}" ] && echo $line
- done < "$datafile" | awk -v path="$*" -v now="$(date +%s)" -F"|" '
- BEGIN {
- rank[path] = 1
- time[path] = now
- }
- $2 >= 1 {
- if( $1 == path ) {
- rank[$1] = $2 + 1
- time[$1] = now
- } else {
- rank[$1] = $2
- time[$1] = $3
- }
- count += $2
- }
- END {
- if( count > 1000 ) {
- for( i in rank ) print i "|" 0.9*rank[i] "|" time[i] # aging
- } else for( i in rank ) print i "|" rank[i] "|" time[i]
- }
- ' 2>/dev/null >| "$tempfile"
+ done < "$datafile" | awk -v path="$*" -v now="$(date +%s)" -F"|" '\
+ BEGIN {\
+ rank[path] = 1\
+ time[path] = now\
+ }\
+ $2 >= 1 {\
+ if( $1 == path ) {\
+ rank[$1] = $2 + 1\
+ time[$1] = now\
+ } else {\
+ rank[$1] = $2\
+ time[$1] = $3\
+ }\
+ count += $2\
+ }\
+ END {\
+ if( count > 1000 ) {\
+ for( i in rank ) print i "|" 0.9*rank[i] "|" time[i] # aging\
+ } else for( i in rank ) print i "|" rank[i] "|" time[i]\
+ }' 2>/dev/null >| "$tempfile"
if [ $? -ne 0 -a -f "$datafile" ]; then
env rm -f "$tempfile"
else
@@ -70,20 +69,19 @@ _z() {
elif [ "$1" = "--complete" ]; then
while read line; do
[ -d "${line%%\|*}" ] && echo $line
- done < "$datafile" | awk -v q="$2" -F"|" '
- BEGIN {
- if( q == tolower(q) ) nocase = 1
- split(substr(q,3),fnd," ")
- }
- {
- if( nocase ) {
- for( i in fnd ) tolower($1) !~ tolower(fnd[i]) && $1 = ""
- } else {
- for( i in fnd ) $1 !~ fnd[i] && $1 = ""
- }
- if( $1 ) print $1
- }
- ' 2>/dev/null
+ done < "$datafile" | awk -v q="$2" -F"|" '\
+ BEGIN {\
+ if( q == tolower(q) ) nocase = 1\
+ split(substr(q,3),fnd," ")\
+ }\
+ {\
+ if( nocase ) {\
+ for( i in fnd ) tolower($1) !~ tolower(fnd[i]) && $1 = ""\
+ } else {\
+ for( i in fnd ) $1 !~ fnd[i] && $1 = ""\
+ }\
+ if( $1 ) print $1\
+ }' 2>/dev/null
else
# list/go
@@ -184,7 +182,7 @@ if compctl &> /dev/null; then
}
else
_z_precmd() {
- _z --add "${PWD:A}"
+ _z --add "${PWD}"
}
fi
precmd_functions+=(_z_precmd)
--
1.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment