mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
(Running pre-commit) Use Yelp-style indentation.
This commit is contained in:
parent
0e4d15ace6
commit
a0719f488e
91
bin/autojump
91
bin/autojump
@ -78,11 +78,13 @@ def set_defaults():
|
|||||||
data_home = os.path.join(
|
data_home = os.path.join(
|
||||||
os.path.expanduser('~'),
|
os.path.expanduser('~'),
|
||||||
'Library',
|
'Library',
|
||||||
'autojump')
|
'autojump',
|
||||||
|
)
|
||||||
elif is_windows():
|
elif is_windows():
|
||||||
data_home = os.path.join(
|
data_home = os.path.join(
|
||||||
os.getenv('APPDATA'),
|
os.getenv('APPDATA'),
|
||||||
'autojump')
|
'autojump',
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
data_home = os.getenv(
|
data_home = os.getenv(
|
||||||
'XDG_DATA_HOME',
|
'XDG_DATA_HOME',
|
||||||
@ -90,7 +92,9 @@ def set_defaults():
|
|||||||
os.path.expanduser('~'),
|
os.path.expanduser('~'),
|
||||||
'.local',
|
'.local',
|
||||||
'share',
|
'share',
|
||||||
'autojump'))
|
'autojump',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
config['data_path'] = os.path.join(data_home, 'autojump.txt')
|
config['data_path'] = os.path.join(data_home, 'autojump.txt')
|
||||||
config['backup_path'] = os.path.join(data_home, 'autojump.txt.bak')
|
config['backup_path'] = os.path.join(data_home, 'autojump.txt.bak')
|
||||||
@ -101,33 +105,42 @@ def set_defaults():
|
|||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
description='Automatically jump to directory passed as an argument.',
|
description='Automatically jump to directory passed as an argument.',
|
||||||
epilog='Please see autojump(1) man pages for full documentation.')
|
epilog='Please see autojump(1) man pages for full documentation.',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'directory', metavar='DIRECTORY', nargs='*', default='',
|
'directory', metavar='DIRECTORY', nargs='*', default='',
|
||||||
help='directory to jump to')
|
help='directory to jump to',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-a', '--add', metavar='DIRECTORY',
|
'-a', '--add', metavar='DIRECTORY',
|
||||||
help='add path')
|
help='add path',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-i', '--increase', metavar='WEIGHT', nargs='?', type=int,
|
'-i', '--increase', metavar='WEIGHT', nargs='?', type=int,
|
||||||
const=10, default=False,
|
const=10, default=False,
|
||||||
help='increase current directory weight')
|
help='increase current directory weight',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-d', '--decrease', metavar='WEIGHT', nargs='?', type=int,
|
'-d', '--decrease', metavar='WEIGHT', nargs='?', type=int,
|
||||||
const=15, default=False,
|
const=15, default=False,
|
||||||
help='decrease current directory weight')
|
help='decrease current directory weight',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--complete', action='store_true', default=False,
|
'--complete', action='store_true', default=False,
|
||||||
help='used for tab completion')
|
help='used for tab completion',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--purge', action='store_true', default=False,
|
'--purge', action='store_true', default=False,
|
||||||
help='remove non-existent paths from database')
|
help='remove non-existent paths from database',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-s', '--stat', action='store_true', default=False,
|
'-s', '--stat', action='store_true', default=False,
|
||||||
help='show database entries and their key weights')
|
help='show database entries and their key weights',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-v', '--version', action='version', version='%(prog)s v' +
|
'-v', '--version', action='version', version='%(prog)s v' +
|
||||||
VERSION, help='show version information')
|
VERSION, help='show version information',
|
||||||
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
@ -187,14 +200,17 @@ def find_matches(entries, needles, check_entries=True):
|
|||||||
data = sorted(
|
data = sorted(
|
||||||
entries,
|
entries,
|
||||||
key=attrgetter('weight', 'path'),
|
key=attrgetter('weight', 'path'),
|
||||||
reverse=True)
|
reverse=True,
|
||||||
|
)
|
||||||
|
|
||||||
return ifilter(
|
return ifilter(
|
||||||
lambda entry: not is_cwd(entry) and path_exists(entry),
|
lambda entry: not is_cwd(entry) and path_exists(entry),
|
||||||
chain(
|
chain(
|
||||||
match_consecutive(needles, data, ignore_case),
|
match_consecutive(needles, data, ignore_case),
|
||||||
match_fuzzy(needles, data, ignore_case),
|
match_fuzzy(needles, data, ignore_case),
|
||||||
match_anywhere(needles, data, ignore_case)))
|
match_anywhere(needles, data, ignore_case),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def handle_tab_completion(needle, entries):
|
def handle_tab_completion(needle, entries):
|
||||||
@ -206,24 +222,33 @@ def handle_tab_completion(needle, entries):
|
|||||||
get_ith_path = lambda i, iterable: last(take(i, iterable)).path
|
get_ith_path = lambda i, iterable: last(take(i, iterable)).path
|
||||||
print_local(get_ith_path(
|
print_local(get_ith_path(
|
||||||
tab_index,
|
tab_index,
|
||||||
find_matches(entries, [tab_needle], check_entries=False)))
|
find_matches(entries, [tab_needle], check_entries=False),
|
||||||
|
))
|
||||||
elif tab_needle:
|
elif tab_needle:
|
||||||
# found partial tab completion entry
|
# found partial tab completion entry
|
||||||
print_tab_menu(
|
print_tab_menu(
|
||||||
tab_needle,
|
tab_needle,
|
||||||
take(TAB_ENTRIES_COUNT, find_matches(
|
take(
|
||||||
entries,
|
TAB_ENTRIES_COUNT, find_matches(
|
||||||
[tab_needle],
|
entries,
|
||||||
check_entries=False)),
|
[tab_needle],
|
||||||
TAB_SEPARATOR)
|
check_entries=False,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TAB_SEPARATOR,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print_tab_menu(
|
print_tab_menu(
|
||||||
needle,
|
needle,
|
||||||
take(TAB_ENTRIES_COUNT, find_matches(
|
take(
|
||||||
entries,
|
TAB_ENTRIES_COUNT, find_matches(
|
||||||
[needle],
|
entries,
|
||||||
check_entries=False)),
|
[needle],
|
||||||
TAB_SEPARATOR)
|
check_entries=False,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TAB_SEPARATOR,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def purge_missing_paths(entries):
|
def purge_missing_paths(entries):
|
||||||
@ -242,7 +267,8 @@ def print_stats(data, data_path):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
print_local(
|
print_local(
|
||||||
'%.2f:\t current directory weight' % data.get(os.getcwdu(), 0))
|
'%.2f:\t current directory weight' % data.get(os.getcwdu(), 0),
|
||||||
|
)
|
||||||
except OSError:
|
except OSError:
|
||||||
# current directory no longer exists
|
# current directory no longer exists
|
||||||
pass
|
pass
|
||||||
@ -265,7 +291,8 @@ def main(args): # noqa
|
|||||||
elif args.complete:
|
elif args.complete:
|
||||||
handle_tab_completion(
|
handle_tab_completion(
|
||||||
needle=first(chain(sanitize(args.directory), [''])),
|
needle=first(chain(sanitize(args.directory), [''])),
|
||||||
entries=entriefy(load(config)))
|
entries=entriefy(load(config)),
|
||||||
|
)
|
||||||
elif args.decrease:
|
elif args.decrease:
|
||||||
data, entry = decrease_path(load(config), get_pwd(), args.decrease)
|
data, entry = decrease_path(load(config), get_pwd(), args.decrease)
|
||||||
save(config, data)
|
save(config, data)
|
||||||
@ -287,7 +314,8 @@ def main(args): # noqa
|
|||||||
print_local(first(chain(
|
print_local(first(chain(
|
||||||
imap(attrgetter('path'), find_matches(entries, [''])),
|
imap(attrgetter('path'), find_matches(entries, [''])),
|
||||||
# always return a path to calling shell functions
|
# always return a path to calling shell functions
|
||||||
['.'])))
|
['.'],
|
||||||
|
)))
|
||||||
else:
|
else:
|
||||||
entries = entriefy(load(config))
|
entries = entriefy(load(config))
|
||||||
needles = sanitize(args.directory)
|
needles = sanitize(args.directory)
|
||||||
@ -306,12 +334,15 @@ def main(args): # noqa
|
|||||||
print_local(
|
print_local(
|
||||||
get_ith_path(
|
get_ith_path(
|
||||||
tab_index,
|
tab_index,
|
||||||
find_matches(entries, [tab_needle])))
|
find_matches(entries, [tab_needle]),
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print_local(first(chain(
|
print_local(first(chain(
|
||||||
imap(attrgetter('path'), find_matches(entries, needles)),
|
imap(attrgetter('path'), find_matches(entries, needles)),
|
||||||
# always return a path to calling shell functions
|
# always return a path to calling shell functions
|
||||||
['.'])))
|
['.'],
|
||||||
|
)))
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -175,11 +175,13 @@ class HelpFormatter(object):
|
|||||||
provided by the class are considered an implementation detail.
|
provided by the class are considered an implementation detail.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
prog,
|
self,
|
||||||
indent_increment=2,
|
prog,
|
||||||
max_help_position=24,
|
indent_increment=2,
|
||||||
width=None):
|
max_help_position=24,
|
||||||
|
width=None,
|
||||||
|
):
|
||||||
|
|
||||||
# default setting for width
|
# default setting for width
|
||||||
if width is None:
|
if width is None:
|
||||||
@ -286,8 +288,10 @@ class HelpFormatter(object):
|
|||||||
# update the maximum item length
|
# update the maximum item length
|
||||||
invocation_length = max([len(s) for s in invocations])
|
invocation_length = max([len(s) for s in invocations])
|
||||||
action_length = invocation_length + self._current_indent
|
action_length = invocation_length + self._current_indent
|
||||||
self._action_max_length = max(self._action_max_length,
|
self._action_max_length = max(
|
||||||
action_length)
|
self._action_max_length,
|
||||||
|
action_length,
|
||||||
|
)
|
||||||
|
|
||||||
# add the item to the list
|
# add the item to the list
|
||||||
self._add_item(self._format_action, [action])
|
self._add_item(self._format_action, [action])
|
||||||
@ -508,8 +512,10 @@ class HelpFormatter(object):
|
|||||||
|
|
||||||
def _format_action(self, action):
|
def _format_action(self, action):
|
||||||
# determine the required width and the entry label
|
# determine the required width and the entry label
|
||||||
help_position = min(self._action_max_length + 2,
|
help_position = min(
|
||||||
self._max_help_position)
|
self._action_max_length + 2,
|
||||||
|
self._max_help_position,
|
||||||
|
)
|
||||||
help_width = self._width - help_position
|
help_width = self._width - help_position
|
||||||
action_width = help_position - self._current_indent - 2
|
action_width = help_position - self._current_indent - 2
|
||||||
action_header = self._format_action_invocation(action)
|
action_header = self._format_action_invocation(action)
|
||||||
@ -641,8 +647,10 @@ class HelpFormatter(object):
|
|||||||
|
|
||||||
def _fill_text(self, text, width, indent):
|
def _fill_text(self, text, width, indent):
|
||||||
text = self._whitespace_matcher.sub(' ', text).strip()
|
text = self._whitespace_matcher.sub(' ', text).strip()
|
||||||
return _textwrap.fill(text, width, initial_indent=indent,
|
return _textwrap.fill(
|
||||||
subsequent_indent=indent)
|
text, width, initial_indent=indent,
|
||||||
|
subsequent_indent=indent,
|
||||||
|
)
|
||||||
|
|
||||||
def _get_help_string(self, action):
|
def _get_help_string(self, action):
|
||||||
return action.help
|
return action.help
|
||||||
@ -724,8 +732,10 @@ class ArgumentError(Exception):
|
|||||||
format = '%(message)s'
|
format = '%(message)s'
|
||||||
else:
|
else:
|
||||||
format = 'argument %(argument_name)s: %(message)s'
|
format = 'argument %(argument_name)s: %(message)s'
|
||||||
return format % dict(message=self.message,
|
return format % dict(
|
||||||
argument_name=self.argument_name)
|
message=self.message,
|
||||||
|
argument_name=self.argument_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ArgumentTypeError(Exception):
|
class ArgumentTypeError(Exception):
|
||||||
@ -790,17 +800,19 @@ class Action(_AttributeHolder):
|
|||||||
help string. If None, the 'dest' value will be used as the name.
|
help string. If None, the 'dest' value will be used as the name.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
dest,
|
option_strings,
|
||||||
nargs=None,
|
dest,
|
||||||
const=None,
|
nargs=None,
|
||||||
default=None,
|
const=None,
|
||||||
type=None,
|
default=None,
|
||||||
choices=None,
|
type=None,
|
||||||
required=False,
|
choices=None,
|
||||||
help=None,
|
required=False,
|
||||||
metavar=None):
|
help=None,
|
||||||
|
metavar=None,
|
||||||
|
):
|
||||||
self.option_strings = option_strings
|
self.option_strings = option_strings
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.nargs = nargs
|
self.nargs = nargs
|
||||||
@ -832,21 +844,25 @@ class Action(_AttributeHolder):
|
|||||||
|
|
||||||
class _StoreAction(Action):
|
class _StoreAction(Action):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
dest,
|
option_strings,
|
||||||
nargs=None,
|
dest,
|
||||||
const=None,
|
nargs=None,
|
||||||
default=None,
|
const=None,
|
||||||
type=None,
|
default=None,
|
||||||
choices=None,
|
type=None,
|
||||||
required=False,
|
choices=None,
|
||||||
help=None,
|
required=False,
|
||||||
metavar=None):
|
help=None,
|
||||||
|
metavar=None,
|
||||||
|
):
|
||||||
if nargs == 0:
|
if nargs == 0:
|
||||||
raise ValueError('nargs for store actions must be > 0; if you '
|
raise ValueError(
|
||||||
'have nothing to store, actions such as store '
|
'nargs for store actions must be > 0; if you '
|
||||||
'true or store const may be more appropriate')
|
'have nothing to store, actions such as store '
|
||||||
|
'true or store const may be more appropriate',
|
||||||
|
)
|
||||||
if const is not None and nargs != OPTIONAL:
|
if const is not None and nargs != OPTIONAL:
|
||||||
raise ValueError('nargs must be %r to supply const' % OPTIONAL)
|
raise ValueError('nargs must be %r to supply const' % OPTIONAL)
|
||||||
super(_StoreAction, self).__init__(
|
super(_StoreAction, self).__init__(
|
||||||
@ -859,7 +875,8 @@ class _StoreAction(Action):
|
|||||||
choices=choices,
|
choices=choices,
|
||||||
required=required,
|
required=required,
|
||||||
help=help,
|
help=help,
|
||||||
metavar=metavar)
|
metavar=metavar,
|
||||||
|
)
|
||||||
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
setattr(namespace, self.dest, values)
|
setattr(namespace, self.dest, values)
|
||||||
@ -867,14 +884,16 @@ class _StoreAction(Action):
|
|||||||
|
|
||||||
class _StoreConstAction(Action):
|
class _StoreConstAction(Action):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
dest,
|
option_strings,
|
||||||
const,
|
dest,
|
||||||
default=None,
|
const,
|
||||||
required=False,
|
default=None,
|
||||||
help=None,
|
required=False,
|
||||||
metavar=None):
|
help=None,
|
||||||
|
metavar=None,
|
||||||
|
):
|
||||||
super(_StoreConstAction, self).__init__(
|
super(_StoreConstAction, self).__init__(
|
||||||
option_strings=option_strings,
|
option_strings=option_strings,
|
||||||
dest=dest,
|
dest=dest,
|
||||||
@ -882,7 +901,8 @@ class _StoreConstAction(Action):
|
|||||||
const=const,
|
const=const,
|
||||||
default=default,
|
default=default,
|
||||||
required=required,
|
required=required,
|
||||||
help=help)
|
help=help,
|
||||||
|
)
|
||||||
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
setattr(namespace, self.dest, self.const)
|
setattr(namespace, self.dest, self.const)
|
||||||
@ -890,55 +910,65 @@ class _StoreConstAction(Action):
|
|||||||
|
|
||||||
class _StoreTrueAction(_StoreConstAction):
|
class _StoreTrueAction(_StoreConstAction):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
dest,
|
option_strings,
|
||||||
default=False,
|
dest,
|
||||||
required=False,
|
default=False,
|
||||||
help=None):
|
required=False,
|
||||||
|
help=None,
|
||||||
|
):
|
||||||
super(_StoreTrueAction, self).__init__(
|
super(_StoreTrueAction, self).__init__(
|
||||||
option_strings=option_strings,
|
option_strings=option_strings,
|
||||||
dest=dest,
|
dest=dest,
|
||||||
const=True,
|
const=True,
|
||||||
default=default,
|
default=default,
|
||||||
required=required,
|
required=required,
|
||||||
help=help)
|
help=help,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class _StoreFalseAction(_StoreConstAction):
|
class _StoreFalseAction(_StoreConstAction):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
dest,
|
option_strings,
|
||||||
default=True,
|
dest,
|
||||||
required=False,
|
default=True,
|
||||||
help=None):
|
required=False,
|
||||||
|
help=None,
|
||||||
|
):
|
||||||
super(_StoreFalseAction, self).__init__(
|
super(_StoreFalseAction, self).__init__(
|
||||||
option_strings=option_strings,
|
option_strings=option_strings,
|
||||||
dest=dest,
|
dest=dest,
|
||||||
const=False,
|
const=False,
|
||||||
default=default,
|
default=default,
|
||||||
required=required,
|
required=required,
|
||||||
help=help)
|
help=help,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class _AppendAction(Action):
|
class _AppendAction(Action):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
dest,
|
option_strings,
|
||||||
nargs=None,
|
dest,
|
||||||
const=None,
|
nargs=None,
|
||||||
default=None,
|
const=None,
|
||||||
type=None,
|
default=None,
|
||||||
choices=None,
|
type=None,
|
||||||
required=False,
|
choices=None,
|
||||||
help=None,
|
required=False,
|
||||||
metavar=None):
|
help=None,
|
||||||
|
metavar=None,
|
||||||
|
):
|
||||||
if nargs == 0:
|
if nargs == 0:
|
||||||
raise ValueError('nargs for append actions must be > 0; if arg '
|
raise ValueError(
|
||||||
'strings are not supplying the value to append, '
|
'nargs for append actions must be > 0; if arg '
|
||||||
'the append const action may be more appropriate')
|
'strings are not supplying the value to append, '
|
||||||
|
'the append const action may be more appropriate',
|
||||||
|
)
|
||||||
if const is not None and nargs != OPTIONAL:
|
if const is not None and nargs != OPTIONAL:
|
||||||
raise ValueError('nargs must be %r to supply const' % OPTIONAL)
|
raise ValueError('nargs must be %r to supply const' % OPTIONAL)
|
||||||
super(_AppendAction, self).__init__(
|
super(_AppendAction, self).__init__(
|
||||||
@ -951,7 +981,8 @@ class _AppendAction(Action):
|
|||||||
choices=choices,
|
choices=choices,
|
||||||
required=required,
|
required=required,
|
||||||
help=help,
|
help=help,
|
||||||
metavar=metavar)
|
metavar=metavar,
|
||||||
|
)
|
||||||
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
items = _copy.copy(_ensure_value(namespace, self.dest, []))
|
items = _copy.copy(_ensure_value(namespace, self.dest, []))
|
||||||
@ -961,14 +992,16 @@ class _AppendAction(Action):
|
|||||||
|
|
||||||
class _AppendConstAction(Action):
|
class _AppendConstAction(Action):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
dest,
|
option_strings,
|
||||||
const,
|
dest,
|
||||||
default=None,
|
const,
|
||||||
required=False,
|
default=None,
|
||||||
help=None,
|
required=False,
|
||||||
metavar=None):
|
help=None,
|
||||||
|
metavar=None,
|
||||||
|
):
|
||||||
super(_AppendConstAction, self).__init__(
|
super(_AppendConstAction, self).__init__(
|
||||||
option_strings=option_strings,
|
option_strings=option_strings,
|
||||||
dest=dest,
|
dest=dest,
|
||||||
@ -977,7 +1010,8 @@ class _AppendConstAction(Action):
|
|||||||
default=default,
|
default=default,
|
||||||
required=required,
|
required=required,
|
||||||
help=help,
|
help=help,
|
||||||
metavar=metavar)
|
metavar=metavar,
|
||||||
|
)
|
||||||
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
items = _copy.copy(_ensure_value(namespace, self.dest, []))
|
items = _copy.copy(_ensure_value(namespace, self.dest, []))
|
||||||
@ -987,19 +1021,22 @@ class _AppendConstAction(Action):
|
|||||||
|
|
||||||
class _CountAction(Action):
|
class _CountAction(Action):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
dest,
|
option_strings,
|
||||||
default=None,
|
dest,
|
||||||
required=False,
|
default=None,
|
||||||
help=None):
|
required=False,
|
||||||
|
help=None,
|
||||||
|
):
|
||||||
super(_CountAction, self).__init__(
|
super(_CountAction, self).__init__(
|
||||||
option_strings=option_strings,
|
option_strings=option_strings,
|
||||||
dest=dest,
|
dest=dest,
|
||||||
nargs=0,
|
nargs=0,
|
||||||
default=default,
|
default=default,
|
||||||
required=required,
|
required=required,
|
||||||
help=help)
|
help=help,
|
||||||
|
)
|
||||||
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
new_count = _ensure_value(namespace, self.dest, 0) + 1
|
new_count = _ensure_value(namespace, self.dest, 0) + 1
|
||||||
@ -1008,17 +1045,20 @@ class _CountAction(Action):
|
|||||||
|
|
||||||
class _HelpAction(Action):
|
class _HelpAction(Action):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
dest=SUPPRESS,
|
option_strings,
|
||||||
default=SUPPRESS,
|
dest=SUPPRESS,
|
||||||
help=None):
|
default=SUPPRESS,
|
||||||
|
help=None,
|
||||||
|
):
|
||||||
super(_HelpAction, self).__init__(
|
super(_HelpAction, self).__init__(
|
||||||
option_strings=option_strings,
|
option_strings=option_strings,
|
||||||
dest=dest,
|
dest=dest,
|
||||||
default=default,
|
default=default,
|
||||||
nargs=0,
|
nargs=0,
|
||||||
help=help)
|
help=help,
|
||||||
|
)
|
||||||
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
@ -1027,18 +1067,21 @@ class _HelpAction(Action):
|
|||||||
|
|
||||||
class _VersionAction(Action):
|
class _VersionAction(Action):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
version=None,
|
option_strings,
|
||||||
dest=SUPPRESS,
|
version=None,
|
||||||
default=SUPPRESS,
|
dest=SUPPRESS,
|
||||||
help="show program's version number and exit"):
|
default=SUPPRESS,
|
||||||
|
help="show program's version number and exit",
|
||||||
|
):
|
||||||
super(_VersionAction, self).__init__(
|
super(_VersionAction, self).__init__(
|
||||||
option_strings=option_strings,
|
option_strings=option_strings,
|
||||||
dest=dest,
|
dest=dest,
|
||||||
default=default,
|
default=default,
|
||||||
nargs=0,
|
nargs=0,
|
||||||
help=help)
|
help=help,
|
||||||
|
)
|
||||||
self.version = version
|
self.version = version
|
||||||
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
@ -1058,13 +1101,15 @@ class _SubParsersAction(Action):
|
|||||||
sup = super(_SubParsersAction._ChoicesPseudoAction, self)
|
sup = super(_SubParsersAction._ChoicesPseudoAction, self)
|
||||||
sup.__init__(option_strings=[], dest=name, help=help)
|
sup.__init__(option_strings=[], dest=name, help=help)
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
option_strings,
|
self,
|
||||||
prog,
|
option_strings,
|
||||||
parser_class,
|
prog,
|
||||||
dest=SUPPRESS,
|
parser_class,
|
||||||
help=None,
|
dest=SUPPRESS,
|
||||||
metavar=None):
|
help=None,
|
||||||
|
metavar=None,
|
||||||
|
):
|
||||||
|
|
||||||
self._prog_prefix = prog
|
self._prog_prefix = prog
|
||||||
self._parser_class = parser_class
|
self._parser_class = parser_class
|
||||||
@ -1077,7 +1122,8 @@ class _SubParsersAction(Action):
|
|||||||
nargs=PARSER,
|
nargs=PARSER,
|
||||||
choices=self._name_parser_map,
|
choices=self._name_parser_map,
|
||||||
help=help,
|
help=help,
|
||||||
metavar=metavar)
|
metavar=metavar,
|
||||||
|
)
|
||||||
|
|
||||||
def add_parser(self, name, **kwargs):
|
def add_parser(self, name, **kwargs):
|
||||||
# set prog from the existing prefix
|
# set prog from the existing prefix
|
||||||
@ -1118,7 +1164,8 @@ class _SubParsersAction(Action):
|
|||||||
# store any unrecognized options on the object, so that the top
|
# store any unrecognized options on the object, so that the top
|
||||||
# level parser can decide what to do with them
|
# level parser can decide what to do with them
|
||||||
namespace, arg_strings = parser.parse_known_args(
|
namespace, arg_strings = parser.parse_known_args(
|
||||||
arg_strings, namespace)
|
arg_strings, namespace,
|
||||||
|
)
|
||||||
if arg_strings:
|
if arg_strings:
|
||||||
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
|
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
|
||||||
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
|
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
|
||||||
@ -1199,11 +1246,13 @@ class Namespace(_AttributeHolder):
|
|||||||
|
|
||||||
class _ActionsContainer(object):
|
class _ActionsContainer(object):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
description,
|
self,
|
||||||
prefix_chars,
|
description,
|
||||||
argument_default,
|
prefix_chars,
|
||||||
conflict_handler):
|
argument_default,
|
||||||
|
conflict_handler,
|
||||||
|
):
|
||||||
super(_ActionsContainer, self).__init__()
|
super(_ActionsContainer, self).__init__()
|
||||||
|
|
||||||
self.description = description
|
self.description = description
|
||||||
@ -1372,7 +1421,8 @@ class _ActionsContainer(object):
|
|||||||
title_group_map[group.title] = self.add_argument_group(
|
title_group_map[group.title] = self.add_argument_group(
|
||||||
title=group.title,
|
title=group.title,
|
||||||
description=group.description,
|
description=group.description,
|
||||||
conflict_handler=group.conflict_handler)
|
conflict_handler=group.conflict_handler,
|
||||||
|
)
|
||||||
|
|
||||||
# map the actions to their new group
|
# map the actions to their new group
|
||||||
for action in group._group_actions:
|
for action in group._group_actions:
|
||||||
@ -1383,7 +1433,8 @@ class _ActionsContainer(object):
|
|||||||
# description= then this code will need to be expanded as above
|
# description= then this code will need to be expanded as above
|
||||||
for group in container._mutually_exclusive_groups:
|
for group in container._mutually_exclusive_groups:
|
||||||
mutex_group = self.add_mutually_exclusive_group(
|
mutex_group = self.add_mutually_exclusive_group(
|
||||||
required=group.required)
|
required=group.required,
|
||||||
|
)
|
||||||
|
|
||||||
# map the actions to their new mutex group
|
# map the actions to their new mutex group
|
||||||
for action in group._group_actions:
|
for action in group._group_actions:
|
||||||
@ -1416,8 +1467,10 @@ class _ActionsContainer(object):
|
|||||||
for option_string in args:
|
for option_string in args:
|
||||||
# error on strings that don't start with an appropriate prefix
|
# error on strings that don't start with an appropriate prefix
|
||||||
if not option_string[0] in self.prefix_chars:
|
if not option_string[0] in self.prefix_chars:
|
||||||
msg = _('invalid option string %r: '
|
msg = _(
|
||||||
'must start with a character %r')
|
'invalid option string %r: '
|
||||||
|
'must start with a character %r',
|
||||||
|
)
|
||||||
tup = option_string, self.prefix_chars
|
tup = option_string, self.prefix_chars
|
||||||
raise ValueError(msg % tup)
|
raise ValueError(msg % tup)
|
||||||
|
|
||||||
@ -1565,19 +1618,21 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||||||
- add_help -- Add a -h/-help option
|
- add_help -- Add a -h/-help option
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(
|
||||||
prog=None,
|
self,
|
||||||
usage=None,
|
prog=None,
|
||||||
description=None,
|
usage=None,
|
||||||
epilog=None,
|
description=None,
|
||||||
version=None,
|
epilog=None,
|
||||||
parents=[],
|
version=None,
|
||||||
formatter_class=HelpFormatter,
|
parents=[],
|
||||||
prefix_chars='-',
|
formatter_class=HelpFormatter,
|
||||||
fromfile_prefix_chars=None,
|
prefix_chars='-',
|
||||||
argument_default=None,
|
fromfile_prefix_chars=None,
|
||||||
conflict_handler='error',
|
argument_default=None,
|
||||||
add_help=True):
|
conflict_handler='error',
|
||||||
|
add_help=True,
|
||||||
|
):
|
||||||
|
|
||||||
if version is not None:
|
if version is not None:
|
||||||
import warnings
|
import warnings
|
||||||
@ -1585,13 +1640,16 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||||||
"""The "version" argument to ArgumentParser is deprecated. """
|
"""The "version" argument to ArgumentParser is deprecated. """
|
||||||
"""Please use """
|
"""Please use """
|
||||||
""""add_argument(..., action='version', version="N", ...)" """
|
""""add_argument(..., action='version', version="N", ...)" """
|
||||||
"""instead""", DeprecationWarning)
|
"""instead""", DeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
superinit = super(ArgumentParser, self).__init__
|
superinit = super(ArgumentParser, self).__init__
|
||||||
superinit(description=description,
|
superinit(
|
||||||
prefix_chars=prefix_chars,
|
description=description,
|
||||||
argument_default=argument_default,
|
prefix_chars=prefix_chars,
|
||||||
conflict_handler=conflict_handler)
|
argument_default=argument_default,
|
||||||
|
conflict_handler=conflict_handler,
|
||||||
|
)
|
||||||
|
|
||||||
# default setting for prog
|
# default setting for prog
|
||||||
if prog is None:
|
if prog is None:
|
||||||
@ -1625,13 +1683,15 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||||||
self.add_argument(
|
self.add_argument(
|
||||||
default_prefix + 'h', default_prefix * 2 + 'help',
|
default_prefix + 'h', default_prefix * 2 + 'help',
|
||||||
action='help', default=SUPPRESS,
|
action='help', default=SUPPRESS,
|
||||||
help=_('show this help message and exit'))
|
help=_('show this help message and exit'),
|
||||||
|
)
|
||||||
if self.version:
|
if self.version:
|
||||||
self.add_argument(
|
self.add_argument(
|
||||||
default_prefix + 'v', default_prefix * 2 + 'version',
|
default_prefix + 'v', default_prefix * 2 + 'version',
|
||||||
action='version', default=SUPPRESS,
|
action='version', default=SUPPRESS,
|
||||||
version=self.version,
|
version=self.version,
|
||||||
help=_("show program's version number and exit"))
|
help=_("show program's version number and exit"),
|
||||||
|
)
|
||||||
|
|
||||||
# add parent arguments and defaults
|
# add parent arguments and defaults
|
||||||
for parent in parents:
|
for parent in parents:
|
||||||
@ -2088,7 +2148,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||||||
# if multiple actions match, the option string was ambiguous
|
# if multiple actions match, the option string was ambiguous
|
||||||
if len(option_tuples) > 1:
|
if len(option_tuples) > 1:
|
||||||
options = ', '.join(
|
options = ', '.join(
|
||||||
[option_string for action, option_string, explicit_arg in option_tuples])
|
[option_string for action, option_string, explicit_arg in option_tuples],
|
||||||
|
)
|
||||||
tup = arg_string, options
|
tup = arg_string, options
|
||||||
self.error(_('ambiguous option: %s could match %s') % tup)
|
self.error(_('ambiguous option: %s could match %s') % tup)
|
||||||
|
|
||||||
@ -2218,8 +2279,10 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||||||
|
|
||||||
# when nargs='*' on a positional, if there were no command-line
|
# when nargs='*' on a positional, if there were no command-line
|
||||||
# args, use the default if it is anything other than None
|
# args, use the default if it is anything other than None
|
||||||
elif (not arg_strings and action.nargs == ZERO_OR_MORE and
|
elif (
|
||||||
not action.option_strings):
|
not arg_strings and action.nargs == ZERO_OR_MORE and
|
||||||
|
not action.option_strings
|
||||||
|
):
|
||||||
if action.default is not None:
|
if action.default is not None:
|
||||||
value = action.default
|
value = action.default
|
||||||
else:
|
else:
|
||||||
@ -2287,16 +2350,20 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||||||
# =======================
|
# =======================
|
||||||
def format_usage(self):
|
def format_usage(self):
|
||||||
formatter = self._get_formatter()
|
formatter = self._get_formatter()
|
||||||
formatter.add_usage(self.usage, self._actions,
|
formatter.add_usage(
|
||||||
self._mutually_exclusive_groups)
|
self.usage, self._actions,
|
||||||
|
self._mutually_exclusive_groups,
|
||||||
|
)
|
||||||
return formatter.format_help()
|
return formatter.format_help()
|
||||||
|
|
||||||
def format_help(self):
|
def format_help(self):
|
||||||
formatter = self._get_formatter()
|
formatter = self._get_formatter()
|
||||||
|
|
||||||
# usage
|
# usage
|
||||||
formatter.add_usage(self.usage, self._actions,
|
formatter.add_usage(
|
||||||
self._mutually_exclusive_groups)
|
self.usage, self._actions,
|
||||||
|
self._mutually_exclusive_groups,
|
||||||
|
)
|
||||||
|
|
||||||
# description
|
# description
|
||||||
formatter.add_text(self.description)
|
formatter.add_text(self.description)
|
||||||
@ -2319,7 +2386,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||||||
warnings.warn(
|
warnings.warn(
|
||||||
'The format_version method is deprecated -- the "version" '
|
'The format_version method is deprecated -- the "version" '
|
||||||
'argument to ArgumentParser is no longer supported.',
|
'argument to ArgumentParser is no longer supported.',
|
||||||
DeprecationWarning)
|
DeprecationWarning,
|
||||||
|
)
|
||||||
formatter = self._get_formatter()
|
formatter = self._get_formatter()
|
||||||
formatter.add_text(self.version)
|
formatter.add_text(self.version)
|
||||||
return formatter.format_help()
|
return formatter.format_help()
|
||||||
@ -2345,7 +2413,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||||||
warnings.warn(
|
warnings.warn(
|
||||||
'The print_version method is deprecated -- the "version" '
|
'The print_version method is deprecated -- the "version" '
|
||||||
'argument to ArgumentParser is no longer supported.',
|
'argument to ArgumentParser is no longer supported.',
|
||||||
DeprecationWarning)
|
DeprecationWarning,
|
||||||
|
)
|
||||||
self._print_message(self.format_version(), file)
|
self._print_message(self.format_version(), file)
|
||||||
|
|
||||||
def _print_message(self, message, file=None):
|
def _print_message(self, message, file=None):
|
||||||
|
@ -55,7 +55,8 @@ def load(config):
|
|||||||
os.path.expanduser('~'),
|
os.path.expanduser('~'),
|
||||||
'.local',
|
'.local',
|
||||||
'share',
|
'share',
|
||||||
'autojump')
|
'autojump',
|
||||||
|
)
|
||||||
|
|
||||||
if is_osx() and os.path.exists(xdg_aj_home):
|
if is_osx() and os.path.exists(xdg_aj_home):
|
||||||
migrate_osx_xdg_data(config)
|
migrate_osx_xdg_data(config)
|
||||||
@ -75,11 +76,14 @@ def load(config):
|
|||||||
with open(
|
with open(
|
||||||
config['data_path'],
|
config['data_path'],
|
||||||
'r', encoding='utf-8',
|
'r', encoding='utf-8',
|
||||||
errors='replace') as f:
|
errors='replace',
|
||||||
|
) as f:
|
||||||
return dict(
|
return dict(
|
||||||
imap(
|
imap(
|
||||||
tupleize,
|
tupleize,
|
||||||
ifilter(correct_length, imap(parse, f))))
|
ifilter(correct_length, imap(parse, f)),
|
||||||
|
),
|
||||||
|
)
|
||||||
except (IOError, EOFError):
|
except (IOError, EOFError):
|
||||||
return load_backup(config)
|
return load_backup(config)
|
||||||
|
|
||||||
|
@ -117,11 +117,13 @@ def match_fuzzy(needles, haystack, ignore_case=False, threshold=0.6):
|
|||||||
needle = last(needles).lower()
|
needle = last(needles).lower()
|
||||||
match_percent = lambda entry: SequenceMatcher(
|
match_percent = lambda entry: SequenceMatcher(
|
||||||
a=needle,
|
a=needle,
|
||||||
b=end_dir(entry.path.lower())).ratio()
|
b=end_dir(entry.path.lower()),
|
||||||
|
).ratio()
|
||||||
else:
|
else:
|
||||||
needle = last(needles)
|
needle = last(needles)
|
||||||
match_percent = lambda entry: SequenceMatcher(
|
match_percent = lambda entry: SequenceMatcher(
|
||||||
a=needle,
|
a=needle,
|
||||||
b=end_dir(entry.path)).ratio()
|
b=end_dir(entry.path),
|
||||||
|
).ratio()
|
||||||
meets_threshold = lambda entry: match_percent(entry) >= threshold
|
meets_threshold = lambda entry: match_percent(entry) >= threshold
|
||||||
return ifilter(meets_threshold, haystack)
|
return ifilter(meets_threshold, haystack)
|
||||||
|
@ -56,7 +56,8 @@ def get_tab_entry_info(entry, separator):
|
|||||||
match_index = re.search(separator + r'([0-9]{1})', entry)
|
match_index = re.search(separator + r'([0-9]{1})', entry)
|
||||||
match_path = re.search(
|
match_path = re.search(
|
||||||
separator + r'[0-9]{1}' + separator + r'(.*)',
|
separator + r'[0-9]{1}' + separator + r'(.*)',
|
||||||
entry)
|
entry,
|
||||||
|
)
|
||||||
|
|
||||||
if match_needle:
|
if match_needle:
|
||||||
needle = match_needle.group(1)
|
needle = match_needle.group(1)
|
||||||
@ -163,7 +164,9 @@ def print_tab_menu(needle, tab_entries, separator):
|
|||||||
separator,
|
separator,
|
||||||
i + 1,
|
i + 1,
|
||||||
separator,
|
separator,
|
||||||
entry.path))
|
entry.path,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def sanitize(directories):
|
def sanitize(directories):
|
||||||
|
57
install.py
57
install.py
@ -45,7 +45,8 @@ def modify_autojump_lua(clink_dir, bin_dir, dryrun=False):
|
|||||||
"""Prepend custom AUTOJUMP_BIN_DIR definition to autojump.lua"""
|
"""Prepend custom AUTOJUMP_BIN_DIR definition to autojump.lua"""
|
||||||
custom_install = "local AUTOJUMP_BIN_DIR = \"%s\"\n" % bin_dir.replace(
|
custom_install = "local AUTOJUMP_BIN_DIR = \"%s\"\n" % bin_dir.replace(
|
||||||
'\\',
|
'\\',
|
||||||
'\\\\')
|
'\\\\',
|
||||||
|
)
|
||||||
clink_file = os.path.join(clink_dir, 'autojump.lua')
|
clink_file = os.path.join(clink_dir, 'autojump.lua')
|
||||||
with open(clink_file, 'r') as f:
|
with open(clink_file, 'r') as f:
|
||||||
original = f.read()
|
original = f.read()
|
||||||
@ -57,11 +58,13 @@ def parse_arguments(): # noqa
|
|||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
default_user_destdir = os.path.join(
|
default_user_destdir = os.path.join(
|
||||||
os.getenv('LOCALAPPDATA', ''),
|
os.getenv('LOCALAPPDATA', ''),
|
||||||
'autojump')
|
'autojump',
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
default_user_destdir = os.path.join(
|
default_user_destdir = os.path.join(
|
||||||
os.path.expanduser('~'),
|
os.path.expanduser('~'),
|
||||||
'.autojump')
|
'.autojump',
|
||||||
|
)
|
||||||
default_user_prefix = ''
|
default_user_prefix = ''
|
||||||
default_user_zshshare = 'functions'
|
default_user_zshshare = 'functions'
|
||||||
default_system_destdir = '/'
|
default_system_destdir = '/'
|
||||||
@ -71,28 +74,36 @@ def parse_arguments(): # noqa
|
|||||||
|
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
description='Installs autojump globally for root users, otherwise \
|
description='Installs autojump globally for root users, otherwise \
|
||||||
installs in current user\'s home directory.')
|
installs in current user\'s home directory.'
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-n', '--dryrun', action='store_true', default=False,
|
'-n', '--dryrun', action='store_true', default=False,
|
||||||
help='simulate installation')
|
help='simulate installation',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-f', '--force', action='store_true', default=False,
|
'-f', '--force', action='store_true', default=False,
|
||||||
help='skip root user, shell type, Python version checks')
|
help='skip root user, shell type, Python version checks',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-d', '--destdir', metavar='DIR', default=default_user_destdir,
|
'-d', '--destdir', metavar='DIR', default=default_user_destdir,
|
||||||
help='set destination to DIR')
|
help='set destination to DIR',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--prefix', metavar='DIR', default=default_user_prefix,
|
'-p', '--prefix', metavar='DIR', default=default_user_prefix,
|
||||||
help='set prefix to DIR')
|
help='set prefix to DIR',
|
||||||
|
)
|
||||||
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(
|
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)',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-s', '--system', action='store_true', default=False,
|
'-s', '--system', action='store_true', default=False,
|
||||||
help='install system wide for all users')
|
help='install system wide for all users',
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -102,18 +113,24 @@ def parse_arguments(): # noqa
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if args.system:
|
if args.system:
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
print('System-wide installation is not supported on Windows.',
|
print(
|
||||||
file=sys.stderr)
|
'System-wide installation is not supported on Windows.',
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif os.geteuid() != 0:
|
elif os.geteuid() != 0:
|
||||||
print('Please rerun as root for system-wide installation.',
|
print(
|
||||||
file=sys.stderr)
|
'Please rerun as root for system-wide installation.',
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if platform.system() != 'Windows' \
|
if platform.system() != 'Windows' \
|
||||||
and get_shell() not in SUPPORTED_SHELLS:
|
and get_shell() not in SUPPORTED_SHELLS:
|
||||||
print('Unsupported shell: %s' % os.getenv('SHELL'),
|
print(
|
||||||
file=sys.stderr)
|
'Unsupported shell: %s' % os.getenv('SHELL'),
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if args.destdir != default_user_destdir \
|
if args.destdir != default_user_destdir \
|
||||||
@ -125,8 +142,10 @@ def parse_arguments(): # noqa
|
|||||||
|
|
||||||
if args.system:
|
if args.system:
|
||||||
if args.custom_install:
|
if args.custom_install:
|
||||||
print('Custom paths incompatible with --system option.',
|
print(
|
||||||
file=sys.stderr)
|
'Custom paths incompatible with --system option.',
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
args.destdir = default_system_destdir
|
args.destdir = default_system_destdir
|
||||||
|
@ -28,7 +28,8 @@ def j(path):
|
|||||||
newpath = Popen(
|
newpath = Popen(
|
||||||
cmd,
|
cmd,
|
||||||
stdout=PIPE,
|
stdout=PIPE,
|
||||||
shell=False).communicate()[0].strip()
|
shell=False,
|
||||||
|
).communicate()[0].strip()
|
||||||
|
|
||||||
if newpath:
|
if newpath:
|
||||||
ip.magic('cd %s' % newpath.decode('utf-8'))
|
ip.magic('cd %s' % newpath.decode('utf-8'))
|
||||||
|
49
uninstall.py
49
uninstall.py
@ -25,24 +25,31 @@ def parse_arguments():
|
|||||||
default_clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink')
|
default_clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink')
|
||||||
|
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
description='Uninstalls autojump.')
|
description='Uninstalls autojump.',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-n', '--dryrun', action='store_true', default=False,
|
'-n', '--dryrun', action='store_true', default=False,
|
||||||
help='simulate installation')
|
help='simulate installation',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-u', '--userdata', action='store_true', default=False,
|
'-u', '--userdata', action='store_true', default=False,
|
||||||
help='delete user data')
|
help='delete user data',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-d', '--destdir', metavar='DIR',
|
'-d', '--destdir', metavar='DIR',
|
||||||
help='custom destdir')
|
help='custom destdir',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--prefix', metavar='DIR', default='',
|
'-p', '--prefix', metavar='DIR', default='',
|
||||||
help='custom prefix')
|
help='custom prefix',
|
||||||
|
)
|
||||||
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(
|
parser.add_argument(
|
||||||
'-c', '--clinkdir', metavar='DIR', default=default_clink_dir)
|
'-c', '--clinkdir', metavar='DIR', default=default_clink_dir,
|
||||||
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
@ -98,13 +105,15 @@ def remove_system_installation(dryrun=False):
|
|||||||
default_prefix,
|
default_prefix,
|
||||||
'share',
|
'share',
|
||||||
'man',
|
'man',
|
||||||
'man1')
|
'man1',
|
||||||
|
)
|
||||||
etc_dir = os.path.join(default_destdir, 'etc', 'profile.d')
|
etc_dir = os.path.join(default_destdir, 'etc', 'profile.d')
|
||||||
share_dir = os.path.join(
|
share_dir = os.path.join(
|
||||||
default_destdir,
|
default_destdir,
|
||||||
default_prefix,
|
default_prefix,
|
||||||
'share',
|
'share',
|
||||||
'autojump')
|
'autojump',
|
||||||
|
)
|
||||||
zshshare_dir = os.path.join(default_destdir, default_zshshare)
|
zshshare_dir = os.path.join(default_destdir, default_zshshare)
|
||||||
|
|
||||||
if not os.path.exists(share_dir):
|
if not os.path.exists(share_dir):
|
||||||
@ -113,8 +122,10 @@ def remove_system_installation(dryrun=False):
|
|||||||
print('\nFound system installation...')
|
print('\nFound system installation...')
|
||||||
|
|
||||||
if os.geteuid() != 0:
|
if os.geteuid() != 0:
|
||||||
print('Please rerun as root for system-wide uninstall, skipping...',
|
print(
|
||||||
file=sys.stderr)
|
'Please rerun as root for system-wide uninstall, skipping...',
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
rm(os.path.join(bin_dir, 'autojump'), dryrun)
|
rm(os.path.join(bin_dir, 'autojump'), dryrun)
|
||||||
@ -135,11 +146,13 @@ def remove_user_data(dryrun=False):
|
|||||||
data_home = os.path.join(
|
data_home = os.path.join(
|
||||||
os.path.expanduser('~'),
|
os.path.expanduser('~'),
|
||||||
'Library',
|
'Library',
|
||||||
'autojump')
|
'autojump',
|
||||||
|
)
|
||||||
elif platform.system() == 'Windows':
|
elif platform.system() == 'Windows':
|
||||||
data_home = os.path.join(
|
data_home = os.path.join(
|
||||||
os.getenv('APPDATA'),
|
os.getenv('APPDATA'),
|
||||||
'autojump')
|
'autojump',
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
data_home = os.getenv(
|
data_home = os.getenv(
|
||||||
'XDG_DATA_HOME',
|
'XDG_DATA_HOME',
|
||||||
@ -147,7 +160,9 @@ def remove_user_data(dryrun=False):
|
|||||||
os.path.expanduser('~'),
|
os.path.expanduser('~'),
|
||||||
'.local',
|
'.local',
|
||||||
'share',
|
'share',
|
||||||
'autojump'))
|
'autojump',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
if os.path.exists(data_home):
|
if os.path.exists(data_home):
|
||||||
print('\nFound user data...')
|
print('\nFound user data...')
|
||||||
@ -156,8 +171,10 @@ def remove_user_data(dryrun=False):
|
|||||||
|
|
||||||
def remove_user_installation(dryrun=False):
|
def remove_user_installation(dryrun=False):
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
default_destdir = os.path.join(os.getenv('LOCALAPPDATA', ''),
|
default_destdir = os.path.join(
|
||||||
'autojump')
|
os.getenv('LOCALAPPDATA', ''),
|
||||||
|
'autojump',
|
||||||
|
)
|
||||||
clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink')
|
clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink')
|
||||||
else:
|
else:
|
||||||
default_destdir = os.path.join(os.path.expanduser('~'), '.autojump')
|
default_destdir = os.path.join(os.path.expanduser('~'), '.autojump')
|
||||||
|
Loading…
Reference in New Issue
Block a user