mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
Use fish shell's autoloading functions for j command
Fish shell allows users to put function files in a directory which are loaded as command line commands during login See https://fishshell.com/docs/current/tutorial.html#tut_autoload for more - Add an option to install autojump.fish to a user's fish function directory (typically ~/.config/fish/functions) - During system install, copy the autojump.fish function file to /usr/share/fish/vendor_functions.d, the system fish function directory - On a non-system install, print instructions to add the autojump's fish function directory to the user's fish function path
This commit is contained in:
parent
865476ed56
commit
0dc718d81b
22
install.py
22
install.py
@ -64,9 +64,11 @@ def parse_arguments(): # noqa
|
|||||||
'.autojump')
|
'.autojump')
|
||||||
default_user_prefix = ''
|
default_user_prefix = ''
|
||||||
default_user_zshshare = 'functions'
|
default_user_zshshare = 'functions'
|
||||||
|
default_user_fishfunc = 'fish_functions'
|
||||||
default_system_destdir = '/'
|
default_system_destdir = '/'
|
||||||
default_system_prefix = '/usr/local'
|
default_system_prefix = '/usr/local'
|
||||||
default_system_zshshare = '/usr/share/zsh/site-functions'
|
default_system_zshshare = '/usr/share/zsh/site-functions'
|
||||||
|
default_system_fishfunc = '/usr/share/fish/vendor_functions.d'
|
||||||
default_clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink')
|
default_clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink')
|
||||||
|
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
@ -87,6 +89,9 @@ def parse_arguments(): # noqa
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-z', '--zshshare', metavar='DIR', default=default_user_zshshare,
|
'-z', '--zshshare', metavar='DIR', default=default_user_zshshare,
|
||||||
help='set zsh share destination to DIR')
|
help='set zsh share destination to DIR')
|
||||||
|
parser.add_argument(
|
||||||
|
'-i', '--fishfunc', metavar='DIR', default=default_user_fishfunc,
|
||||||
|
help='set fish function destination to DIR')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--clinkdir', metavar='DIR', default=default_clink_dir,
|
'-c', '--clinkdir', metavar='DIR', default=default_clink_dir,
|
||||||
help='set clink directory location to DIR (Windows only)')
|
help='set clink directory location to DIR (Windows only)')
|
||||||
@ -118,7 +123,8 @@ def parse_arguments(): # noqa
|
|||||||
|
|
||||||
if args.destdir != default_user_destdir \
|
if args.destdir != default_user_destdir \
|
||||||
or args.prefix != default_user_prefix \
|
or args.prefix != default_user_prefix \
|
||||||
or args.zshshare != default_user_zshshare:
|
or args.zshshare != default_user_zshshare \
|
||||||
|
or args.fishfunc != default_user_fishfunc:
|
||||||
args.custom_install = True
|
args.custom_install = True
|
||||||
else:
|
else:
|
||||||
args.custom_install = False
|
args.custom_install = False
|
||||||
@ -132,17 +138,17 @@ def parse_arguments(): # noqa
|
|||||||
args.destdir = default_system_destdir
|
args.destdir = default_system_destdir
|
||||||
args.prefix = default_system_prefix
|
args.prefix = default_system_prefix
|
||||||
args.zshshare = default_system_zshshare
|
args.zshshare = default_system_zshshare
|
||||||
|
args.fishfunc = default_system_fishfunc
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def show_post_installation_message(etc_dir, share_dir, bin_dir):
|
def show_post_installation_message(args, etc_dir, share_dir, bin_dir, fishfunc_dir):
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
print('\nPlease manually add %s to your user path' % bin_dir)
|
print('\nPlease manually add %s to your user path' % bin_dir)
|
||||||
else:
|
else:
|
||||||
if get_shell() == 'fish':
|
if get_shell() == 'fish' and not args.system:
|
||||||
aj_shell = '%s/autojump.fish' % share_dir
|
source_msg = 'set fish_function_path %s $fish_function_path' % fishfunc_dir
|
||||||
source_msg = 'if test -f %s; . %s; end' % (aj_shell, aj_shell)
|
|
||||||
rcfile = '~/.config/fish/config.fish'
|
rcfile = '~/.config/fish/config.fish'
|
||||||
else:
|
else:
|
||||||
aj_shell = '%s/autojump.sh' % etc_dir
|
aj_shell = '%s/autojump.sh' % etc_dir
|
||||||
@ -172,6 +178,7 @@ def main(args):
|
|||||||
doc_dir = os.path.join(args.destdir, args.prefix, 'share', 'man', 'man1')
|
doc_dir = os.path.join(args.destdir, args.prefix, 'share', 'man', 'man1')
|
||||||
share_dir = os.path.join(args.destdir, args.prefix, 'share', 'autojump')
|
share_dir = os.path.join(args.destdir, args.prefix, 'share', 'autojump')
|
||||||
zshshare_dir = os.path.join(args.destdir, args.zshshare)
|
zshshare_dir = os.path.join(args.destdir, args.zshshare)
|
||||||
|
fishfunc_dir = os.path.join(args.destdir, args.fishfunc)
|
||||||
|
|
||||||
mkdir(bin_dir, args.dryrun)
|
mkdir(bin_dir, args.dryrun)
|
||||||
mkdir(doc_dir, args.dryrun)
|
mkdir(doc_dir, args.dryrun)
|
||||||
@ -200,17 +207,18 @@ def main(args):
|
|||||||
mkdir(etc_dir, args.dryrun)
|
mkdir(etc_dir, args.dryrun)
|
||||||
mkdir(share_dir, args.dryrun)
|
mkdir(share_dir, args.dryrun)
|
||||||
mkdir(zshshare_dir, args.dryrun)
|
mkdir(zshshare_dir, args.dryrun)
|
||||||
|
mkdir(fishfunc_dir, args.dryrun)
|
||||||
|
|
||||||
cp('./bin/autojump.sh', etc_dir, args.dryrun)
|
cp('./bin/autojump.sh', etc_dir, args.dryrun)
|
||||||
cp('./bin/autojump.bash', share_dir, args.dryrun)
|
cp('./bin/autojump.bash', share_dir, args.dryrun)
|
||||||
cp('./bin/autojump.fish', share_dir, args.dryrun)
|
cp('./bin/autojump.fish', fishfunc_dir+'/j.fish', args.dryrun)
|
||||||
cp('./bin/autojump.zsh', share_dir, args.dryrun)
|
cp('./bin/autojump.zsh', share_dir, args.dryrun)
|
||||||
cp('./bin/_j', zshshare_dir, args.dryrun)
|
cp('./bin/_j', zshshare_dir, args.dryrun)
|
||||||
|
|
||||||
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(args, etc_dir, share_dir, bin_dir, fishfunc_dir)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
10
uninstall.py
10
uninstall.py
@ -41,6 +41,9 @@ def parse_arguments():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-z', '--zshshare', metavar='DIR', default='functions',
|
'-z', '--zshshare', metavar='DIR', default='functions',
|
||||||
help='custom zshshare')
|
help='custom zshshare')
|
||||||
|
parser.add_argument(
|
||||||
|
'-i', '--fishfunc', metavar='DIR', default='fish_functions',
|
||||||
|
help='set fish function destination to DIR')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--clinkdir', metavar='DIR', default=default_clink_dir)
|
'-c', '--clinkdir', metavar='DIR', default=default_clink_dir)
|
||||||
|
|
||||||
@ -56,6 +59,7 @@ def remove_custom_installation(args, dryrun=False):
|
|||||||
etc_dir = os.path.join(args.destdir, 'etc', 'profile.d')
|
etc_dir = os.path.join(args.destdir, 'etc', 'profile.d')
|
||||||
share_dir = os.path.join(args.destdir, args.prefix, 'share', 'autojump')
|
share_dir = os.path.join(args.destdir, args.prefix, 'share', 'autojump')
|
||||||
zshshare_dir = os.path.join(args.destdir, args.zshshare)
|
zshshare_dir = os.path.join(args.destdir, args.zshshare)
|
||||||
|
fishfunc_dir = os.path.join(args.destdir, args.fishfunc)
|
||||||
|
|
||||||
if not os.path.exists(share_dir):
|
if not os.path.exists(share_dir):
|
||||||
return
|
return
|
||||||
@ -76,7 +80,7 @@ def remove_custom_installation(args, dryrun=False):
|
|||||||
else:
|
else:
|
||||||
rm(os.path.join(etc_dir, 'autojump.sh'), dryrun)
|
rm(os.path.join(etc_dir, 'autojump.sh'), dryrun)
|
||||||
rm(os.path.join(share_dir, 'autojump.bash'), dryrun)
|
rm(os.path.join(share_dir, 'autojump.bash'), dryrun)
|
||||||
rm(os.path.join(share_dir, 'autojump.fish'), dryrun)
|
rm(os.path.join(fishfunc_dir, 'j.fish'), dryrun)
|
||||||
rm(os.path.join(share_dir, 'autojump.tcsh'), dryrun)
|
rm(os.path.join(share_dir, 'autojump.tcsh'), dryrun)
|
||||||
rm(os.path.join(share_dir, 'autojump.zsh'), dryrun)
|
rm(os.path.join(share_dir, 'autojump.zsh'), dryrun)
|
||||||
rm(os.path.join(zshshare_dir, '_j'), dryrun)
|
rm(os.path.join(zshshare_dir, '_j'), dryrun)
|
||||||
@ -91,6 +95,7 @@ def remove_system_installation(dryrun=False):
|
|||||||
default_destdir = '/'
|
default_destdir = '/'
|
||||||
default_prefix = '/usr/local'
|
default_prefix = '/usr/local'
|
||||||
default_zshshare = '/usr/share/zsh/site-functions'
|
default_zshshare = '/usr/share/zsh/site-functions'
|
||||||
|
default_fishfunc = '/usr/share/fish/vendor_functions.d'
|
||||||
|
|
||||||
bin_dir = os.path.join(default_destdir, default_prefix, 'bin')
|
bin_dir = os.path.join(default_destdir, default_prefix, 'bin')
|
||||||
doc_dir = os.path.join(
|
doc_dir = os.path.join(
|
||||||
@ -106,6 +111,7 @@ def remove_system_installation(dryrun=False):
|
|||||||
'share',
|
'share',
|
||||||
'autojump')
|
'autojump')
|
||||||
zshshare_dir = os.path.join(default_destdir, default_zshshare)
|
zshshare_dir = os.path.join(default_destdir, default_zshshare)
|
||||||
|
fishfunc_dir = os.path.join(default_destdir, default_fishfunc)
|
||||||
|
|
||||||
if not os.path.exists(share_dir):
|
if not os.path.exists(share_dir):
|
||||||
return
|
return
|
||||||
@ -122,7 +128,7 @@ def remove_system_installation(dryrun=False):
|
|||||||
rm(os.path.join(bin_dir, 'autojump_utils.py'), dryrun)
|
rm(os.path.join(bin_dir, 'autojump_utils.py'), dryrun)
|
||||||
rm(os.path.join(etc_dir, 'autojump.sh'), dryrun)
|
rm(os.path.join(etc_dir, 'autojump.sh'), dryrun)
|
||||||
rm(os.path.join(share_dir, 'autojump.bash'), dryrun)
|
rm(os.path.join(share_dir, 'autojump.bash'), dryrun)
|
||||||
rm(os.path.join(share_dir, 'autojump.fish'), dryrun)
|
rm(os.path.join(fishfunc_dir, 'j.fish'), dryrun)
|
||||||
rm(os.path.join(share_dir, 'autojump.tcsh'), dryrun)
|
rm(os.path.join(share_dir, 'autojump.tcsh'), dryrun)
|
||||||
rm(os.path.join(share_dir, 'autojump.zsh'), dryrun)
|
rm(os.path.join(share_dir, 'autojump.zsh'), dryrun)
|
||||||
rm(os.path.join(zshshare_dir, '_j'), dryrun)
|
rm(os.path.join(zshshare_dir, '_j'), dryrun)
|
||||||
|
Loading…
Reference in New Issue
Block a user