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:
commit
c41771e2f2
6
autojump
6
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"""
|
||||
|
@ -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="$AUTOJUMP ; ${PROMPT_COMMAND:-:}"
|
||||
|
12
autojump.zsh
12
autojump.zsh
@ -14,17 +14,17 @@
|
||||
#You should have received a copy of the GNU General Public License
|
||||
#along with autojump. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#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
|
||||
|
31
jumpapplet
31
jumpapplet
@ -29,6 +29,15 @@ from autojump import open_dic,get_dic_file
|
||||
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,17 +66,22 @@ def has_child_file(filename):
|
||||
return os.path.isfile(os.path.join(path,filename))
|
||||
return wrapper
|
||||
|
||||
#do the work
|
||||
def load_paths(maxpath=10):
|
||||
path_dict=open_dic(get_dic_file())
|
||||
path_dict=path_dict.items()
|
||||
path_dict.sort(key=lambda x: x[1],reverse=True)
|
||||
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"
|
||||
global defaults
|
||||
dic_file=os.path.expanduser(filename)
|
||||
dic_file = filename
|
||||
|
||||
try:
|
||||
aj_file=open(dic_file,'r')
|
||||
@ -85,9 +99,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)
|
||||
|
Loading…
Reference in New Issue
Block a user