mirror of
https://github.com/wting/autojump
synced 2025-06-13 12:54:07 +00:00
* Separate cd from autojump -a (use j instead)
* Add directory completion to j (bash only) * Add _autojump completion to autojump (bash only) * Add --remove and --purge command to autojump
This commit is contained in:
parent
0217d6e066
commit
f624838766
28
autojump
28
autojump
@ -44,6 +44,12 @@ def uniqadd(list,key):
|
||||
def dicadd(dic,key,increment=1):
|
||||
dic[key]=dic.get(key,0.)+increment
|
||||
|
||||
def dicremove(dic,key):
|
||||
if key not in dic:
|
||||
return False
|
||||
del dic[key]
|
||||
return True
|
||||
|
||||
def save(path_dict,dic_file):
|
||||
f=NamedTemporaryFile(dir=config_dir,delete=False)
|
||||
pickle.dump(path_dict,f,-1)
|
||||
@ -120,7 +126,7 @@ def open_dic(dic_file,error_recovery=False):
|
||||
|
||||
#Main code
|
||||
try:
|
||||
optlist, args = getopt.getopt(argv[1:], 'a',['stat','import','completion', 'bash'])
|
||||
optlist, args = getopt.getopt(argv[1:], 'a',['remove', 'purge', 'stat','import','completion', 'bash'])
|
||||
except getopt.GetoptError as e:
|
||||
print("Unknown command line argument: %s" % e)
|
||||
exit(1)
|
||||
@ -134,6 +140,26 @@ if ('-a','') in optlist:
|
||||
if(args[-1] != os.path.expanduser("~")): # home dir can be reached quickly by "cd" and may interfere with other directories
|
||||
dicadd(path_dict,args[-1])
|
||||
save(path_dict,dic_file)
|
||||
elif ('--remove','') in optlist and ('--completion', '') not in optlist:
|
||||
try:
|
||||
if dicremove(path_dict,args[-1]):
|
||||
save(path_dict,dic_file)
|
||||
except:
|
||||
print "usage : autojump --remove key"
|
||||
print "Remove key from autojump database"
|
||||
exit
|
||||
elif ('--purge','') in optlist:
|
||||
try:
|
||||
a=path_dict.items()
|
||||
limit=int(args[-1])
|
||||
for path,count in a:
|
||||
if count <= limit:
|
||||
dicremove(path_dict,path)
|
||||
save(path_dict,dic_file)
|
||||
except:
|
||||
print "usage : autojump --purge MaxKeyWeight"
|
||||
print "Remove all keys <= MaxKeyWeight"
|
||||
exit
|
||||
elif ('--stat','') in optlist:
|
||||
a=list(path_dict.items())
|
||||
a.sort(key=itemgetter(1))
|
||||
|
@ -24,7 +24,8 @@ _autojump()
|
||||
COMPREPLY=("${COMPREPLY[@]}" "${i}")
|
||||
done < <(autojump --bash --completion $cur)
|
||||
}
|
||||
complete -F _autojump j
|
||||
complete -o dirnames -F _autojump j
|
||||
complete -F _autojump autojump
|
||||
#data_dir=${XDG_DATA_HOME:-$([ -e ~/.local/share ] && echo ~/.local/share || echo ~)}
|
||||
data_dir=$([ -e ~/.local/share ] && echo ~/.local/share || echo ~)
|
||||
export AUTOJUMP_HOME=${HOME}
|
||||
@ -43,8 +44,21 @@ then
|
||||
fi
|
||||
|
||||
AUTOJUMP='{ [[ "$AUTOJUMP_HOME" == "$HOME" ]] && (autojump -a "$(pwd -P)"&)>/dev/null 2>>${AUTOJUMP_DATA_DIR}/autojump_errors;} 2>/dev/null'
|
||||
if [[ ! $PROMPT_COMMAND =~ autojump ]]; then
|
||||
export PROMPT_COMMAND="${PROMPT_COMMAND:-:} ; $AUTOJUMP"
|
||||
fi
|
||||
# if [[ ! $PROMPT_COMMAND =~ autojump ]]; then
|
||||
# export PROMPT_COMMAND="${PROMPT_COMMAND:-:} ; $AUTOJUMP"
|
||||
# fi
|
||||
alias jumpstat="autojump --stat"
|
||||
function j { new_path="$(autojump $@)";if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; cd "$new_path";fi }
|
||||
function j {
|
||||
new_path="$(autojump $@)"
|
||||
if [ -n "$new_path" ]; then
|
||||
echo -e "\\033[31m${new_path}\\033[0m"
|
||||
cd "$new_path";
|
||||
autojump -a "$(pwd -P)" >/dev/null 2>>${AUTOJUMP_DATA_DIR}/.autojump_errors
|
||||
else
|
||||
if [ -d "$@" ] ; then
|
||||
cd "$@"
|
||||
echo -e "\\033[31m$(pwd -P)\\033[0m"
|
||||
autojump -a "$(pwd -P)" >/dev/null 2>>${AUTOJUMP_DATA_DIR}/.autojump_errors
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user