From 3ff9135aa11288d7634fe7d3afd57ffdda917cd3 Mon Sep 17 00:00:00 2001 From: Joel Schaerer Date: Sat, 14 Feb 2009 00:39:54 +0100 Subject: [PATCH 1/5] small changes --- autojump | 8 +++++--- autojump.sh | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/autojump b/autojump index b092a76..cee0a04 100755 --- a/autojump +++ b/autojump @@ -81,7 +81,8 @@ else: print path found=True break - else: uniqadd(results,path) + else: + uniqadd(results,path) dirs=path_dict.items() #we need to recreate the list since the first iteration potentially deletes paths dirs.sort(key=lambda e:e[1],reverse=True) if not found: @@ -90,9 +91,10 @@ else: if not completion: print path break - else: uniqadd(results,path) + else: + uniqadd(results,path) if completion: - print " ".join(results) + print " ".join(("%.4d)_%s" % (n,r) for n,r in enumerate(results))) cPickle.dump(path_dict,open(dic_file+".tmp",'w'),-1) import shutil shutil.copy(dic_file+".tmp",dic_file) #cPickle.dump doesn't seem to be atomic, so this is more secure diff --git a/autojump.sh b/autojump.sh index adea395..a23e1d8 100644 --- a/autojump.sh +++ b/autojump.sh @@ -1,5 +1,5 @@ if [ $SHELL = "/bin/bash" ]; then export PROMPT_COMMAND='autojump -a "$(pwd -P)";'"$PROMPT_COMMAND" alias jumpstat="autojump --stat" - function j { new_path=$(autojump $@);if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; echo; cd "$new_path";fi } + function j { new_path=$(autojump $@ | sed 's/.*)_//');if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; echo; cd "$new_path";fi } fi From d5a7c0579a338663a14e5c669ae75ca716e488cc Mon Sep 17 00:00:00 2001 From: Joel Schaerer Date: Sat, 14 Feb 2009 00:41:03 +0100 Subject: [PATCH 2/5] use only the last argument --- autojump | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autojump b/autojump index cee0a04..4e632a2 100755 --- a/autojump +++ b/autojump @@ -49,7 +49,7 @@ except IOError: path_dict={} if ('-a','') in optlist: - dicadd(path_dict," ".join(args)) + dicadd(path_dict,args[-1]) cPickle.dump(path_dict,open(dic_file,'w'),-1) elif ('--stat','') in optlist: a=path_dict.items() @@ -58,7 +58,7 @@ elif ('--stat','') in optlist: print "%.1f:\t%s" % (count,path) print "Total key weight: %d" % sum(path_dict.values()) elif ('--import','') in optlist: - for i in open(" ".join(args)).readlines(): + for i in open(args[-1]).readlines(): dicadd(path_dict,i[:-1]) cPickle.dump(path_dict,open(dic_file,'w'),-1) else: @@ -76,7 +76,7 @@ else: import re found=False for path,count in dirs: - if match(path," ".join(args),path_dict): #First look for case-matching path + if match(path,args[-1],path_dict): #First look for case-matching path if not completion: print path found=True @@ -87,7 +87,7 @@ else: dirs.sort(key=lambda e:e[1],reverse=True) if not found: for path,count in dirs: - if match(path," ".join(args),path_dict,re.IGNORECASE): #Then try to ignore case + if match(path,args[-1],path_dict,re.IGNORECASE): #Then try to ignore case if not completion: print path break From 4b64944832ac8904232effbf84479ceb322fac88 Mon Sep 17 00:00:00 2001 From: Joel Schaerer Date: Sat, 14 Feb 2009 00:51:07 +0100 Subject: [PATCH 3/5] this is already something... --- autojump | 2 +- autojump.sh | 2 +- autojump_completion | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 autojump_completion diff --git a/autojump b/autojump index 4e632a2..6e727f5 100755 --- a/autojump +++ b/autojump @@ -94,7 +94,7 @@ else: else: uniqadd(results,path) if completion: - print " ".join(("%.4d)_%s" % (n,r) for n,r in enumerate(results))) + print " ".join(("%d)%s" % (n,r) for n,r in enumerate(results))) cPickle.dump(path_dict,open(dic_file+".tmp",'w'),-1) import shutil shutil.copy(dic_file+".tmp",dic_file) #cPickle.dump doesn't seem to be atomic, so this is more secure diff --git a/autojump.sh b/autojump.sh index a23e1d8..adea395 100644 --- a/autojump.sh +++ b/autojump.sh @@ -1,5 +1,5 @@ if [ $SHELL = "/bin/bash" ]; then export PROMPT_COMMAND='autojump -a "$(pwd -P)";'"$PROMPT_COMMAND" alias jumpstat="autojump --stat" - function j { new_path=$(autojump $@ | sed 's/.*)_//');if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; echo; cd "$new_path";fi } + function j { new_path=$(autojump $@);if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; echo; cd "$new_path";fi } fi diff --git a/autojump_completion b/autojump_completion new file mode 100644 index 0000000..a7d81f0 --- /dev/null +++ b/autojump_completion @@ -0,0 +1,31 @@ +# unrar(1) completion by Guillaume Rousse +# +# $Id: unrar,v 1.4 2004/07/05 23:37:47 ianmacd Exp $ + +_autojump() +{ + local cur + + COMPREPLY=() + cur=${COMP_WORDS[1]} + COMPREPLY=($(autojump --completion "$cur")) + +# case "$cur" in +# -*) +# COMPREPLY=( $( compgen -W '-ad -ap -av- -c- -cfg- -cl -cu \ +# -dh -ep -f -idp -ierr -inul -kb -o+ -o- -ow -p -p- -r -ta \ +# -tb -tn -to -u -v -ver -vp -x -x@ -y' -- $cur ) ) +# ;; +# *) +# if [ $COMP_CWORD -eq 1 ]; then +# COMPREPLY=( $( compgen -W 'e l lb lt p t v vb vt x' -- $cur ) ) +# else +# _filedir '@(rar|RAR)' +# fi +# ;; +# esac + + return 0 + +} +complete -F _autojump j From 1f2292708ac1af49a97ced23b39226f79e5fac1b Mon Sep 17 00:00:00 2001 From: Joel Schaerer Date: Sat, 14 Feb 2009 01:18:11 +0100 Subject: [PATCH 4/5] ok this is already a little better --- autojump | 9 +++++---- autojump.sh | 0 2 files changed, 5 insertions(+), 4 deletions(-) mode change 100644 => 100755 autojump.sh diff --git a/autojump b/autojump index 6e727f5..8643171 100755 --- a/autojump +++ b/autojump @@ -62,6 +62,7 @@ elif ('--import','') in optlist: dicadd(path_dict,i[:-1]) cPickle.dump(path_dict,open(dic_file,'w'),-1) else: + import re completion=False if ('--completion','') in optlist: completion=True @@ -71,12 +72,12 @@ else: for k in path_dict.keys(): path_dict[k]*=0.9*max_keyweight/keyweight if not args: args=[''] + argument=re.sub("[0-9]*\__","",args[-1]) dirs=path_dict.items() dirs.sort(key=lambda e:e[1],reverse=True) - import re found=False for path,count in dirs: - if match(path,args[-1],path_dict): #First look for case-matching path + if match(path,argument,path_dict): #First look for case-matching path if not completion: print path found=True @@ -87,14 +88,14 @@ else: dirs.sort(key=lambda e:e[1],reverse=True) if not found: for path,count in dirs: - if match(path,args[-1],path_dict,re.IGNORECASE): #Then try to ignore case + if match(path,argument,path_dict,re.IGNORECASE): #Then try to ignore case if not completion: print path break else: uniqadd(results,path) if completion: - print " ".join(("%d)%s" % (n,r) for n,r in enumerate(results))) + print " ".join(("%d__%s" % (n,r) for n,r in enumerate(results))) cPickle.dump(path_dict,open(dic_file+".tmp",'w'),-1) import shutil shutil.copy(dic_file+".tmp",dic_file) #cPickle.dump doesn't seem to be atomic, so this is more secure diff --git a/autojump.sh b/autojump.sh old mode 100644 new mode 100755 From 81c8e3ea3fea25fc3b8ff83e90421c6b5e18139c Mon Sep 17 00:00:00 2001 From: Joel Schaerer Date: Sat, 14 Feb 2009 01:57:49 +0100 Subject: [PATCH 5/5] still buggy, but I think we are improving --- autojump | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/autojump b/autojump index 8643171..2ed1fdb 100755 --- a/autojump +++ b/autojump @@ -64,6 +64,7 @@ elif ('--import','') in optlist: else: import re completion=False + userchoice=-1 #3 if the pattern is of the form __pattern__3, otherwise -1 if ('--completion','') in optlist: completion=True results=[] @@ -72,7 +73,18 @@ else: for k in path_dict.keys(): path_dict[k]*=0.9*max_keyweight/keyweight if not args: args=[''] - argument=re.sub("[0-9]*\__","",args[-1]) + if completion: + argument=args[-1] + endmatch=re.search("__([0-9]+)$",argument) + if endmatch: + userchoice=int(endmatch.group(1)) + argument=argument[2:] + argument=re.sub("__[0-9]+$","",argument) + else: + endmatch=re.match("__(.*)__",argument) + if endmatch: argument=endmatch.group(1) + else: + argument=re.sub("^__.*__[0-9]+__","",args[-1]) dirs=path_dict.items() dirs.sort(key=lambda e:e[1],reverse=True) found=False @@ -95,7 +107,10 @@ else: else: uniqadd(results,path) if completion: - print " ".join(("%d__%s" % (n,r) for n,r in enumerate(results))) + if userchoice!=-1: + print results[userchoice] + else: + print " ".join(("__%s__%d__%s" % (argument,n,r) for n,r in enumerate(results))) cPickle.dump(path_dict,open(dic_file+".tmp",'w'),-1) import shutil shutil.copy(dic_file+".tmp",dic_file) #cPickle.dump doesn't seem to be atomic, so this is more secure