git.iko.soy/typeable/nixpkgs
on master help sign in
tmux module: add additional variables for configuring tmux
60025e3Peter Hoeg
nixos/modules/programs/tmux.nix+133−5
@@ -5,8 +5,57 @@ let
5
5
6 cfg = config.programs.tmux;
6 cfg = config.programs.tmux;
7
7
8+ defaultKeyMode = "emacs";
9+ defaultResize = 5;
10+ defaultShortcut = "b";
11+ defaultTerminal = "screen";
12+
13+ boolToStr = value: if value then "on" else "off";
14+
15+ tmuxConf = ''
16+ set -g default-terminal "${cfg.terminal}"
17+ set -g base-index ${toString cfg.baseIndex}
18+ setw -g pane-base-index ${toString cfg.baseIndex}
19+
20+ ${if cfg.newSession then "new-session" else ""}
21+
22+ ${if cfg.reverseSplit then ''
23+ bind v split-window -h
24+ bind s split-window -v
25+ '' else ""}
26+
27+ set -g status-keys ${cfg.keyMode}
28+ set -g mode-keys ${cfg.keyMode}
29+
30+ ${if cfg.keyMode == "vi" then ''
31+ bind h select-pane -L
32+ bind j select-pane -D
33+ bind k select-pane -U
34+ bind l select-pane -R
35+
36+ bind -r H resize-pane -L ${toString cfg.resizeAmount}
37+ bind -r J resize-pane -D ${toString cfg.resizeAmount}
38+ bind -r K resize-pane -U ${toString cfg.resizeAmount}
39+ bind -r L resize-pane -R ${toString cfg.resizeAmount}
40+ '' else ""}
41+
42+ ${if (cfg.shortcut != defaultShortcut) then ''
43+ # rebind main key: C-${cfg.shortcut}
44+ unbind C-${defaultShortcut}
45+ set -g prefix C-${cfg.shortcut}
46+ bind ${cfg.shortcut} send-prefix
47+ bind C-${cfg.shortcut} last-window
48+ '' else ""}
49+
50+ setw -g aggressive-resize ${boolToStr cfg.aggressiveResize}
51+ setw -g clock-mode-style ${if cfg.clock24 then "24" else "12"}
52+ set -s escape-time ${toString cfg.escapeTime}
53+ set -g history-limit ${toString cfg.historyLimit}
54+
55+ ${cfg.extraTmuxConf}
56+ '';
57+
8−in
58+in {
9−{
10 ###### interface
59 ###### interface
11
60
12 options = {
61 options = {
@@ -14,13 +63,92 @@ in
14
63
15 enable = mkEnableOption "<command>tmux</command> - a <command>screen</command> replacement.";
64 enable = mkEnableOption "<command>tmux</command> - a <command>screen</command> replacement.";
16
65
66+ aggressiveResize = mkOption {
67+ default = false;
68+ example = true;
69+ type = types.bool;
70+ description = ''
71+ Resize the window to the size of the smallest session for which it is the current window.
72+ '';
73+ };
74+
75+ baseIndex = mkOption {
76+ default = 0;
77+ example = 1;
78+ type = types.int;
79+ description = "Base index for windows and panes.";
80+ };
81+
82+ clock24 = mkOption {
83+ default = false;
84+ example = true;
85+ type = types.bool;
86+ description = "Use 24 hour clock.";
87+ };
88+
89+ escapeTime = mkOption {
90+ default = 500;
91+ example = 0;
92+ type = types.int;
93+ description = "Time in milliseconds for which tmux waits after an escape is input.";
94+ };
95+
17− tmuxconf = mkOption {
96+ extraTmuxConf = mkOption {
18 default = "";
97 default = "";
19 description = ''
98 description = ''
20− The contents of /etc/tmux.conf
99+ Additional contents of /etc/tmux.conf
21 '';
100 '';
22 type = types.lines;
101 type = types.lines;
23 };
102 };
103+
104+ historyLimit = mkOption {
105+ default = 2000;
106+ example = 5000;
107+ type = types.int;
108+ description = "Maximum number of lines held in window history.";
109+ };
110+
111+ keyMode = mkOption {
112+ default = defaultKeyMode;
113+ example = "vi";
114+ type = types.enum [ "emacs" "vi" ];
115+ description = "VI or Emacs style shortcuts.";
116+ };
117+
118+ newSession = mkOption {
119+ default = false;
120+ example = true;
121+ type = types.bool;
122+ description = "Automatically spawn a session if trying to attach and none are running.";
123+ };
124+
125+ reverseSplit = mkOption {
126+ default = false;
127+ example = true;
128+ type = types.bool;
129+ description = "Reverse the window split shortcuts.";
130+ };
131+
132+ resizeAmount = mkOption {
133+ default = defaultResize;
134+ example = 10;
135+ type = types.int;
136+ description = "Number of lines/columns when resizing.";
137+ };
138+
139+ shortcut = mkOption {
140+ default = defaultShortcut;
141+ example = "a";
142+ type = types.str;
143+ description = "Ctrl following by this key is used as the main shortcut.";
144+ };
145+
146+ terminal = mkOption {
147+ default = defaultTerminal;
148+ example = "screen-256color";
149+ type = types.str;
150+ description = "Set the $TERM variable.";
151+ };
24 };
152 };
25 };
153 };
26
154
@@ -29,7 +157,7 @@ in
29 config = mkIf cfg.enable {
157 config = mkIf cfg.enable {
30 environment = {
158 environment = {
31 systemPackages = [ pkgs.tmux ];
159 systemPackages = [ pkgs.tmux ];
32− etc."tmux.conf".text = cfg.tmuxconf;
160+ etc."tmux.conf".text = tmuxConf;
33 };
161 };
34 };
162 };
35}
163}
pkgs/tools/misc/tmux/default.nix+7−4
@@ -1,4 +1,4 @@
1−{ stdenv, fetchFromGitHub, autoreconfHook, ncurses, libevent, pkgconfig }:
1+{ stdenv, fetchFromGitHub, autoreconfHook, ncurses, libevent, pkgconfig, makeWrapper }:
2
2
3let
3let
4
4
@@ -24,7 +24,7 @@ stdenv.mkDerivation rec {
24
24
25 nativeBuildInputs = [ pkgconfig autoreconfHook ];
25 nativeBuildInputs = [ pkgconfig autoreconfHook ];
26
26
27− buildInputs = [ ncurses libevent ];
27+ buildInputs = [ ncurses libevent makeWrapper ];
28
28
29 configureFlags = [
29 configureFlags = [
30 "--sysconfdir=/etc"
30 "--sysconfdir=/etc"
@@ -32,8 +32,11 @@ stdenv.mkDerivation rec {
32 ];
32 ];
33
33
34 postInstall = ''
34 postInstall = ''
35− mkdir -p $out/etc/bash_completion.d
35+ mkdir -p $out/share/bash-completion/completions
36− cp -v ${bashCompletion}/completions/tmux $out/etc/bash_completion.d/tmux
36+ cp -v ${bashCompletion}/completions/tmux $out/share/bash-completion/completions/tmux
37+
38+ wrapProgram $out/bin/tmux \
39+ --set TMUX_TMPDIR \''${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}
37 '';
40 '';
38
41
39 meta = {
42 meta = {