From 88575c72f8b7bce926ee17f58058351f6c8a190d Mon Sep 17 00:00:00 2001 From: Tanguy Ortolo Date: Sun, 24 Jul 2011 20:56:46 +0200 Subject: [PATCH 1/3] Let jumpapplet follow the XDG Base Directory Spec. --- jumpapplet | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/jumpapplet b/jumpapplet index 4b44826..4e5fff0 100755 --- a/jumpapplet +++ b/jumpapplet @@ -28,6 +28,15 @@ import gtk defaults={} actions={} +#directory finding helpers, conforming to the XDG Base Directory Specification +def data_dir(): + xdg_data_dir = os.environ.get('XDG_DATA_HOME') or os.path.join(os.environ['HOME'], '.local', 'share') + return os.path.join(xdg_data_dir, 'autojump') + +def config_dir(): + xdg_config_dir = os.environ.get('XDG_CONFIG_HOME') or os.path.join(os.environ['HOME'], '.config') + return os.path.join(xdg_config_dir, 'autojump') + #decorator truff def action(validator,name=None): if name is None: @@ -57,8 +66,11 @@ def has_child_file(filename): return wrapper #do the work -def load_paths(filename="~/.autojump_py",maxpath=10): - dic_file=os.path.expanduser(filename) +def load_paths(filename=None,maxpath=10): + if not filename: + filename = os.path.join(data_dir(), 'autojump_py') + + dic_file = filename try: aj_file=open(dic_file) @@ -71,10 +83,18 @@ def load_paths(filename="~/.autojump_py",maxpath=10): except IOError: return [] -def load_settings_file(filename="~/.jumpapplet_py"): +def load_settings_file(filename=None): + if not filename: + filename = os.path.join(config_dir(), 'jumpapplet_py') + + #migration from old location + old_filename = os.path.join(os.environ['HOME'], '.jumpapplet_py') + if not os.path.exists(filename) and os.path.exists(old_filename): + os.rename(old_filename, filename) + print "loading settings" global defaults - dic_file=os.path.expanduser(filename) + dic_file = filename try: aj_file=open(dic_file,'r') @@ -92,9 +112,16 @@ def load_settings_file(filename="~/.jumpapplet_py"): create_actions() -def save_settings_file(filename="~/.jumpapplet_py"): +def save_settings_file(filename=None): + directory = config_dir() + if not filename: + filename = os.path.join(directory, 'jumpapplet_py') + + if not os.path.exists(directory): + os.makedirs(directory) + print "saving settings" - dic_file=os.path.expanduser(filename) + dic_file= filename aj_file=open(dic_file,'w') cPickle.dump(defaults,aj_file) From a45d94167fd740761acc73cbd2c9d9ca85c98f8b Mon Sep 17 00:00:00 2001 From: Tanguy Ortolo Date: Sun, 24 Jul 2011 21:08:56 +0200 Subject: [PATCH 2/3] Update the shell snippets to use the XDG spec. --- autojump.bash | 15 ++++++++------- autojump.zsh | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/autojump.bash b/autojump.bash index e512640..7f7e3d8 100644 --- a/autojump.bash +++ b/autojump.bash @@ -25,23 +25,24 @@ _autojump() done < <(autojump --bash --completion $cur) } complete -F _autojump j -#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} -if [[ "$data_dir" = "${HOME}" ]] + +#determine the data directory according to the XDG Base Directory Specification +if [ -n "$XDG_DATA_HOME" ] then - export AUTOJUMP_DATA_DIR=${data_dir} + export AUTOJUMP_DATA_DIR="$XDG_DATA_HOME/autojump" else - export AUTOJUMP_DATA_DIR=${data_dir}/autojump + export AUTOJUMP_DATA_DIR=~/.local/share/autojump fi + if [ ! -e "${AUTOJUMP_DATA_DIR}" ] then - mkdir "${AUTOJUMP_DATA_DIR}" + mkdir -p "${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 +export AUTOJUMP_HOME=${HOME} 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" diff --git a/autojump.zsh b/autojump.zsh index fcf24a0..d2a98b4 100644 --- a/autojump.zsh +++ b/autojump.zsh @@ -14,17 +14,17 @@ #You should have received a copy of the GNU General Public License #along with autojump. If not, see . -#local data_dir=${XDG_DATA_HOME:-$([ -e ~/.local/share ] && echo ~/.local/share || echo ~)} -local data_dir=$([ -e ~/.local/share ] && echo ~/.local/share || echo ~) -if [[ "$data_dir" = "${HOME}" ]] +#determine the data directory according to the XDG Base Directory Specification +if [ -n "$XDG_DATA_HOME" ] then - export AUTOJUMP_DATA_DIR=${data_dir} + export AUTOJUMP_DATA_DIR="$XDG_DATA_HOME/autojump" else - export AUTOJUMP_DATA_DIR=${data_dir}/autojump + export AUTOJUMP_DATA_DIR=~/.local/share/autojump fi + if [ ! -e "${AUTOJUMP_DATA_DIR}" ] then - mkdir "${AUTOJUMP_DATA_DIR}" + mkdir -p "${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 From 07ad27b583acfa5c8529fc1ae92ec7f4495bb782 Mon Sep 17 00:00:00 2001 From: Tanguy Ortolo Date: Sun, 24 Jul 2011 21:16:36 +0200 Subject: [PATCH 3/3] Let autojump follow the XDG Base Directory Spec. It now uses $AUTOJUMP_HOME if set, else $XDG_DATA_HOME/autojump if set, else ~/.local/share/autojump. --- autojump | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autojump b/autojump index 7a2702d..2e321da 100755 --- a/autojump +++ b/autojump @@ -34,7 +34,11 @@ import os MAX_KEYWEIGHT = 1000 MAX_STORED_PATHS = 600 COMPLETION_SEPARATOR = '__' -CONFIG_DIR = os.environ.get("AUTOJUMP_DATA_DIR", os.path.expanduser("~")) +if "AUTOJUMP_DATA_DIR" in os.environ: + CONFIG_DIR = os.environ.get("AUTOJUMP_DATA_DIR") +else: + xdg_data_dir = os.environ.get('XDG_DATA_HOME') or os.path.join(os.environ['HOME'], '.local', 'share') + CONFIG_DIR=os.path.join(xdg_data_dir, 'autojump') def uniqadd(collection, key): """Adds a key to a list only if it is not already present"""