keycut
¤
keycut package.
A command line tool that helps you remembering ALL the numerous keyboard shortcuts of ALL your favorite programs.
Classes:
-
FileWatcher–Watch a command file and display shortcuts for new commands.
-
WindowFocusWatcher–Watch the focused process for application shortcuts.
-
XdotoolWatcher–Watch the focused window name for application shortcuts.
Functions:
-
as_colored_text–Render shortcut entries with terminal colors for fields and matches.
-
as_text–Render shortcut entries as plain text.
-
as_yaml–Serialize shortcut entries as YAML.
-
check–Get the path to a shortcut file and check whether it exists.
-
from_yaml–Load an application's shortcuts from YAML.
-
get_parser–Return the CLI argument parser.
-
grep–Find a shortcut file whose suffix appears in a command line.
-
in_action–Return shortcuts whose action matches a case-insensitive regex.
-
in_category–Return shortcuts whose category matches a case-insensitive regex.
-
in_keys–Return shortcuts whose keys field matches a case-insensitive regex.
-
main–Run the main program.
-
print_err–Write a message to standard error.
-
reload–Print shortcut entries with terminal colors.
-
search–Search shortcut actions, categories, and keys with a case-insensitive regex.
-
word_in_action–Return shortcuts with a whole-word match in their action.
-
word_in_category–Return shortcuts with a whole-word match in their category.
-
word_in_keys–Return shortcuts with a whole-word match in their keys field.
-
word_search–Search all shortcut fields for whole-word matches.
Attributes:
-
ACTION_COLOR–Default color for action names;
Noneleaves them uncolored. -
CATEGORY_COLOR–Default color for category names.
-
DIRECTORY–Directory containing application shortcut files.
-
Document–Shortcut entries with fields such as
category,action, andkeys. -
KEY_COLOR–Default color for shortcut keys.
-
MATCH_COLOR–Color used to highlight matching text.
-
UI_COMMANDS–Command names mapped to their shortcut search functions.
ACTION_COLOR
module-attribute
¤
ACTION_COLOR = None
Default color for action names; None leaves them uncolored.
DIRECTORY
module-attribute
¤
Document
module-attribute
¤
Shortcut entries with fields such as category, action, and keys.
UI_COMMANDS
module-attribute
¤
UI_COMMANDS = {
"s": search,
"a": in_action,
"c": in_category,
"k": in_keys,
"ws": word_search,
"wa": word_in_action,
"wc": word_in_category,
"wk": word_in_keys,
}
Command names mapped to their shortcut search functions.
FileWatcher
¤
FileWatcher(file: str)
Bases: Thread
Watch a command file and display shortcuts for new commands.
Creating the watcher clears the command file.
Methods:
-
read–Return the first line of the command file without trailing whitespace.
-
run–Poll the command file and display shortcuts for new commands.
-
write–Write a command and newline to the command file.
Attributes:
-
current–Last command used to load a shortcut document.
-
file–Path to the command file.
-
sleep–Seconds between reads of the command file.
Source code in src/keycut/_internal/watch.py
114 115 116 117 118 119 120 121 122 | |
read
¤
read() -> str
Return the first line of the command file without trailing whitespace.
Source code in src/keycut/_internal/watch.py
146 147 148 149 | |
run
¤
run() -> None
Poll the command file and display shortcuts for new commands.
Source code in src/keycut/_internal/watch.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
write
¤
Write a command and newline to the command file.
Parameters:
Source code in src/keycut/_internal/watch.py
151 152 153 154 155 156 157 158 | |
WindowFocusWatcher
¤
WindowFocusWatcher()
Bases: Thread
Watch the focused process for application shortcuts.
Methods:
-
run–Poll the focused process and display shortcuts when it changes.
Attributes:
-
cmdline–Last process command line with a loaded shortcut document.
-
name–Last process name with a loaded shortcut document.
-
sleep–Seconds between checks of the focused process.
Source code in src/keycut/_internal/watch.py
68 69 70 71 72 73 74 75 | |
cmdline
instance-attribute
¤
cmdline = ''
Last process command line with a loaded shortcut document.
run
¤
run() -> None
Poll the focused process and display shortcuts when it changes.
Source code in src/keycut/_internal/watch.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
XdotoolWatcher
¤
XdotoolWatcher()
Bases: Thread
Watch the focused window name for application shortcuts.
Methods:
-
run–Poll the focused window and display shortcuts when its name changes.
Attributes:
-
name–Last window name with a loaded shortcut document.
-
sleep–Seconds between checks of the focused window.
Source code in src/keycut/_internal/watch.py
34 35 36 37 38 39 | |
run
¤
run() -> None
Poll the focused window and display shortcuts when its name changes.
Source code in src/keycut/_internal/watch.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
as_colored_text
¤
Render shortcut entries with terminal colors for fields and matches.
Parameters:
-
(document¤Document) –Shortcut entries to render. Position fields, when present, mark the text to highlight.
Returns:
-
str–Formatted text, or an empty string for an empty document.
Source code in src/keycut/_internal/render.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
as_text
¤
Render shortcut entries as plain text.
Parameters:
Returns:
-
str–Formatted text, or an empty string for an empty document.
Source code in src/keycut/_internal/render.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
as_yaml
¤
Serialize shortcut entries as YAML.
Parameters:
Returns:
-
str–YAML text.
Source code in src/keycut/_internal/render.py
120 121 122 123 124 125 126 127 128 129 | |
check
¤
Get the path to a shortcut file and check whether it exists.
Parameters:
-
(name¤str) –Application name without the
.ymlsuffix. -
(path¤Path, default:DIRECTORY) –Directory containing the shortcut file.
Returns:
Source code in src/keycut/_internal/load.py
47 48 49 50 51 52 53 54 55 56 57 58 | |
from_yaml
¤
from_yaml(
app: str, command_line: str | None = None
) -> Document | None
Load an application's shortcuts from YAML.
Parameters:
-
(app¤str) –Application name used to locate the YAML file.
-
(command_line¤str | None, default:None) –Command line used to find a fallback file when the application's file is missing.
Returns:
-
Document | None–Shortcut entries, or
Noneif no fallback file matches.
Source code in src/keycut/_internal/load.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
get_parser
¤
get_parser() -> ArgumentParser
Return the CLI argument parser.
Returns:
-
ArgumentParser–An argparse parser.
Source code in src/keycut/_internal/cli.py
48 49 50 51 52 53 54 55 56 57 | |
grep
¤
Find a shortcut file whose suffix appears in a command line.
Parameters:
Returns:
-
Path | None–The matching file path, or
Noneif no file matches.
Source code in src/keycut/_internal/load.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
in_action
¤
Return shortcuts whose action matches a case-insensitive regex.
Parameters:
Returns:
-
Document–Matching shortcut entries.
Source code in src/keycut/_internal/search.py
90 91 92 93 94 95 96 97 98 99 100 | |
in_category
¤
Return shortcuts whose category matches a case-insensitive regex.
Parameters:
Returns:
-
Document–Matching shortcut entries.
Source code in src/keycut/_internal/search.py
77 78 79 80 81 82 83 84 85 86 87 | |
in_keys
¤
Return shortcuts whose keys field matches a case-insensitive regex.
Parameters:
Returns:
-
Document–Matching shortcut entries.
Source code in src/keycut/_internal/search.py
103 104 105 106 107 108 109 110 111 112 113 | |
main
¤
Run the main program.
This function is executed when you type keycut or python -m keycut.
Parameters:
Returns:
-
int–An exit code.
Source code in src/keycut/_internal/cli.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
print_err
¤
Write a message to standard error.
Parameters:
Source code in src/keycut/_internal/utils.py
22 23 24 25 26 27 28 | |
reload
¤
Print shortcut entries with terminal colors.
Parameters:
Source code in src/keycut/_internal/ui.py
45 46 47 48 49 50 51 52 | |
search
¤
Search shortcut actions, categories, and keys with a case-insensitive regex.
Matching entries gain position fields for highlighting. If nothing matches, return the original document.
Parameters:
Returns:
-
Document–Matching shortcut entries, or the original document if none match.
Source code in src/keycut/_internal/search.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
word_in_action
¤
Return shortcuts with a whole-word match in their action.
Parameters:
-
(document¤Document) –Shortcut entries to search.
-
(pattern¤str) –Case-insensitive regular expression to match as a whole word.
Returns:
-
Document–Matching shortcut entries.
Source code in src/keycut/_internal/search.py
145 146 147 148 149 150 151 152 153 154 155 | |
word_in_category
¤
Return shortcuts with a whole-word match in their category.
Parameters:
-
(document¤Document) –Shortcut entries to search.
-
(pattern¤str) –Case-insensitive regular expression to match as a whole word.
Returns:
-
Document–Matching shortcut entries.
Source code in src/keycut/_internal/search.py
132 133 134 135 136 137 138 139 140 141 142 | |
word_in_keys
¤
Return shortcuts with a whole-word match in their keys field.
Parameters:
-
(document¤Document) –Shortcut entries to search.
-
(pattern¤str) –Case-insensitive regular expression to match as a whole word.
Returns:
-
Document–Matching shortcut entries.
Source code in src/keycut/_internal/search.py
158 159 160 161 162 163 164 165 166 167 168 | |
word_search
¤
Search all shortcut fields for whole-word matches.
Matching entries gain position fields for highlighting. If nothing matches, return the original document.
Parameters:
-
(document¤Document) –Shortcut entries to search.
-
(pattern¤str) –Case-insensitive regular expression to match as a whole word.
Returns:
-
Document–Matching shortcut entries, or the original document if none match.
Source code in src/keycut/_internal/search.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |