mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
initial windows support
This commit is contained in:
parent
09d8992289
commit
53eeed8a99
12
bin/autojump
12
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)))
|
||||
|
2
bin/autojump.bat
Normal file
2
bin/autojump.bat
Normal file
@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
python %~dp0\autojump %*
|
8
bin/autojump.lua
Normal file
8
bin/autojump.lua
Normal file
@ -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)
|
15
bin/j.bat
Normal file
15
bin/j.bat
Normal file
@ -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 %*
|
||||
)
|
8
bin/jc.bat
Normal file
8
bin/jc.bat
Normal file
@ -0,0 +1,8 @@
|
||||
@echo off
|
||||
|
||||
echo %*|>nul findstr /rx \-.*
|
||||
if ERRORLEVEL 1 (
|
||||
%~dp0\j.bat %cd% %*
|
||||
) else (
|
||||
python %~dp0\autojump %*
|
||||
)
|
8
bin/jco.bat
Normal file
8
bin/jco.bat
Normal file
@ -0,0 +1,8 @@
|
||||
@echo off
|
||||
|
||||
echo %*|>nul findstr /rx \-.*
|
||||
if ERRORLEVEL 1 (
|
||||
%~dp0\jc.bat %cd% %*
|
||||
) else (
|
||||
python %~dp0\autojump %*
|
||||
)
|
15
bin/jo.bat
Normal file
15
bin/jo.bat
Normal file
@ -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 %*
|
||||
)
|
34
install.py
34
install.py
@ -78,7 +78,7 @@ 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'),
|
||||
file=sys.stderr)
|
||||
@ -88,6 +88,11 @@ def parse_arguments():
|
||||
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,7 +114,8 @@ def parse_arguments():
|
||||
return args
|
||||
|
||||
|
||||
def print_post_installation_message(etc_dir):
|
||||
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)
|
||||
@ -129,6 +135,8 @@ def print_post_installation_message(etc_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")
|
||||
|
||||
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
|
||||
print_post_installation_message(etc_dir, bin_dir)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(parse_arguments()))
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user