From 29c0c46883106b9844f2f1ec4037988f3cac43bc Mon Sep 17 00:00:00 2001 From: Azriel Hoh Date: Sat, 23 Jul 2016 14:54:39 +1200 Subject: [PATCH 1/4] Added support for Git bash (msysgit) Issue #356 --- bin/autojump.bash | 10 ++++++++-- bin/autojump.sh | 11 +++++++++-- bin/autojump_match.py | 7 +++++-- install.py | 24 +++++++++++++++++++++--- uninstall.py | 10 +++++++++- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/bin/autojump.bash b/bin/autojump.bash index 379e529..2198708 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 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 8747b90..39e092d 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 a44fecc..76ffb80 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() == '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 3627245..e9ea718 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) From 6dd21196014d6207e5e158cf5fccb0ad511f9a15 Mon Sep 17 00:00:00 2001 From: Azriel Hoh Date: Sat, 23 Jul 2016 14:55:03 +1200 Subject: [PATCH 2/4] Added Azriel to authors list --- AUTHORS | 1 + 1 file changed, 1 insertion(+) 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 From 73d242582a3730e5e496cfbb16863e0db21e9606 Mon Sep 17 00:00:00 2001 From: Niklas Bergius Date: Tue, 3 Sep 2019 16:53:53 +0200 Subject: [PATCH 3/4] Recognizing bash.exe as bash. --- install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.py b/install.py index 76ffb80..76f235d 100755 --- a/install.py +++ b/install.py @@ -20,7 +20,7 @@ def cp(src, dest, dryrun=False): def in_bash(): - return get_shell() == 'bash' + return get_shell().startswith('bash') def in_msysgit(): From 40afedd2dd87b0b985f158a4b485145d64a2ae4c Mon Sep 17 00:00:00 2001 From: Niklas Bergius Date: Tue, 3 Sep 2019 16:54:41 +0200 Subject: [PATCH 4/4] Opening directory in Explorer when using Git Bash. --- bin/autojump.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/autojump.bash b/bin/autojump.bash index 2198708..008deb9 100644 --- a/bin/autojump.bash +++ b/bin/autojump.bash @@ -112,6 +112,9 @@ jo() { cygwin) cygstart "" $(cygpath -w -a ${output}) ;; + msys) + start "${output}" + ;; *) echo "Unknown operating system: ${OSTYPE}." 1>&2 ;;