0x0i.tmux

ansible logo

tmux logo

Ansible 角色 :eyeglasses: tmux

Galaxy 角色 GitHub 最新版本 许可证: MIT

目录

Ansible 角色用于安装、配置和运行 tmux:一个终端复用器,可以通过一个屏幕创建、访问和控制多个终端。

支持的平台:
* Debian
* Redhat(CentOS/Fedora)
* Ubuntu

要求

需要预先安装 libevent 2.xncurses 软件包。

角色变量

变量根据以下软件和机器提供阶段进行组织:

  • 安装
  • 配置
  • 卸载

安装

tmux可以通过支持平台提供的操作系统包管理系统(例如 apt, yum/dnf)进行安装。

以下变量可以自定义以控制安装过程的各个方面:

service_package: <package-name-and-version> (默认值: tmux[-latest])

  • 要下载和安装的 tmux 包的名称和版本。参考 或在终端中运行 dnf --showduplicates list tmux 来显示可用包的列表

配置

使用此角色,可以通过 tmux_config 用户变量管理 tmux 的实例配置,其值可以用哈希表达,按用户账户键控。这些用户账户键的值可以是字典、字典列表或二者结合(根据操作员 yaml 语法和自定义偏好设置),表示相关的启动/配置命令和命令序列(通过执行链接的命令组合)以及一个 可选 注释。

以下提供概述和示例配置供参考:

[tmux_config: {global | user-account} : {entry} :] comment: <string> (默认值: 参见 none)

  • [可选] 与配置命令或命令序列相关的注释
示例
 tmux_config:
   global:
     - comment: "此注释提供了以下命令的上下文"
       commands:
         - "source-file": "'~/.tmux.conf'"

[tmux_config: {global | user-account} : {entry} :] commands: <key: value,...> (默认值: 参见 defaults/main.yml)

  • 一组将在 用户账户 的 tmux.conf 中呈现的配置命令。可用命令的列表可以在 这里 找到。

通常,每个 key:value 对分别代表 tmux 命令的 {command}: {flags} 组件:

 tmux_config:
   global:
     - comment: "将 ctrl-A 添加为次要前缀键"
       commands:
         # {command}: {flags} 格式
         - "set-option": "-g prefix2 C-a"
         - "bind-key": "C-a send-prefix -2"

但是,技术上任何 tmux 命令语法的拆分都是允许的,并且应该能够正确渲染所需的配置。

 tmux_config:
   user-account-1:
     - commands:
         - "bind-key C-c": "new-session"
         - "if-shell true": "{ display -p 'bar-dollar-foo: $foo' }"
         - "set-hook -g pane-mode-changed[42] 'set -g status-left-style bg=red'": ""
     - commands:
         - "set": "-g @plugin 'tmux-plugins/tpm'"
           "set -g": "@plugin 'tmux-plugins/tmux-sensible'"
       comment: "安装 tmux TPM 和 'tmux-sensible'(合理配置)插件"

卸载

移除所有包安装以及管理的 tmux 用户配置,将目标主机恢复到应用此角色之前的配置状态,但不包括全局/系统范围的配置(例如,这在系统升级期间回收配置设置时非常有用)。

可以自定义以下变量以管理此卸载过程:

perform_uninstall: <true | false> (默认值: false)

  • 是否在目标主机上卸载管理的 tmux 安装和用户配置(参见: handlers/main.yml 以获取详细信息)

依赖项

示例剧本

默认示例:

- hosts: all
  roles:
  - role: 0x0I.tmux

安装和管理特定版本:

- hosts: all
  roles:
  - role: 0x0I.tmux
    vars:
      service_package: tmux-2.7-2

手动应用 Tmux "合理(配置)" 插件设置:

- hosts: all
  roles:
  - role: 0x0I.tmux
    vars:
      tmux_config:
        global:
          - comment: "utf8已开启"
            commands:
              - "set-option": "-g utf8 on"
              - "set-option": "-g status-utf8 on"
          - comment: "解决 vim 模式切换延迟 (http://superuser.com/a/252717/65504)"
            commands:
              - "set-option": "-s escape-time 0"
          - comment: "增加滚动缓冲区大小"
            commands:
              - "set-option": "-g history-limit 50000"
          - comment: "tmux 消息显示 4 秒"
            commands:
              - "set-option": "-g display-time 4000"
          - comment: "更频繁地刷新 'status-left' 和 'status-right'"
            commands:
              - "set-option": "-g status-interval 5"
          - comment: "升级 $TERM"
            commands:
              - "set-option": "-g default-terminal "screen-256color"
          - comment: "tmux 命令提示符中的 emacs 键绑定(前缀 + :) 比 vi 键更好,即使是对 vim 用户也是如此"
            commands:
              - "set-option": "status-keys emacs"
          - comment: "支持焦点事件的终端启用"
            commands:
              - "set-option": "-g focus-events on"
          - comment: "在使用 '分组会话' 和多监视器设置时超有用"
            commands:
              - "set-window-option": "-g aggressive-resize on"
          - comment: "更容易和更快地在下一个/上一个窗口之间切换"
            commands:
              - "bind-key": "C-p previous-window"
              - "bind-key": "C-n next-window"
          - comment: "如 `man tmux` 中建议的那样加载 .tmux.conf"
            commands:
              - "bind-key": "R source-file '~/.tmux.conf'"
          - comment: "如果前缀是 'C-a'"
            commands:
              - "bind-key": "C-a send-prefix"
              - "bind-key": "a last-window"

...或者与插件安装:

- hosts: all
  roles:
  - role: 0x0I.tmux
    vars:
      tmux_config:
        global:
          - comment: "将合理配置添加到 TPM 插件列表"
            commands:
              - "set-option": "-g @plugin 'tmux-plugins/tmux-sensible'"

许可证

MIT

作者信息

该角色由 O1.IO 于 2019 年创建。

关于项目

tmux, a terminal multiplexer enabling multiple terminals to be created, accessed, and controlled from a single screen

安装
ansible-galaxy install 0x0i.tmux
许可证
Unknown
下载
299
拥有者