From 8dc4688f633189959254c77b7cffb8e9d647ab98 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 18 May 2009 18:58:19 -0500 Subject: update autojump script --- bash/j.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'bash') diff --git a/bash/j.sh b/bash/j.sh index db1f541..e0306b3 100644 --- a/bash/j.sh +++ b/bash/j.sh @@ -32,19 +32,18 @@ j() { # we're in $HOME all the time, let something else get all the good letters [ "$*" = "$HOME" ] && return awk -v q="$*" -v t="$(date +%s)" -F"|" ' + BEGIN { l[q] = 1; d[q] = t } $2 >= 1 { if( $1 == q ) { l[$1] = $2 + 1 d[$1] = t - found = 1 } else { l[$1] = $2 d[$1] = $3 - count += $2 } + count += $2 } END { - if( !found ) l[q] = 1 && d[q] = t if( count > 1000 ) { for( i in l ) print i "|" 0.9*l[i] "|" d[i] # aging } else for( i in l ) print i "|" l[i] "|" d[i] @@ -53,7 +52,7 @@ j() { mv -f $jfile.tmp $jfile return } - # tab completion + # for tab completion [ "$1" = "--complete" ] && { awk -v q="$2" -F"|" ' BEGIN { split(substr(q,3),a," ") } @@ -67,7 +66,7 @@ j() { if [ $1 ]; then local x; local out for x do case $x in - --h*) echo "j [--h[elp]] [--r] [--l] [regex1 ... regexn]"; return;; + --h*) echo "j [--h[elp]] [--l] [--r] [--s] [regex1 ... regexn]"; return;; --l)local list=1;; --r)local recent=r;; --s)local short=1;; @@ -77,14 +76,20 @@ j() { else local list=1 fi + # remove directories that no longer exist + awk -F"|" ' + { if( system("test -d \"" $1 "\"") ) next; print $0 } + ' $jfile 2>/dev/null > $jfile.tmp + mv -f $jfile.tmp $jfile if [ $list ]; then [ "$short" ] && return awk -v q="$*" -v t="$(date +%s)" -v r="$recent" -F"|" ' BEGIN { f = 2; split(q,a," "); if( r ) f = 3 } { - if( system("test -d \"" $1 "\"") ) next for( i in a ) $1 !~ a[i] && $1 = "" - if( $1 ) if( f == 3 ) { print t - $f "\t" $1 } else print $f "\t" $1 + if( $1 ) if( f == 3 ) { + print t - $f "\t" $1 + } else print $f "\t" $1 } ' $jfile 2>/dev/null | sort -n$recent # if we hit enter on a completion just go there @@ -95,7 +100,6 @@ j() { out=$(awk -v q="$*" -v s="$short" -v r="$recent" -F"|" ' BEGIN { split(q,a," "); if( r ) { f = 3 } else f = 2 } { - if( system("test -d \"" $1 "\"") ) next for( i in a ) $1 !~ a[i] && $1 = "" if( $1 ) { if( s ) { @@ -109,7 +113,6 @@ j() { if( ! x ) { close(FILENAME) while( getline < FILENAME ) { - if( system("test -d \"" $1 "\"") ) continue for( i in a ) tolower($1) !~ tolower(a[i]) && $1 = "" if( $1 ) { if( s ) { -- cgit v1.2.3-54-g00ecf