|
|
@ -8,13 +8,13 @@ import shutil |
|
|
|
import sys |
|
|
|
|
|
|
|
sys.path.append('bin') |
|
|
|
from autojump_argparse import ArgumentParser |
|
|
|
from autojump_argparse import ArgumentParser # noqa |
|
|
|
|
|
|
|
SUPPORTED_SHELLS = ('bash', 'zsh', 'fish', 'tcsh') |
|
|
|
|
|
|
|
|
|
|
|
def cp(src, dest, dryrun=False): |
|
|
|
print("copying file: %s -> %s"; % (src, dest)) |
|
|
|
print('copying file: %s -> %s'; % (src, dest)) |
|
|
|
if not dryrun: |
|
|
|
shutil.copy(src, dest) |
|
|
|
|
|
|
@ -24,18 +24,18 @@ def get_shell(): |
|
|
|
|
|
|
|
|
|
|
|
def mkdir(path, dryrun=False): |
|
|
|
print("creating directory:";, path) |
|
|
|
print('creating directory:';, path) |
|
|
|
if not dryrun and not os.path.exists(path): |
|
|
|
os.makedirs(path) |
|
|
|
|
|
|
|
|
|
|
|
def modify_autojump_sh(etc_dir, share_dir, dryrun=False): |
|
|
|
"""Append custom installation path to autojump.sh""" |
|
|
|
custom_install = "\ |
|
|
|
custom_install = '\ |
|
|
|
\n# check custom install \ |
|
|
|
\nif [ -s %s/autojump.${shell} ]; then \ |
|
|
|
\n source %s/autojump.${shell} \ |
|
|
|
\nfi\n" % (share_dir, share_dir) |
|
|
|
\nfi\n' % (share_dir, share_dir) |
|
|
|
|
|
|
|
with open(os.path.join(etc_dir, 'autojump.sh'), 'a') as f: |
|
|
|
f.write(custom_install) |
|
|
@ -44,8 +44,8 @@ def modify_autojump_sh(etc_dir, share_dir, dryrun=False): |
|
|
|
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() |
|
|
@ -60,7 +60,7 @@ def parse_arguments(): # noqa |
|
|
|
'autojump') |
|
|
|
else: |
|
|
|
default_user_destdir = os.path.join( |
|
|
|
os.path.expanduser("~";), |
|
|
|
os.path.expanduser('~';), |
|
|
|
'.autojump') |
|
|
|
default_user_prefix = '' |
|
|
|
default_user_zshshare = 'functions' |
|
|
@ -73,10 +73,10 @@ def parse_arguments(): # noqa |
|
|
|
description='Installs autojump globally for root users, otherwise \ |
|
|
|
installs in current user\'s home directory.') |
|
|
|
parser.add_argument( |
|
|
|
'-n', '--dryrun', action="store_true";, default=False, |
|
|
|
'-n', '--dryrun', action='store_true';, default=False, |
|
|
|
help='simulate installation') |
|
|
|
parser.add_argument( |
|
|
|
'-f', '--force', action="store_true";, default=False, |
|
|
|
'-f', '--force', action='store_true';, default=False, |
|
|
|
help='skip root user, shell type, Python version checks') |
|
|
|
parser.add_argument( |
|
|
|
'-d', '--destdir', metavar='DIR', default=default_user_destdir, |
|
|
@ -91,28 +91,28 @@ def parse_arguments(): # noqa |
|
|
|
'-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, |
|
|
|
'-s', '--system', action='store_true';, default=False, |
|
|
|
help='install system wide for all users') |
|
|
|
|
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
if not args.force: |
|
|
|
if sys.version_info[0] == 2 and sys.version_info[1] < 6: |
|
|
|
print("Python v2.6+ or v3.0+ required.";, file=sys.stderr) |
|
|
|
print('Python v2.6+ or v3.0+ required.';, file=sys.stderr) |
|
|
|
sys.exit(1) |
|
|
|
if args.system: |
|
|
|
if platform.system() == 'Windows': |
|
|
|
print("System-wide installation is not supported on 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.";, |
|
|
|
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'), |
|
|
|
print('Unsupported shell: %s'; % os.getenv('SHELL'), |
|
|
|
file=sys.stderr) |
|
|
|
sys.exit(1) |
|
|
|
|
|
|
@ -125,7 +125,7 @@ def parse_arguments(): # noqa |
|
|
|
|
|
|
|
if args.system: |
|
|
|
if args.custom_install: |
|
|
|
print("Custom paths incompatible with --system option.";, |
|
|
|
print('Custom paths incompatible with --system option.';, |
|
|
|
file=sys.stderr) |
|
|
|
sys.exit(1) |
|
|
|
|
|
|
@ -138,34 +138,34 @@ def parse_arguments(): # noqa |
|
|
|
|
|
|
|
def show_post_installation_message(etc_dir, share_dir, bin_dir): |
|
|
|
if platform.system() == 'Windows': |
|
|
|
print("\nPlease manually add %s to your user path"; % bin_dir) |
|
|
|
print('\nPlease manually add %s to your user path'; % bin_dir) |
|
|
|
else: |
|
|
|
if get_shell() == 'fish': |
|
|
|
aj_shell = '%s/autojump.fish' % share_dir |
|
|
|
source_msg = "if test -f %s; . %s; end"; % (aj_shell, aj_shell) |
|
|
|
source_msg = 'if test -f %s; . %s; end'; % (aj_shell, aj_shell) |
|
|
|
rcfile = '~/.config/fish/config.fish' |
|
|
|
else: |
|
|
|
aj_shell = '%s/autojump.sh' % etc_dir |
|
|
|
source_msg = "[[ -s %s ]] && source %s"; % (aj_shell, aj_shell) |
|
|
|
source_msg = '[[ -s %s ]] && source %s'; % (aj_shell, aj_shell) |
|
|
|
|
|
|
|
if platform.system() == 'Darwin' and get_shell() == 'bash': |
|
|
|
rcfile = '~/.profile' |
|
|
|
else: |
|
|
|
rcfile = '~/.%src' % get_shell() |
|
|
|
|
|
|
|
print("\nPlease manually add the following line(s) to %s:"; % rcfile) |
|
|
|
print('\nPlease manually add the following line(s) to %s:'; % rcfile) |
|
|
|
print('\n\t' + source_msg) |
|
|
|
if get_shell() == 'zsh': |
|
|
|
print("\n\tautoload -U compinit && compinit -u";) |
|
|
|
print('\n\tautoload -U compinit && compinit -u';) |
|
|
|
|
|
|
|
print("\nPlease restart terminal(s) before running autojump.\n";) |
|
|
|
print('\nPlease restart terminal(s) before running autojump.\n';) |
|
|
|
|
|
|
|
|
|
|
|
def main(args): |
|
|
|
if args.dryrun: |
|
|
|
print("Installing autojump to %s (DRYRUN)..."; % args.destdir) |
|
|
|
print('Installing autojump to %s (DRYRUN)...'; % args.destdir) |
|
|
|
else: |
|
|
|
print("Installing autojump to %s ..."; % args.destdir) |
|
|
|
print('Installing autojump to %s ...'; % args.destdir) |
|
|
|
|
|
|
|
bin_dir = os.path.join(args.destdir, args.prefix, 'bin') |
|
|
|
etc_dir = os.path.join(args.destdir, 'etc', 'profile.d') |
|
|
@ -212,5 +212,5 @@ def main(args): |
|
|
|
show_post_installation_message(etc_dir, share_dir, bin_dir) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__";: |
|
|
|
if __name__ == '__main__';: |
|
|
|
sys.exit(main(parse_arguments())) |