From 53eeed8a993ac2cd234f11021a5a7d8e1fe3eb53 Mon Sep 17 00:00:00 2001 From: Michael Lawson Date: Sun, 12 Jan 2014 19:34:28 +0000 Subject: [PATCH 1/6] initial windows support --- bin/autojump | 12 ++++-- bin/autojump.bat | 2 + bin/autojump.lua | 8 ++++ bin/j.bat | 15 ++++++++ bin/jc.bat | 8 ++++ bin/jco.bat | 8 ++++ bin/jo.bat | 15 ++++++++ install.py | 96 ++++++++++++++++++++++++++++-------------------- uninstall.py | 9 +++++ 9 files changed, 130 insertions(+), 43 deletions(-) create mode 100644 bin/autojump.bat create mode 100644 bin/autojump.lua create mode 100644 bin/j.bat create mode 100644 bin/jc.bat create mode 100644 bin/jco.bat create mode 100644 bin/jo.bat diff --git a/bin/autojump b/bin/autojump index df716c8..119f635 100755 --- a/bin/autojump +++ b/bin/autojump @@ -50,6 +50,7 @@ from autojump_utils import get_tab_entry_info from autojump_utils import get_pwd from autojump_utils import has_uppercase from autojump_utils import is_osx +from autojump_utils import is_windows from autojump_utils import last from autojump_utils import print_entry from autojump_utils import print_local @@ -72,6 +73,10 @@ def set_defaults(): os.path.expanduser('~'), 'Library', 'autojump') + elif is_windows(): + data_home = os.path.join( + os.getenv('LOCALAPPDATA'), + 'autojump') else: data_home = os.getenv( 'XDG_DATA_HOME', @@ -258,13 +263,13 @@ def match_consecutive(needles, haystack, ignore_case=False): (path="/moo/foo/baz", weight=10), (path="/foo/baz", weight=10)] """ - regex_no_sep = '[^' + os.sep + ']*' - regex_one_sep = regex_no_sep + os.sep + regex_no_sep + sep = os.sep.encode('string-escape') + regex_no_sep = '[^' + sep + ']*' + regex_one_sep = regex_no_sep + sep + regex_no_sep regex_no_sep_end = regex_no_sep + '$' # can't use compiled regex because of flags regex_needle = regex_one_sep.join(needles) + regex_no_sep_end regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE - found = lambda entry: re.search( regex_needle, entry.path, @@ -336,7 +341,6 @@ def print_stats(data, data_path): def main(args): # noqa config = set_defaults() - # all arguments are mutually exclusive if args.add: save(config, first(add_path(load(config), args.add))) diff --git a/bin/autojump.bat b/bin/autojump.bat new file mode 100644 index 0000000..a9e359a --- /dev/null +++ b/bin/autojump.bat @@ -0,0 +1,2 @@ +@echo off +python %~dp0\autojump %* \ No newline at end of file diff --git a/bin/autojump.lua b/bin/autojump.lua new file mode 100644 index 0000000..1f3f869 --- /dev/null +++ b/bin/autojump.lua @@ -0,0 +1,8 @@ +local HOME = clink.get_env("USERPROFILE") .."\\" +local AUTOJUMP_BIN = HOME .. ".autojump\\bin\\autojump" + +function autojump_add_to_database() + os.execute("python " .. AUTOJUMP_BIN .. " --add " .. clink.get_cwd()) +end + +clink.prompt.register_filter(autojump_add_to_database, 99) diff --git a/bin/j.bat b/bin/j.bat new file mode 100644 index 0000000..602344c --- /dev/null +++ b/bin/j.bat @@ -0,0 +1,15 @@ +@echo off + +echo %*|>nul findstr /rx \-.* +if ERRORLEVEL 1 ( + for /f %%G in ('python %~dp0\autojump %*') do set new_path=%%G + if exist %new_path%/nul ( + cd %new_path% + ) else ( + echo autojump: directory %* not found + echo try `autojump --help` for more information + ) + echo %new_path% +) else ( + python %~dp0\autojump %* +) \ No newline at end of file diff --git a/bin/jc.bat b/bin/jc.bat new file mode 100644 index 0000000..f0cc8db --- /dev/null +++ b/bin/jc.bat @@ -0,0 +1,8 @@ +@echo off + +echo %*|>nul findstr /rx \-.* +if ERRORLEVEL 1 ( + %~dp0\j.bat %cd% %* +) else ( + python %~dp0\autojump %* +) \ No newline at end of file diff --git a/bin/jco.bat b/bin/jco.bat new file mode 100644 index 0000000..efd42ff --- /dev/null +++ b/bin/jco.bat @@ -0,0 +1,8 @@ +@echo off + +echo %*|>nul findstr /rx \-.* +if ERRORLEVEL 1 ( + %~dp0\jc.bat %cd% %* +) else ( + python %~dp0\autojump %* +) \ No newline at end of file diff --git a/bin/jo.bat b/bin/jo.bat new file mode 100644 index 0000000..f952d1f --- /dev/null +++ b/bin/jo.bat @@ -0,0 +1,15 @@ +@echo off + +echo %*|>nul findstr /rx \-.* +if ERRORLEVEL 1 ( + for /f %%G in ('python %~dp0\autojump %*') do set new_path=%%G + if exist %new_path%/nul ( + start %new_path% + ) else ( + echo autojump: directory %* not found + echo try `autojump --help` for more information + ) + echo %new_path% +) else ( + python %~dp0\autojump %* +) \ No newline at end of file diff --git a/install.py b/install.py index a152e1a..ac5b324 100755 --- a/install.py +++ b/install.py @@ -78,16 +78,21 @@ 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 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) + 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: + print("System-wide installation is not supported on Windows.", + file=sys.stderr) + sys.exit(1) if args.destdir != default_user_destdir \ or args.prefix != default_user_prefix \ @@ -109,26 +114,29 @@ def parse_arguments(): return args -def print_post_installation_message(etc_dir): - if get_shell() == 'fish': - aj_shell = '%s/autojump.fish' % etc_dir - source_msg = "if test -f %s; . %s; end" % (aj_shell, aj_shell) +def print_post_installation_message(etc_dir, bin_dir): + if platform.system() != 'Windows': + if get_shell() == 'fish': + aj_shell = '%s/autojump.fish' % etc_dir + source_msg = "if test -f %s; . %s; end" % (aj_shell, aj_shell) - # TODO(ting|2013-12-31): check config.fish location on OSX - rcfile = '~/.config/fish/config.fish' - else: - aj_shell = '%s/autojump.sh' % etc_dir - source_msg = "[[ -s %s ]] && source %s" % (aj_shell, aj_shell) - - if platform.system() == 'Darwin' and get_shell() == 'bash': - rcfile = '~/.profile' + # TODO(ting|2013-12-31): check config.fish location on OSX + rcfile = '~/.config/fish/config.fish' else: - rcfile = '~/.%src' % get_shell() - - 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") + aj_shell = '%s/autojump.sh' % etc_dir + 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('\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") @@ -139,10 +147,11 @@ def main(args): 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') - doc_dir = os.path.join(args.destdir, args.prefix, 'share/man/man1') - icon_dir = os.path.join(args.destdir, args.prefix, 'share/autojump') + etc_dir = os.path.join(args.destdir, 'etc', 'profile.d') + 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) @@ -154,18 +163,27 @@ def main(args): 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) - cp('./bin/autojump.sh', etc_dir, args.dryrun) - cp('./bin/autojump.bash', etc_dir, args.dryrun) - cp('./bin/autojump.fish', etc_dir, args.dryrun) - cp('./bin/autojump.zsh', etc_dir, args.dryrun) - cp('./bin/_j', zshshare_dir, args.dryrun) + if platform.system() != 'Windows': + cp('./bin/autojump.sh', etc_dir, args.dryrun) + cp('./bin/autojump.bash', etc_dir, args.dryrun) + cp('./bin/autojump.fish', etc_dir, args.dryrun) + cp('./bin/autojump.zsh', etc_dir, args.dryrun) + cp('./bin/_j', zshshare_dir, args.dryrun) + + 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) - if args.custom_install: - modify_autojump_sh(etc_dir, args.dryrun) - print_post_installation_message(etc_dir) + print_post_installation_message(etc_dir, bin_dir) if __name__ == "__main__": sys.exit(main(parse_arguments())) diff --git a/uninstall.py b/uninstall.py index 5430479..d8e9bfc 100755 --- a/uninstall.py +++ b/uninstall.py @@ -8,6 +8,7 @@ import platform import shutil import sys +sys.path.append('bin') from autojump_argparse import ArgumentParser @@ -111,6 +112,10 @@ def remove_user_data(dryrun=False): os.path.expanduser('~'), 'Library', 'autojump') + elif platform.system() == 'Windows': + data_home = os.path.join( + os.getenv('APPDATA'), + 'autojump') else: data_home = os.getenv( 'XDG_DATA_HOME', @@ -127,9 +132,13 @@ 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 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) def rm(path, dryrun): From 1d13c0d4aef91740f0c406a294bcee3c24010138 Mon Sep 17 00:00:00 2001 From: Michael Lawson Date: Mon, 13 Jan 2014 19:04:39 +0000 Subject: [PATCH 2/6] fixed batch variable handling --- bin/j.bat | 14 ++++++++++---- bin/jo.bat | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/bin/j.bat b/bin/j.bat index 602344c..77925c9 100644 --- a/bin/j.bat +++ b/bin/j.bat @@ -1,15 +1,21 @@ @echo off +setlocal EnableDelayedExpansion echo %*|>nul findstr /rx \-.* if ERRORLEVEL 1 ( - for /f %%G in ('python %~dp0\autojump %*') do set new_path=%%G - if exist %new_path%/nul ( - cd %new_path% + for /f %%i in ('python %~dp0\autojump %*') do set new_path=%%i + if exist !new_path!\nul ( + echo !new_path! + pushd !new_path! + REM endlocal is necessary so that we can change directory for outside of this script + REM but will automatically popd. We mush pushd twice to work around this. + pushd !new_path! + endlocal + popd ) else ( echo autojump: directory %* not found echo try `autojump --help` for more information ) - echo %new_path% ) else ( python %~dp0\autojump %* ) \ No newline at end of file diff --git a/bin/jo.bat b/bin/jo.bat index f952d1f..1bb2485 100644 --- a/bin/jo.bat +++ b/bin/jo.bat @@ -1,15 +1,15 @@ @echo off +setlocal EnableDelayedExpansion echo %*|>nul findstr /rx \-.* if ERRORLEVEL 1 ( - for /f %%G in ('python %~dp0\autojump %*') do set new_path=%%G - if exist %new_path%/nul ( - start %new_path% + for /f %%i in ('python %~dp0\autojump %*') do set new_path=%%i + if exist !new_path!\nul ( + start !new_path! ) else ( echo autojump: directory %* not found echo try `autojump --help` for more information ) - echo %new_path% ) else ( python %~dp0\autojump %* ) \ No newline at end of file From 19f09e5cb00478f44e02d744644ba5682ae6619c Mon Sep 17 00:00:00 2001 From: Michael Lawson Date: Mon, 13 Jan 2014 19:13:36 +0000 Subject: [PATCH 3/6] added note about windows to readme --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d876c1e..3ab24ec 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ INSTALLATION ### REQUIREMENTS - Python v2.6+ -- Bash v4.0+, zsh, or fish +- Bash v4.0+, zsh, fish or clink (Windows) ### AUTOMATIC @@ -106,6 +106,12 @@ Run the installation script and follow on screen instructions. cd autojump ./install.py or ./uinstall.py +## Windows + +Windows support is enabled by [clink](https://code.google.com/p/clink/) which should be installed prior to installing autojump. + +Completion support on windows has not yet been added. + KNOWN ISSUES ------------ From de939863be433969083446bc9ec95f5b81af0a16 Mon Sep 17 00:00:00 2001 From: Michael Lawson Date: Mon, 13 Jan 2014 19:25:05 +0000 Subject: [PATCH 4/6] ensure batch files are crlf --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e31770e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Ensure batch files are crlf +*.bat text eol=crlf \ No newline at end of file From 7a756aaa4e1a30abb30a3869293ca1008e732607 Mon Sep 17 00:00:00 2001 From: Michael Lawson Date: Wed, 15 Jan 2014 13:05:45 +0000 Subject: [PATCH 5/6] add completion support --- bin/autojump.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bin/autojump.lua b/bin/autojump.lua index 1f3f869..91d425d 100644 --- a/bin/autojump.lua +++ b/bin/autojump.lua @@ -6,3 +6,15 @@ function autojump_add_to_database() end clink.prompt.register_filter(autojump_add_to_database, 99) + +function autojump_completion(word) + for line in io.popen("python " .. AUTOJUMP_BIN .. " --complete " .. word):lines() do + clink.add_match(line) + end + return {} +end + +local autojump_parser = clink.arg.new_parser() +autojump_parser:set_arguments({ autojump_completion }) + +clink.arg.register_parser("j", autojump_parser) \ No newline at end of file From ff9376cb93a52de5b155a54f791cbd24fafacc5b Mon Sep 17 00:00:00 2001 From: Michael Lawson Date: Thu, 16 Jan 2014 11:39:17 +0000 Subject: [PATCH 6/6] cleanup, add custom installation support, change default windows install directory --- bin/autojump | 4 +-- bin/autojump.lua | 5 ++-- install.py | 75 ++++++++++++++++++++++++++++++------------------ uninstall.py | 38 +++++++++++++++++------- 4 files changed, 78 insertions(+), 44 deletions(-) diff --git a/bin/autojump b/bin/autojump index 119f635..562620d 100755 --- a/bin/autojump +++ b/bin/autojump @@ -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 + '$' diff --git a/bin/autojump.lua b/bin/autojump.lua index 91d425d..37422e8 100644 --- a/bin/autojump.lua +++ b/bin/autojump.lua @@ -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) diff --git a/install.py b/install.py index ac5b324..31db07a 100755 --- a/install.py +++ b/install.py @@ -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'), + if args.system: + if platform.system() == 'Windows': + print("System-wide installation is not supported on Windows.", file=sys.stderr) sys.exit(1) - - if args.system and os.geteuid() != 0: + elif os.geteuid() != 0: print("Please rerun as root for system-wide installation.", file=sys.stderr) sys.exit(1) - else: - if args.system: - print("System-wide installation is not supported on Windows.", - 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) diff --git a/uninstall.py b/uninstall.py index d8e9bfc..456a5ce 100755 --- a/uninstall.py +++ b/uninstall.py @@ -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):