From 4de9c1c3115affbd9311e554ef701c2ac1e7af8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Schaerer?= Date: Mon, 26 Jul 2010 16:24:34 +0200 Subject: [PATCH] put the autojump data files in the correct directories. Existing files should be migrated automatically --- autojump | 6 +++++- autojump.bash | 17 ++++++++++++++++- autojump.zsh | 17 ++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/autojump b/autojump index ee6de9a..68489a9 100755 --- a/autojump +++ b/autojump @@ -24,6 +24,7 @@ import signal max_keyweight=1000 max_stored_paths=400 completion_separator='__' +config_dir=os.environ.get("AUTOJUMP_DATA_DIR",os.path.expanduser("~")) def signal_handler(arg1,arg2): print "Received SIGINT, trying to continue" @@ -123,7 +124,10 @@ except getopt.GetoptError, e: print "Unknown command line argument: %s" % e exit(1) -dic_file=os.path.expanduser("~/.autojump_py") +if config_dir == os.path.expanduser("~"): + dic_file=config_dir+"/.autojump_py" +else: + dic_file=config_dir+"/autojump_py" path_dict=open_dic(dic_file) if ('-a','') in optlist: if(args[-1] != os.path.expanduser("~")): # home dir can be reached quickly by "cd" and may interfere with other directories diff --git a/autojump.bash b/autojump.bash index 7f03b00..88ded03 100644 --- a/autojump.bash +++ b/autojump.bash @@ -25,7 +25,22 @@ _autojump() done < <(autojump --bash --completion $cur) } complete -F _autojump j -AUTOJUMP='{ (autojump -a "$(pwd -P)"&)>/dev/null 2>>${HOME}/.autojump_errors;} 2>/dev/null' +data_dir=${XDG_DATA_DIR:-$([ -e ~/.config ] && echo ~/.config || echo ~)} +if [ "$data_dir" = "~" ] +then + export AUTOJUMP_DATA_DIR=${data_dir} +else + export AUTOJUMP_DATA_DIR=${data_dir}/autojump +fi +if [ ! -e "${AUTOJUMP_DATA_DIR}" ] +then + mkdir "${AUTOJUMP_DATA_DIR}" + mv ~/.autojump_py "${AUTOJUMP_DATA_DIR}/autojump_py" 2>>/dev/null #migration + mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null + mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null +fi + +AUTOJUMP='{ (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 diff --git a/autojump.zsh b/autojump.zsh index bbf9df0..59b6c07 100755 --- a/autojump.zsh +++ b/autojump.zsh @@ -14,8 +14,23 @@ #You should have received a copy of the GNU General Public License #along with autojump. If not, see . +data_dir=${XDG_DATA_DIR:-$([ -e ~/.config ] && echo ~/.config || echo ~)} +if [ "$data_dir" = "~" ] +then + export AUTOJUMP_DATA_DIR=${data_dir} +else + export AUTOJUMP_DATA_DIR=${data_dir}/autojump +fi +if [ ! -e "${AUTOJUMP_DATA_DIR}" ] +then + mkdir "${AUTOJUMP_DATA_DIR}" + mv ~/.autojump_py "${AUTOJUMP_DATA_DIR}/autojump_py" 2>>/dev/null #migration + mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null + mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null +fi + function autojump_preexec() { - { (autojump -a "$(pwd -P)"&)>/dev/null 2>>|${HOME}/.autojump_errors ; } 2>/dev/null + { (autojump -a "$(pwd -P)"&)>/dev/null 2>>|${AUTOJUMP_DATA_DIR}/.autojump_errors ; } 2>/dev/null } typeset -ga preexec_functions