2018-05-29 18:33:50 +03:00
|
|
|
Hints
|
|
|
|
==========
|
|
|
|
|
|
|
|
|kitty| has a *hints mode* to select and act on arbitrary text snippets currently
|
2018-06-05 05:43:28 +03:00
|
|
|
visible on the screen. For example, you can press :sc:`open_url`
|
2018-05-29 18:33:50 +03:00
|
|
|
to choose any URL visible on the screen and then open it using your system
|
|
|
|
browser.
|
|
|
|
|
2018-05-30 17:34:49 +03:00
|
|
|
.. figure:: ../screenshots/hints_mode.png
|
|
|
|
:alt: URL hints mode
|
|
|
|
:align: center
|
|
|
|
:scale: 100%
|
|
|
|
|
|
|
|
URL hints mode
|
2018-05-29 18:33:50 +03:00
|
|
|
|
2018-06-05 05:43:28 +03:00
|
|
|
Similarly, you can press :sc:`insert_selected_path` to
|
2018-05-29 18:33:50 +03:00
|
|
|
select anything that looks like a path or filename and then insert it into the
|
|
|
|
terminal, very useful for picking files from the output of a ``git`` or ``ls`` command and
|
|
|
|
adding them to the command line for the next command.
|
|
|
|
|
|
|
|
The hints kitten is very powerful to see more detailed help on its various
|
2018-09-17 04:12:20 +03:00
|
|
|
options and modes of operation, see below. You can use these options to
|
|
|
|
create mappings in :file:`kitty.conf` to select various different text
|
|
|
|
snippets. See :sc:`insert_selected_path` for examples.
|
2018-05-29 18:33:50 +03:00
|
|
|
|
2019-11-11 18:56:42 +03:00
|
|
|
Completely customizing the matching and actions of the kitten
|
|
|
|
---------------------------------------------------------------
|
|
|
|
|
|
|
|
The hints kitten supports writing simple python scripts that can be used to
|
|
|
|
completely customize how it finds matches and what happens when a match is
|
|
|
|
selected. This allows the hints kitten to provide the user interface, while
|
|
|
|
you can provide the logic for finding matches and performing actions on them.
|
|
|
|
This is best illustrated with an example. Create the file
|
|
|
|
:file:`custom-hints.py` in the kitty config directory with the following
|
|
|
|
contents:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
2019-11-13 14:57:55 +03:00
|
|
|
def mark(text, args, Mark, extra_cli_args, *a):
|
2019-11-11 18:56:42 +03:00
|
|
|
# This function is responsible for finding all
|
2019-11-13 14:57:55 +03:00
|
|
|
# matching text. extra_cli_args are any extra arguments
|
|
|
|
# passed on the command line when invoking the kitten.
|
2019-11-11 18:56:42 +03:00
|
|
|
# We mark all individual word for potential selection
|
|
|
|
for idx, m in enumerate(re.finditer(r'\w+', text)):
|
|
|
|
start, end = m.span()
|
|
|
|
mark_text = text[start:end].replace('\n', '').replace('\0', '')
|
|
|
|
# The empty dictionary below will be available as groupdicts
|
|
|
|
# in handle_result() and can contain arbitrary data.
|
|
|
|
yield Mark(idx, start, end, mark_text, {})
|
|
|
|
|
|
|
|
|
2019-11-13 14:57:55 +03:00
|
|
|
def handle_result(args, data, target_window_id, boss, extra_cli_args, *a):
|
2019-11-11 18:56:42 +03:00
|
|
|
# This function is responsible for performing some
|
|
|
|
# action on the selected text.
|
|
|
|
# matches is a list of the selected entries and groupdicts contains
|
|
|
|
# the arbitrary data associated with each entry in mark() above
|
|
|
|
matches, groupdicts = [], []
|
|
|
|
for m, g in zip(data['match'], data['groupdicts']):
|
|
|
|
if m:
|
|
|
|
matches.append(m), groupdicts.append(g)
|
|
|
|
for word, data in zip(matches, groupdicts):
|
|
|
|
# Lookup the word in a dictionary, the open_url function
|
|
|
|
# will open the provided url in the system browser
|
|
|
|
boss.open_url(f'https://www.google.com/search?q=define:{word}')
|
|
|
|
|
2019-11-13 17:15:28 +03:00
|
|
|
Now run kitty with::
|
2019-11-11 18:56:42 +03:00
|
|
|
|
|
|
|
kitty -o 'map f1 kitten hints --customize-processing custom-hints.py'
|
|
|
|
|
|
|
|
and when you press the :kbd:`F1` key you will be able to select a word to
|
|
|
|
look it up in the Google dictionary.
|
|
|
|
|
|
|
|
|
2018-06-02 10:34:25 +03:00
|
|
|
Command Line Interface
|
|
|
|
-------------------------
|
2018-05-29 18:33:50 +03:00
|
|
|
|
2018-06-02 10:34:25 +03:00
|
|
|
.. include:: ../generated/cli-kitten-hints.rst
|