mirror of
				https://github.com/wting/autojump
				synced 2025-06-13 12:54:07 +00:00 
			
		
		
		
	merge autojump_completion into autojump.sh ; fix atomic write ; avoid risk of extreme slowdown by multiple autojumps in prompt command
This commit is contained in:
		
							parent
							
								
									3d4f8a4d4f
								
							
						
					
					
						commit
						bcd5476c6d
					
				
							
								
								
									
										11
									
								
								autojump
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								autojump
									
									
									
									
									
								
							| @ -31,15 +31,18 @@ def match(path,pattern,path_dict,re_flags=0): | ||||
|             del path_dict[path] | ||||
|             return False | ||||
| 
 | ||||
| def save(path_dict,dic_file): | ||||
|     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 | ||||
| 
 | ||||
| def forget(path_dict,dic_file): | ||||
|     """Gradually forget about directories. Only call from the actual jump since it can take time""" | ||||
|     keyweight=sum(path_dict.values()) #Gradually forget about old directories | ||||
|     if keyweight>max_keyweight:  | ||||
|         for k in path_dict.keys(): | ||||
|             path_dict[k]*=0.9*max_keyweight/keyweight | ||||
|     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 | ||||
|     save(path_dict,dic_file) | ||||
| 
 | ||||
| def find_matches(dirs,pattern,path_dict,result_list,re_flags): | ||||
|     for path,count in dirs: | ||||
| @ -63,7 +66,7 @@ except IOError: | ||||
| 
 | ||||
| if ('-a','') in optlist: | ||||
|     dicadd(path_dict,args[-1]) | ||||
|     cPickle.dump(path_dict,open(dic_file,'w'),-1) | ||||
|     save(path_dict,dic_file) | ||||
| elif ('--stat','') in optlist: | ||||
|     a=path_dict.items() | ||||
|     a.sort(key=lambda e:e[1]) | ||||
|  | ||||
							
								
								
									
										11
									
								
								autojump.sh
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								autojump.sh
									
									
									
									
									
								
							| @ -1,7 +1,16 @@ | ||||
| #This shell snippet sets the prompt command and the necessary aliases | ||||
| #Only excecute if the shell is bash and it is interactive | ||||
| if [ $SHELL = "/bin/bash" ] && [ -n "$PS1" ]; then | ||||
|     export PROMPT_COMMAND='autojump -a "$(pwd -P)";'"$PROMPT_COMMAND" | ||||
|     _autojump()  | ||||
|     { | ||||
|             local cur | ||||
|             COMPREPLY=() | ||||
|             cur=${COMP_WORDS[1]} | ||||
|             IFS=$'\n' read -d '' -a COMPREPLY < <(autojump --completion "$cur") | ||||
|             return 0 | ||||
|     } | ||||
|     complete -F _autojump j | ||||
|     export PROMPT_COMMAND='autojump -a "$(pwd -P)"' | ||||
|     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 } | ||||
| fi | ||||
|  | ||||
| @ -2,12 +2,3 @@ | ||||
| # | ||||
| # $Id: unrar,v 1.4 2004/07/05 23:37:47 ianmacd Exp $ | ||||
| 
 | ||||
| _autojump()  | ||||
| { | ||||
| 	local cur | ||||
| 	COMPREPLY=() | ||||
| 	cur=${COMP_WORDS[1]} | ||||
| 	IFS=$'\n' read -d '' -a COMPREPLY < <(autojump --completion "$cur") | ||||
| 	return 0 | ||||
| } | ||||
| complete -F _autojump j | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user