diff --git a/kittens/ask/main.py b/kittens/ask/main.py index 30752141b..db039b200 100644 --- a/kittens/ask/main.py +++ b/kittens/ask/main.py @@ -53,7 +53,6 @@ class HistoryCompleter: if os.path.exists(self.history_path): readline.read_history_file(self.history_path) readline.set_completer(self.complete) - readline.parse_and_bind('tab: complete') return self def __exit__(self, *a): @@ -87,6 +86,7 @@ def main(args): global readline import readline as rl readline = rl + from kitty.shell import init_readline msg = 'Ask the user for input' try: args, items = parse_args(args[1:], option_text, '', msg, 'kitty ask') @@ -96,7 +96,7 @@ def main(args): input('Press enter to quit...') raise SystemExit(e.code) - readline.read_init_file() + init_readline(readline) ans = {'items': items} with alternate_screen(), HistoryCompleter(args.name): diff --git a/kitty/shell.py b/kitty/shell.py index 4d88bcdbd..60b91dafe 100644 --- a/kitty/shell.py +++ b/kitty/shell.py @@ -14,12 +14,24 @@ from .cli import ( emph, green, italic, parse_option_spec, print_help_for_seq, title ) from .cmds import cmap, display_subcommand_help, parse_subcommand_cli -from .constants import cache_dir, version +from .constants import cache_dir, is_macos, version all_commands = tuple(sorted(cmap)) match_commands = tuple(sorted(all_commands + ('exit', 'help', 'quit'))) +def init_readline(readline): + try: + readline.read_init_file() + except EnvironmentError: + if not is_macos: + raise + if 'libedit' in readline.__doc__: + readline.parse_and_bind("bind ^I rl_complete") + else: + readline.parse_and_bind('tab: complete') + + def cmd_names_matching(prefix): for cmd in match_commands: if not prefix or cmd.startswith(prefix): @@ -76,7 +88,6 @@ class Completer: if os.path.exists(self.history_path): readline.read_history_file(self.history_path) readline.set_completer(self.complete) - readline.parse_and_bind('tab: complete') delims = readline.get_completer_delims() readline.set_completer_delims(delims.replace('-', '')) return self @@ -141,7 +152,7 @@ def run_cmd(global_opts, cmd, func, opts, items): def real_main(global_opts): - readline.read_init_file() + init_readline(readline) print_help_for_seq.allow_pager = False print('Welcome to the kitty shell!') print('Use {} for assistance or {} to quit'.format(green('help'), green('exit')))