Jump to content

Tmux: Difference between revisions

From NixOS Wiki
imported>Srid
Actually this is home-manager
Pigs (talk | contribs)
m Add category CLI Applications, link to pkgs
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
''tmux'' is a "terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. ''tmux'' may be detached from a screen and continue running in the background, then later reattached."
[https://github.com/tmux/tmux/wiki tmux] is a "terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. ''tmux'' may be detached from a screen and continue running in the background, then later reattached."




== Global configuration ==
== Global configuration ==


''tmux'' can be configured globally from <code>/etc/nixos/configuration.nix</code>.
{{nixos:package|tmux}} can be configured globally from <code>/etc/nixos/configuration.nix</code>.


As an example:
As an example:
Line 11: Line 11:
   enable = true;
   enable = true;
   clock24 = true;
   clock24 = true;
   extraTmuxConf = '' # used for less common options, intelligently combines if defined in multiple places.
   extraConfig = '' # used for less common options, intelligently combines if defined in multiple places.
     ...
     ...
   '';
   '';
Line 17: Line 17:
</syntaxhighlight>
</syntaxhighlight>


Note that <code>extraTmuxConf</code> writes directly to <code>/etc/tmux.conf</code>
Note that <code>extraConfig</code> writes directly to <code>/etc/tmux.conf</code>
 
 
=== Using Plugins ===
 
 
Tmux plugins can be also configured using <code>programs.tmux.plugins</code>. They can be found as NixOS packages: [https://search.nixos.org/packages?type=packages&query=tmuxPlugins tmuxPlugins]. Each of the tmux plugin is run via <code>run-shell</code> automatically.
Some plugins need to be run after having had some custom configuration done>, but extraConfig gets executed after. For example <code>tmuxPlugins.cpu</code> needs the status line be declared before the plugin is run. For that scenario, <code>run-shell</code> can be added within <code>extraConfig</code>:
<syntaxhighlight lang="nix">
programs.tmux = {
  enable = true;
  extraConfig = ''
    ...
    set -g status-right '#[fg=black,bg=color15] #{cpu_percentage}  %H:%M '
    run-shell ${pkgs.tmuxPlugins.cpu}/share/tmux-plugins/cpu/cpu.tmux
  '';
}
</syntaxhighlight>


== Per-user configuration ==
== Per-user configuration ==


However, if you want to configure per user, you could use [[Home Manager]]. This also grants you with more options available directly through nix, as opposed to through an extra config option. Though it should be noted that a few of the options have different names.
However, if you want to configure per user, you could use [[Home Manager]]. This also grants you with more options available directly through nix, as opposed to through an extra config option. Though it should be noted that a few of the options have different names.
Example: https://github.com/srid/nix-config/blob/master/nix/home/tmux.nix


== See also ==
== See also ==
Line 29: Line 44:
* [https://wiki.archlinux.org/index.php/Tmux Arch Wiki page on tmux]
* [https://wiki.archlinux.org/index.php/Tmux Arch Wiki page on tmux]
* [https://github.com/tmux/tmux tmux repository]
* [https://github.com/tmux/tmux tmux repository]
[[Category:CLI Applications]]

Latest revision as of 16:56, 17 May 2025

tmux is a "terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached."


Global configuration

tmux can be configured globally from /etc/nixos/configuration.nix.

As an example:

programs.tmux = {
  enable = true;
  clock24 = true;
  extraConfig = '' # used for less common options, intelligently combines if defined in multiple places.
    ...
  '';
}

Note that extraConfig writes directly to /etc/tmux.conf


Using Plugins

Tmux plugins can be also configured using programs.tmux.plugins. They can be found as NixOS packages: tmuxPlugins. Each of the tmux plugin is run via run-shell automatically. Some plugins need to be run after having had some custom configuration done>, but extraConfig gets executed after. For example tmuxPlugins.cpu needs the status line be declared before the plugin is run. For that scenario, run-shell can be added within extraConfig:

programs.tmux = {
  enable = true;
  extraConfig = ''
    ...
    set -g status-right '#[fg=black,bg=color15] #{cpu_percentage}  %H:%M '
    run-shell ${pkgs.tmuxPlugins.cpu}/share/tmux-plugins/cpu/cpu.tmux
  '';
}

Per-user configuration

However, if you want to configure per user, you could use Home Manager. This also grants you with more options available directly through nix, as opposed to through an extra config option. Though it should be noted that a few of the options have different names.

See also