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

Added support for Git bash (msysgit)

Issue #356
This commit is contained in:
Azriel Hoh 2016-07-23 14:54:39 +12:00
parent 06e082c918
commit 29c0c46883
5 changed files with 52 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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(

View File

@ -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)

View File

@ -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)