From 1b7244f3c83be9779e2c3da3b619ad5a74c2e9ad Mon Sep 17 00:00:00 2001 From: "Pablo S. Blum de Aguiar" Date: Mon, 27 Aug 2018 00:51:30 +0200 Subject: [PATCH] Completion for fish --- docs/index.rst | 10 ++++++++++ kitty/complete.py | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 330474a57..e7f8f787e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -371,6 +371,16 @@ Add the following to your :file:`~/.bashrc` source <(kitty + complete setup bash) +fish +~~~~~~~~ + +Add the following to your :file:`~/.config/fish/config.fish` + +.. code-block:: sh + + kitty + complete setup fish | source + + zsh ~~~~~~~~~ diff --git a/kitty/complete.py b/kitty/complete.py index 4700a0590..1e6d8349c 100644 --- a/kitty/complete.py +++ b/kitty/complete.py @@ -56,6 +56,14 @@ kitty_completions() { } complete -o nospace -F kitty_completions kitty +''', + 'fish': ''' +function __kitty_completions + # Send all words up to the one before the cursor + commandline -cop | kitty +complete fish +end + +complete -f -c kitty -a "(__kitty_completions)" ''', } @@ -86,6 +94,11 @@ def bash_input_parser(data): return words, new_word +@input_parser +def fish_input_parser(data): + return data.rstrip().splitlines(), True + + @output_serializer def zsh_output_serializer(ans): lines = [] @@ -117,6 +130,16 @@ def bash_output_serializer(ans): # }}} +@output_serializer +def fish_output_serializer(ans): + lines = [] + for matches in ans.match_groups.values(): + for word in matches: + lines.append(shlex.quote(word)) + # debug('\n'.join(lines)) + return '\n'.join(lines) + + def completions_for_first_word(ans, prefix, entry_points, namespaced_entry_points): cmds = ['@' + c for c in cmap] ans.match_groups['Entry points'] = {