Implement completion for the kitty command
Implemented for bash and zsh. Completion scripts are just thin wrappers around kitty + complete which knows how to complete kitty command lines. Should make it easy to add completion for other shells in the future.
This commit is contained in:
parent
ff09bdcbf1
commit
42546f4371
@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
kitty_completions() {
|
||||
local src
|
||||
local limit
|
||||
# Send all words up to the word the cursor is currently on
|
||||
let limit=1+$COMP_CWORD
|
||||
src=$(printf "%s\n" "${COMP_WORDS[@]: 0:$limit}" | kitty +complete bash)
|
||||
if [[ $? == 0 ]]; then
|
||||
eval ${src}
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F kitty_completions kitty
|
||||
@ -1,10 +0,0 @@
|
||||
#compdef kitty
|
||||
|
||||
_kitty() {
|
||||
local src
|
||||
# Send all words upto the word the cursor is currently on
|
||||
src=$(printf "%s\n" "${(@)words[1,$CURRENT]}" | kitty +complete zsh)
|
||||
if [[ $? == 0 ]]; then
|
||||
eval ${src}
|
||||
fi
|
||||
}
|
||||
@ -14,6 +14,9 @@ Changelog
|
||||
using standard keyboards) via `IBus
|
||||
<https://github.com/ibus/ibus/wiki/ReadMe>`_ (:iss:`469`)
|
||||
|
||||
- Implement completion for the kitty command in bash and zsh. See
|
||||
:ref:`completion`.
|
||||
|
||||
- Render the text under the cursor in a fixed color, configurable via
|
||||
the option :opt:`cursor_text_color` (:iss:`126`)
|
||||
|
||||
|
||||
@ -350,6 +350,39 @@ Frequently Asked Questions
|
||||
|
||||
The list of Frequently Asked Questions (*FAQ*) is :doc:`available here <faq>`.
|
||||
|
||||
.. _completion:
|
||||
|
||||
Completion for kitty
|
||||
---------------------------------
|
||||
|
||||
|kitty| comes with completion for the ``kitty`` command for popular shells.
|
||||
|
||||
|
||||
bash
|
||||
~~~~~~~~
|
||||
|
||||
Add the following to your :file:`~/.bashrc`
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
source <(kitty + complete setup bash)
|
||||
|
||||
|
||||
zsh
|
||||
~~~~~~~~~
|
||||
|
||||
Add the following to your :file:`~/.zshrc`
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
autoload -Uz compinit
|
||||
compinit
|
||||
# Completion for kitty
|
||||
kitty + complete setup zsh | source /dev/stdin
|
||||
|
||||
The important thing above is to make sure the call to |kitty| to load the zsh
|
||||
completions happens after the call to :file:`compinit`.
|
||||
|
||||
|
||||
Changelog
|
||||
------------------
|
||||
|
||||
@ -26,7 +26,37 @@ class Completions:
|
||||
self.no_space_groups = set()
|
||||
|
||||
|
||||
# I/O {{{
|
||||
# Shell specific code {{{
|
||||
|
||||
|
||||
completion_scripts = {
|
||||
'zsh': '''
|
||||
_kitty() {
|
||||
local src
|
||||
# Send all words upto the word the cursor is currently on
|
||||
src=$(printf "%s\n" "${(@)words[1,$CURRENT]}" | kitty +complete zsh)
|
||||
if [[ $? == 0 ]]; then
|
||||
eval ${src}
|
||||
fi
|
||||
}
|
||||
compdef _kitty kitty
|
||||
''',
|
||||
'bash': '''
|
||||
kitty_completions() {
|
||||
local src
|
||||
local limit
|
||||
# Send all words up to the word the cursor is currently on
|
||||
let limit=1+$COMP_CWORD
|
||||
src=$(printf "%s\n" "${COMP_WORDS[@]: 0:$limit}" | kitty +complete bash)
|
||||
if [[ $? == 0 ]]; then
|
||||
eval ${src}
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F kitty_completions kitty
|
||||
''',
|
||||
}
|
||||
|
||||
|
||||
def input_parser(func):
|
||||
name = func.__name__.split('_')[0]
|
||||
@ -209,10 +239,16 @@ def find_completions(words, new_word, entry_points, namespaced_entry_points):
|
||||
return ans
|
||||
|
||||
|
||||
def setup(cstyle):
|
||||
print(completion_scripts[cstyle])
|
||||
|
||||
|
||||
def main(args, entry_points, namespaced_entry_points):
|
||||
if not args:
|
||||
raise SystemExit('Must specify completion style')
|
||||
cstyle = args[0]
|
||||
if cstyle == 'setup':
|
||||
return setup(args[1])
|
||||
data = sys.stdin.read()
|
||||
try:
|
||||
parser = parsers[cstyle]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user