Red Hat предоставляет "ksh-93", в котором нет команды bind
. Он предоставляет нечто под названием KEYBD
, которое запускается через специальную функцию trap
. Согласно странице руководства, это можно использовать для изменения режима редактирования Emacs.
Пример в [Korn Shell] Fixing Home, End, pgup, pgdown, and delete keys является полезной отправной точкой для демонстрации того, как сделать ^L
очисткой экрана. По умолчанию, metacontrolL (^[^L
) привязана к функции clear-screen, в то время как обычная ^L
- это просто следующая строка, которую вы хотите изменить:
^L Line feed and print current line.
M-^L Clear the screen.
Добавление всего одной строки в пример делает то, о чем просили:
set -o emacs
keybd_trap () {
case ${.sh.edchar} in
$'\f') .sh.edchar=$'\e\f';; # clear-screen (THIS QUESTION)
$'\e[1~') .sh.edchar=$'\001';; # Home = beginning-of-line
$'\e[4~') .sh.edchar=$'\005';; # End = end-of-line
$'\e[5~') .sh.edchar=$'\e>';; # PgUp = history-previous
$'\e[6~') .sh.edchar=$'\e<';; # PgDn = history-next
$'\e[3~') .sh.edchar=$'\004';; # Delete = delete-char
esac
}
trap keybd_trap KEYBD
По какой-то причине, vi-mode гораздо менее способен в ksh
.
В документации неясно, как клавиши фактически сопоставляются с функциями. В данном случае функция реализована в src/cmd/ksh93/edit/emacs.c
как часть оператора switch/case:
#ifdef _cmd_tput
case cntl('L'): /* clear screen */
sh_trap("tput clear", 0);
draw(ep,REFRESH);
return(-1);
#endif
внутри функции escape (т.е. обработка "meta"). Таким образом, это встроенное поведение, которое можно настроитьksh.
Further reading:
Q4. How is keybinding done? A4. ksh93 provides a KEYBD trap that gets executed whenever a key is entered from the keyboard. Using this trap, and the associate array feature of ksh93, a keybind function can easily be written which will map any entered key sequence to another key sequence.
Эта функция уже есть в mandb man , реализации, часто встречающейся в дистрибутивах Linux. Изman 1 man
:
--no-subpages
By default, man will try to interpret pairs of manual page names given on the
command line as equivalent to a single manual page name containing a hyphen or an
underscore. This supports the common pattern of programs that implement a number
of subcommands, allowing them to provide manual pages for each that can be accessed
using similar syntax as would be used to invoke the subcommands themselves. For
example:
$ man -aw git diff
/usr/share/man/man1/git-diff.1.gz
Итак, все, что вам нужно, это иметь справочную страницу с правильным названием <command>-<subcommand>
.
Этого может не быть в других реализациях. Например, macOS man
не поддерживает :
~ man git commit
# shows git manpage
No manual entry for commit