1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00

Merge branch 'contrib/xdg-base-directory' of git://git.ortolo.eu/pkg-autojump into tanguy

Conflicts:

	autojump.bash
	jumpapplet

This should correctly merge Tanguy's XDG changes (thanks!) into the new
codebase.
This commit is contained in:
Joël Schaerer 2011-08-26 15:59:02 +02:00
commit c41771e2f2
4 changed files with 45 additions and 19 deletions

View File

@ -34,7 +34,11 @@ import os
MAX_KEYWEIGHT = 1000 MAX_KEYWEIGHT = 1000
MAX_STORED_PATHS = 600 MAX_STORED_PATHS = 600
COMPLETION_SEPARATOR = '__' 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): def uniqadd(collection, key):
"""Adds a key to a list only if it is not already present""" """Adds a key to a list only if it is not already present"""

View File

@ -25,23 +25,24 @@ _autojump()
done < <(autojump --bash --completion $cur) done < <(autojump --bash --completion $cur)
} }
complete -F _autojump j 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 ~) #determine the data directory according to the XDG Base Directory Specification
export AUTOJUMP_HOME=${HOME} if [ -n "$XDG_DATA_HOME" ]
if [[ "$data_dir" = "${HOME}" ]]
then then
export AUTOJUMP_DATA_DIR=${data_dir} export AUTOJUMP_DATA_DIR="$XDG_DATA_HOME/autojump"
else else
export AUTOJUMP_DATA_DIR=${data_dir}/autojump export AUTOJUMP_DATA_DIR=~/.local/share/autojump
fi fi
if [ ! -e "${AUTOJUMP_DATA_DIR}" ] if [ ! -e "${AUTOJUMP_DATA_DIR}" ]
then 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 "${AUTOJUMP_DATA_DIR}/autojump_py" 2>>/dev/null #migration
mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null
mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null
fi fi
export AUTOJUMP_HOME=${HOME}
AUTOJUMP='{ [[ "$AUTOJUMP_HOME" == "$HOME" ]] && (autojump -a "$(pwd -P)"&)>/dev/null 2>>${AUTOJUMP_DATA_DIR}/.autojump_errors;} 2>/dev/null' AUTOJUMP='{ [[ "$AUTOJUMP_HOME" == "$HOME" ]] && (autojump -a "$(pwd -P)"&)>/dev/null 2>>${AUTOJUMP_DATA_DIR}/.autojump_errors;} 2>/dev/null'
if [[ ! $PROMPT_COMMAND =~ autojump ]]; then if [[ ! $PROMPT_COMMAND =~ autojump ]]; then
export PROMPT_COMMAND="$AUTOJUMP ; ${PROMPT_COMMAND:-:}" export PROMPT_COMMAND="$AUTOJUMP ; ${PROMPT_COMMAND:-:}"

View File

@ -14,17 +14,17 @@
#You should have received a copy of the GNU General Public License #You should have received a copy of the GNU General Public License
#along with autojump. If not, see <http://www.gnu.org/licenses/>. #along with autojump. If not, see <http://www.gnu.org/licenses/>.
#local data_dir=${XDG_DATA_HOME:-$([ -e ~/.local/share ] && echo ~/.local/share || echo ~)} #determine the data directory according to the XDG Base Directory Specification
local data_dir=$([ -e ~/.local/share ] && echo ~/.local/share || echo ~) if [ -n "$XDG_DATA_HOME" ]
if [[ "$data_dir" = "${HOME}" ]]
then then
export AUTOJUMP_DATA_DIR=${data_dir} export AUTOJUMP_DATA_DIR="$XDG_DATA_HOME/autojump"
else else
export AUTOJUMP_DATA_DIR=${data_dir}/autojump export AUTOJUMP_DATA_DIR=~/.local/share/autojump
fi fi
if [ ! -e "${AUTOJUMP_DATA_DIR}" ] if [ ! -e "${AUTOJUMP_DATA_DIR}" ]
then 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 "${AUTOJUMP_DATA_DIR}/autojump_py" 2>>/dev/null #migration
mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null
mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null

View File

@ -29,6 +29,15 @@ from autojump import open_dic,get_dic_file
defaults={} defaults={}
actions={} 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 #decorator truff
def action(validator,name=None): def action(validator,name=None):
if name is None: if name is None:
@ -57,17 +66,22 @@ def has_child_file(filename):
return os.path.isfile(os.path.join(path,filename)) return os.path.isfile(os.path.join(path,filename))
return wrapper return wrapper
#do the work
def load_paths(maxpath=10): def load_paths(maxpath=10):
path_dict=open_dic(get_dic_file()) path_dict=open_dic(get_dic_file())
path_dict=path_dict.items() path_dict=path_dict.items()
path_dict.sort(key=lambda x: x[1],reverse=True) path_dict.sort(key=lambda x: x[1],reverse=True)
return [path for path,score in path_dict[:maxpath]] return [path for path,score in path_dict[:maxpath]]
def load_settings_file(filename="~/.jumpapplet_py"): def load_settings_file():
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" print "loading settings"
global defaults global defaults
dic_file=os.path.expanduser(filename) dic_file = filename
try: try:
aj_file=open(dic_file,'r') aj_file=open(dic_file,'r')
@ -85,9 +99,16 @@ def load_settings_file(filename="~/.jumpapplet_py"):
create_actions() 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" print "saving settings"
dic_file=os.path.expanduser(filename) dic_file= filename
aj_file=open(dic_file,'w') aj_file=open(dic_file,'w')
cPickle.dump(defaults,aj_file) cPickle.dump(defaults,aj_file)