diff --git a/AUTHORS b/AUTHORS index 2787fd7..56e6a69 100644 --- a/AUTHORS +++ b/AUTHORS @@ -25,3 +25,4 @@ made autojump that much better (in no particular order): Jui-Shan Liang Pierre Gueth Alexander Bolodurin + Azriel Hoh diff --git a/bin/autojump.bash b/bin/autojump.bash index 379e529..008deb9 100644 --- a/bin/autojump.bash +++ b/bin/autojump.bash @@ -1,8 +1,14 @@ export AUTOJUMP_SOURCED=1 +if [[ "${OS}" =~ Windows ]]; then + local_autojump_dir="${LOCALAPPDATA}/autojump" +else + local_autojump_dir="~/.autojump" +fi + # set user installation paths -if [[ -d ~/.autojump/ ]]; then - export PATH=~/.autojump/bin:"${PATH}" +if [[ -d "${local_autojump_dir}" ]]; then + export PATH="${local_autojump_dir}":"${PATH}" fi @@ -106,6 +112,9 @@ jo() { cygwin) cygstart "" $(cygpath -w -a ${output}) ;; + msys) + start "${output}" + ;; *) echo "Unknown operating system: ${OSTYPE}." 1>&2 ;; diff --git a/bin/autojump.sh b/bin/autojump.sh index 0ddff47..7e01006 100644 --- a/bin/autojump.sh +++ b/bin/autojump.sh @@ -12,13 +12,20 @@ else shell=$(echo ${SHELL} | awk -F/ '{ print $NF }') fi +# Support git-bash (msysgit) +if [[ "${OS}" =~ Windows ]]; then + local_autojump_dir="${LOCALAPPDATA}/autojump" +else + local_autojump_dir="~/.autojump" +fi + # prevent circular loop for sh shells if [ "${shell}" = "sh" ]; then return 0 # check local install -elif [ -s ~/.autojump/share/autojump/autojump.${shell} ]; then - source ~/.autojump/share/autojump/autojump.${shell} +elif [ -s "${local_autojump_dir}/share/autojump/autojump.${shell}" ]; then + source "${local_autojump_dir}/share/autojump/autojump.${shell}" # check global install elif [ -s /usr/local/share/autojump/autojump.${shell} ]; then diff --git a/bin/autojump_match.py b/bin/autojump_match.py index 54bf411..05dfb33 100644 --- a/bin/autojump_match.py +++ b/bin/autojump_match.py @@ -75,9 +75,12 @@ def match_consecutive(needles, haystack, ignore_case=False): (path='/foo/baz', weight=10), ] """ - regex_no_sep = '[^' + os.sep + ']*' + + # We explicitly use forward slash instead of os.sep as this works across unix platforms as well as msysgit in Windows + separator = '/' + regex_no_sep = '[^' + separator + ']*' regex_no_sep_end = regex_no_sep + '$' - regex_one_sep = regex_no_sep + os.sep + regex_no_sep + regex_one_sep = regex_no_sep + separator + regex_no_sep regex_needle = regex_one_sep.join(imap(re.escape, needles)) + regex_no_sep_end regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE found = lambda entry: re.search( diff --git a/install.py b/install.py index b02abf8..aad1448 100755 --- a/install.py +++ b/install.py @@ -19,10 +19,28 @@ def cp(src, dest, dryrun=False): shutil.copy(src, dest) +def in_bash(): + return get_shell().startswith('bash') + + +def in_msysgit(): + return platform.system() == 'Windows' and in_bash() + + def get_shell(): return os.path.basename(os.getenv('SHELL', '')) +def unixify(path): + if in_msysgit(): + idx = path.find(':') + if idx == -1: + return path + drive_letter = path[0:idx].lower() + path = '/' + drive_letter + path[idx + 1:].replace('\\', '/') + return path + + def mkdir(path, dryrun=False): print('creating directory:', path) if not dryrun and not os.path.exists(path): @@ -156,7 +174,7 @@ def parse_arguments(): # noqa def show_post_installation_message(etc_dir, share_dir, bin_dir): - if platform.system() == 'Windows': + if platform.system() == 'Windows' and not in_bash(): print('\nPlease manually add %s to your user path' % bin_dir) else: if get_shell() == 'fish': @@ -164,7 +182,7 @@ def show_post_installation_message(etc_dir, share_dir, bin_dir): 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 + aj_shell = '%s/autojump.sh' % unixify(etc_dir) source_msg = '[[ -s %s ]] && source %s' % (aj_shell, aj_shell) if platform.system() == 'Darwin' and get_shell() == 'bash': @@ -205,7 +223,7 @@ def main(args): cp('./bin/icon.png', share_dir, args.dryrun) cp('./docs/autojump.1', doc_dir, args.dryrun) - if platform.system() == 'Windows': + if platform.system() == 'Windows' and not in_bash(): cp('./bin/autojump.lua', args.clinkdir, args.dryrun) cp('./bin/autojump.bat', bin_dir, args.dryrun) cp('./bin/j.bat', bin_dir, args.dryrun) diff --git a/uninstall.py b/uninstall.py index 4bd7042..436c77f 100755 --- a/uninstall.py +++ b/uninstall.py @@ -11,6 +11,14 @@ sys.path.append('bin') from autojump_argparse import ArgumentParser # noqa +def get_shell(): + return os.path.basename(os.getenv('SHELL', '')) + + +def in_bash(): + return get_shell == 'bash' + + def is_empty_dir(path): """ Checks if any files are present within a directory and all sub-directories. @@ -72,7 +80,7 @@ def remove_custom_installation(args, dryrun=False): rm(os.path.join(bin_dir, 'autojump_data.py'), dryrun) rm(os.path.join(bin_dir, 'autojump_utils.py'), dryrun) rm(os.path.join(bin_dir, 'autojump_argparse.py'), dryrun) - if platform.system() == 'Windows': + if platform.system() == 'Windows' and not in_bash(): if os.path.exists(args.clinkdir): rm(os.path.join(args.clinkdir, 'autojump.lua'), dryrun) rm(os.path.join(bin_dir, 'autojump.bat'), dryrun)