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

cleanup, add custom installation support, change default windows install directory

This commit is contained in:
Michael Lawson 2014-01-16 11:39:17 +00:00
parent 7a756aaa4e
commit ff9376cb93
4 changed files with 80 additions and 46 deletions

View File

@ -75,7 +75,7 @@ def set_defaults():
'autojump')
elif is_windows():
data_home = os.path.join(
os.getenv('LOCALAPPDATA'),
os.getenv('APPDATA'),
'autojump')
else:
data_home = os.getenv(
@ -263,7 +263,7 @@ def match_consecutive(needles, haystack, ignore_case=False):
(path="/moo/foo/baz", weight=10),
(path="/foo/baz", weight=10)]
"""
sep = os.sep.encode('string-escape')
sep = os.sep.replace('\\','\\\\')
regex_no_sep = '[^' + sep + ']*'
regex_one_sep = regex_no_sep + sep + regex_no_sep
regex_no_sep_end = regex_no_sep + '$'

View File

@ -1,8 +1,7 @@
local HOME = clink.get_env("USERPROFILE") .."\\"
local AUTOJUMP_BIN = HOME .. ".autojump\\bin\\autojump"
local AUTOJUMP_BIN = (AUTOJUMP_BIN_DIR or clink.get_env("LOCALAPPDATA") .. "\\autojump\\bin") .. "\\autojump"
function autojump_add_to_database()
os.execute("python " .. AUTOJUMP_BIN .. " --add " .. clink.get_cwd())
os.execute("python " .. AUTOJUMP_BIN .. " --add " .. clink.get_cwd() .. " 2> " .. clink.get_env("TEMP") .. "\\autojump_error.txt")
end
clink.prompt.register_filter(autojump_add_to_database, 99)

View File

@ -42,13 +42,27 @@ def modify_autojump_sh(etc_dir, dryrun=False):
f.write(custom_install)
def modify_autojump_lua(clink_dir, bin_dir, dryrun=False):
"""Prepend custom AUTOJUMP_BIN_DIR definition to autojump.lua"""
custom_install = "local AUTOJUMP_BIN_DIR = \"%s\"\n" % bin_dir.replace("\\", "\\\\")
clink_file = os.path.join(clink_dir, 'autojump.lua')
with open(clink_file, 'r') as f:
original = f.read()
with open(clink_file, 'w') as f:
f.write(custom_install + original)
def parse_arguments():
default_user_destdir = os.path.join(os.path.expanduser("~"), '.autojump')
if platform.system() == 'Windows':
default_user_destdir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'autojump')
else:
default_user_destdir = os.path.join(os.path.expanduser("~"), '.autojump')
default_user_prefix = ''
default_user_zshshare = 'functions'
default_system_destdir = '/'
default_system_prefix = '/usr/local'
default_system_zshshare = '/usr/share/zsh/site-functions'
default_clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink')
parser = ArgumentParser(
description='Installs autojump globally for root users, otherwise \
@ -68,6 +82,9 @@ def parse_arguments():
parser.add_argument(
'-z', '--zshshare', metavar='DIR', default=default_user_zshshare,
help='set zsh share destination to DIR')
parser.add_argument(
'-c', '--clinkdir', metavar='DIR', default=default_clink_dir,
help='set clink directory location to DIR (Windows only)')
parser.add_argument(
'-s', '--system', action="store_true", default=False,
help='install system wide for all users')
@ -78,21 +95,20 @@ def parse_arguments():
if sys.version_info[0] == 2 and sys.version_info[1] < 6:
print("Python v2.6+ or v3.0+ required.", file=sys.stderr)
sys.exit(1)
if platform.system() != 'Windows':
if get_shell() not in SUPPORTED_SHELLS:
print("Unsupported shell: %s" % os.getenv('SHELL'),
file=sys.stderr)
sys.exit(1)
if args.system and os.geteuid() != 0:
print("Please rerun as root for system-wide installation.",
file=sys.stderr)
sys.exit(1)
else:
if args.system:
if args.system:
if platform.system() == 'Windows':
print("System-wide installation is not supported on Windows.",
file=sys.stderr)
sys.exit(1)
elif os.geteuid() != 0:
print("Please rerun as root for system-wide installation.",
file=sys.stderr)
sys.exit(1)
if platform.system() != 'Windows' and get_shell() not in SUPPORTED_SHELLS:
print("Unsupported shell: %s" % os.getenv('SHELL'),
file=sys.stderr)
sys.exit(1)
if args.destdir != default_user_destdir \
or args.prefix != default_user_prefix \
@ -115,7 +131,9 @@ def parse_arguments():
def print_post_installation_message(etc_dir, bin_dir):
if platform.system() != 'Windows':
if platform.system() == 'Windows':
print("\nPlease manually add %s to your user path" % bin_dir)
else:
if get_shell() == 'fish':
aj_shell = '%s/autojump.fish' % etc_dir
source_msg = "if test -f %s; . %s; end" % (aj_shell, aj_shell)
@ -135,8 +153,6 @@ def print_post_installation_message(etc_dir, bin_dir):
print('\n\t' + source_msg)
if get_shell() == 'zsh':
print("\n\tautoload -U compinit && compinit -u")
else:
print("\nPlease manually add %s to your user path" % bin_dir)
print("\nPlease restart terminal(s) before running autojump.\n")
@ -151,19 +167,32 @@ def main(args):
doc_dir = os.path.join(args.destdir, args.prefix, 'share', 'man', 'man1')
icon_dir = os.path.join(args.destdir, args.prefix, 'share', 'autojump')
zshshare_dir = os.path.join(args.destdir, args.zshshare)
clink_dir = os.path.join(os.getenv("LOCALAPPDATA"),'clink')
mkdir(bin_dir, args.dryrun)
mkdir(etc_dir, args.dryrun)
mkdir(doc_dir, args.dryrun)
mkdir(icon_dir, args.dryrun)
mkdir(zshshare_dir, args.dryrun)
cp('./bin/autojump', bin_dir, args.dryrun)
cp('./bin/autojump_argparse.py', bin_dir, args.dryrun)
cp('./bin/autojump_data.py', bin_dir, args.dryrun)
cp('./bin/autojump_utils.py', bin_dir, args.dryrun)
if platform.system() != 'Windows':
cp('./bin/icon.png', icon_dir, args.dryrun)
cp('./docs/autojump.1', doc_dir, args.dryrun)
if platform.system() == 'Windows':
cp('./bin/autojump.lua', args.clinkdir, args.dryrun)
cp('./bin/autojump.bat', bin_dir, args.dryrun)
cp('./bin/j.bat', bin_dir, args.dryrun)
cp('./bin/jc.bat', bin_dir, args.dryrun)
cp('./bin/jo.bat', bin_dir, args.dryrun)
cp('./bin/jco.bat', bin_dir, args.dryrun)
if args.custom_install:
modify_autojump_lua(args.clinkdir, bin_dir, args.dryrun)
else:
mkdir(etc_dir, args.dryrun)
mkdir(zshshare_dir, args.dryrun)
cp('./bin/autojump.sh', etc_dir, args.dryrun)
cp('./bin/autojump.bash', etc_dir, args.dryrun)
cp('./bin/autojump.fish', etc_dir, args.dryrun)
@ -172,16 +201,6 @@ def main(args):
if args.custom_install:
modify_autojump_sh(etc_dir, args.dryrun)
else:
cp('./bin/autojump.lua', clink_dir, args.dryrun)
cp('./bin/autojump.bat', bin_dir, args.dryrun)
cp('./bin/j.bat', bin_dir, args.dryrun)
cp('./bin/jc.bat', bin_dir, args.dryrun)
cp('./bin/jo.bat', bin_dir, args.dryrun)
cp('./bin/jco.bat', bin_dir, args.dryrun)
cp('./bin/icon.png', icon_dir, args.dryrun)
cp('./docs/autojump.1', doc_dir, args.dryrun)
print_post_installation_message(etc_dir, bin_dir)

View File

@ -23,6 +23,8 @@ def is_empty_dir(path):
def parse_arguments():
default_clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink')
parser = ArgumentParser(
description='Uninstalls autojump.')
parser.add_argument(
@ -40,6 +42,8 @@ def parse_arguments():
parser.add_argument(
'-z', '--zshshare', metavar='DIR', default='functions',
help='custom zshshare')
parser.add_argument(
'-c', '--clinkdir', metavar='DIR', default=default_clink_dir)
return parser.parse_args()
@ -61,11 +65,21 @@ def remove_custom_installation(args, dryrun=False):
rm(os.path.join(bin_dir, 'autojump'), dryrun)
rm(os.path.join(bin_dir, 'autojump_data.py'), dryrun)
rm(os.path.join(bin_dir, 'autojump_utils.py'), dryrun)
rm(os.path.join(etc_dir, 'autojump.sh'), dryrun)
rm(os.path.join(etc_dir, 'autojump.bash'), dryrun)
rm(os.path.join(etc_dir, 'autojump.fish'), dryrun)
rm(os.path.join(etc_dir, 'autojump.zsh'), dryrun)
rm(os.path.join(zshshare_dir, '_j'), dryrun)
rm(os.path.join(bin_dir, 'autojump_argparse.py'), dryrun)
if platform.system() == 'Windows':
if os.path.exists(args.clinkdir):
rm(os.path.join(args.clinkdir, 'autojump.lua'), dryrun)
rm(os.path.join(bin_dir, 'autojump.bat'), dryrun)
rm(os.path.join(bin_dir, 'j.bat'), dryrun)
rm(os.path.join(bin_dir, 'jc.bat'), dryrun)
rm(os.path.join(bin_dir, 'jco.bat'), dryrun)
rm(os.path.join(bin_dir, 'jo.bat'), dryrun)
else:
rm(os.path.join(etc_dir, 'autojump.sh'), dryrun)
rm(os.path.join(etc_dir, 'autojump.bash'), dryrun)
rm(os.path.join(etc_dir, 'autojump.fish'), dryrun)
rm(os.path.join(etc_dir, 'autojump.zsh'), dryrun)
rm(os.path.join(zshshare_dir, '_j'), dryrun)
rmdir(icon_dir, dryrun)
rm(os.path.join(doc_dir, 'autojump.1'), dryrun)
@ -113,7 +127,7 @@ def remove_user_data(dryrun=False):
'Library',
'autojump')
elif platform.system() == 'Windows':
data_home = os.path.join(
data_home = os.path.join(
os.getenv('APPDATA'),
'autojump')
else:
@ -131,14 +145,16 @@ def remove_user_data(dryrun=False):
def remove_user_installation(dryrun=False):
default_destdir = os.path.join(os.path.expanduser("~"), '.autojump')
clink_dir = os.path.join(os.getenv("LOCALAPPDATA"),'clink')
if platform.system() == 'Windows':
default_destdir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'autojump')
clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink')
else:
default_destdir = os.path.join(os.path.expanduser("~"), '.autojump')
if os.path.exists(default_destdir):
print("\nFound user installation...")
rmdir(default_destdir, dryrun)
if platform.system() == 'Windows':
if os.path.exists(clink_dir):
rm(os.path.join(clink_dir,'autojump.lua'), dryrun)
if platform.system() == 'Windows' and os.path.exists(clink_dir):
rm(os.path.join(clink_dir, 'autojump.lua'), dryrun)
def rm(path, dryrun):