mirror of
https://github.com/wting/autojump
synced 2025-12-05 06:01:59 +00:00
Merge d6e4cb4d76 into ee21082751
This commit is contained in:
commit
0009fa3703
36
install.py
36
install.py
@ -28,6 +28,35 @@ def mkdir(path, dryrun=False):
|
|||||||
if not dryrun and not os.path.exists(path):
|
if not dryrun and not os.path.exists(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
|
|
||||||
|
def mkdir(path, dryrun=False):
|
||||||
|
print('creating directory:', path)
|
||||||
|
if not dryrun and not os.path.exists(path):
|
||||||
|
os.makedirs(path)
|
||||||
|
|
||||||
|
def update_windows_path(bin_dir, dryrun=False):
|
||||||
|
"""Add bin directory to Windows user PATH if not present"""
|
||||||
|
if dryrun or platform.system() != 'Windows':
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
import winreg
|
||||||
|
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
|
||||||
|
try:
|
||||||
|
current_path = winreg.QueryValueEx(key, "Path")[0]
|
||||||
|
except FileNotFoundError:
|
||||||
|
current_path = ""
|
||||||
|
|
||||||
|
# Check if bin_dir is already in PATH
|
||||||
|
path_entries = [entry.strip() for entry in current_path.split(';') if entry.strip()]
|
||||||
|
normalized_bin_dir = os.path.normpath(str(bin_dir))
|
||||||
|
normalized_entries = [os.path.normpath(entry) for entry in path_entries]
|
||||||
|
|
||||||
|
if normalized_bin_dir not in normalized_entries:
|
||||||
|
new_path = current_path + ";" + str(bin_dir) if current_path else str(bin_dir)
|
||||||
|
winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_path)
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def modify_autojump_sh(etc_dir, share_dir, dryrun=False):
|
def modify_autojump_sh(etc_dir, share_dir, dryrun=False):
|
||||||
"""Append custom installation path to autojump.sh"""
|
"""Append custom installation path to autojump.sh"""
|
||||||
@ -157,7 +186,10 @@ def parse_arguments(): # noqa
|
|||||||
|
|
||||||
def show_post_installation_message(etc_dir, share_dir, bin_dir):
|
def show_post_installation_message(etc_dir, share_dir, bin_dir):
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
print('\nPlease manually add %s to your user path' % bin_dir)
|
if update_windows_path(bin_dir, dryrun):
|
||||||
|
print('\nAutojump has been added to your user path')
|
||||||
|
else:
|
||||||
|
print('\nPlease manually add %s to your user path' % bin_dir)
|
||||||
else:
|
else:
|
||||||
if get_shell() == 'fish':
|
if get_shell() == 'fish':
|
||||||
aj_shell = '%s/autojump.fish' % share_dir
|
aj_shell = '%s/autojump.fish' % share_dir
|
||||||
@ -229,7 +261,7 @@ def main(args):
|
|||||||
if args.custom_install:
|
if args.custom_install:
|
||||||
modify_autojump_sh(etc_dir, share_dir, args.dryrun)
|
modify_autojump_sh(etc_dir, share_dir, args.dryrun)
|
||||||
|
|
||||||
show_post_installation_message(etc_dir, share_dir, bin_dir)
|
show_post_installation_message(etc_dir, share_dir, bin_dir, args.dryrun)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user