终端键绑定的配置文件在哪里?

Dav*_* J. 2 server command-line

我想检查/更改/重新映射我的 Ubuntu 服务器终端中的键绑定。(我没有使用任何 GUI。我指的是准系统终端 TTY1)。

我的核心问题是:

  • 终端键绑定的配置文件在哪里?

背景:(我写这个背景是为了帮助读者理解我来自哪里。)

  • 我想了解我的“低级”终端键绑定,以便我可以更好地配置和使用 Byobu。

  • 如果答案可以,我也将不胜感激:

    • 解释终端如何启动的进程顺序/堆栈(因为这将帮助我了解哪些进程正在“窃取”键绑定)

    • 澄清我是否错误地使用了任何术语

Dav*_* J. 5

简答

直接回答问题:

终端键绑定的配置文件在哪里?

就我而言(带有 bash 的 Ubuntu 16.04),Serge 的回答很有用。(虽然我不太确定它是否完整地涵盖了所有可能发生冲突的键绑定,这就是我写这个较长答案的原因。)Bash 在这些文件中配置键绑定:

  • 默认键绑定: /etc/inputrc
  • 自定义键绑定: ~/.inputrc

长答案

在本节中,我想更全面一些。虽然 bash 和 readline 影响键绑定,但它们涉及其他进程。例如,如何ALT-2绑定到 TTY #2?

概述

作为概述,以下是我的 Ubuntu Server 16.04 机器上涉及的部分。我从systemd开始,这是 Ubuntu 当前的初始化系统。

  • systemd开始systemd_logind
  • systemd_logindlogin.开始 TTY1 。
  • login开始bash
  • bash使用readline图书馆。
  • bash~/.bashrc最终开始的运行byobu
  • byobu,在我的系统上,tmux用作后端

(注:systemd。在Ubuntu 15.04 16.04和使用新贵是为Ubuntu 6.10初始化系统15.10,根据https://en.wikipedia.org/wiki/Ubuntu_version_history。)

实际上,以下组件会捕获一些按键:

  • systemd-logind(陷阱ALT-1ALT-2等)。
  • login
  • bash使用readline图书馆
  • tmux
  • byobu
  • 在TTY(TODO:我不知道这是一部分systemdlogin?)

系统登录

对于 Ubuntu 16.04,systemd-logind是用户登录的起点。根据systemd-logindUbuntu 手册页

systemd-logind 是一个管理用户登录的系统服务。它负责:

  • Keeping track of users and sessions, their processes and their idle state
  • Providing PolicyKit-based access for users to operations such as system shutdown or sleep
  • Implementing a shutdown/sleep inhibition logic for applications
  • Handling of power/sleep hardware keys
  • Multi-seat management
  • Session switch management
  • Device access management for users
  • Automatic spawning of text logins (gettys) on virtual console activation and user runtime directory management

See also the man page for logind.conf. I didn't see any mention there of terminal keybindings.

TTY / keyboard configuration

Related links about TTY / keyboard configuration:

Tools for TTY / keyboard layouts:

bash (with the readline library)

The gnu.org bash reference has nice documentation about bash and readline functions.

These configuration files affect key bindings:

  • default key-bindings: /etc/inputrc
  • custom key-bindings: ~/.inputrc

tmux

tmux key bindings are described here: https://wiki.archlinux.org/index.php/Tmux#Key_bindings

A user-specific configuration file should be located at ~/.tmux.conf, while a global configuration file should be located at /etc/tmux.conf.

byobu

Byobu has default key bindings which can be user defined in /usr/share/byobu/keybindings/.

Work In Progress

注意:这个答案是一个正在进行的工作。可能有错误。(我发现根据我的阅读和推理,陈述似乎正确的内容更容易,如果有误,请更正。)我将更新此内容,并在接近完成时删除此通知。