Tmux: Difference between revisions

m Split blocks for more obvious reading
Add installation section and make sections follow MoS better.
 
Line 1: Line 1:
[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."
[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."


== Installation ==


== Global configuration ==
==== Shell ====
To temporarily use tmux in a shell environment without modifying your system configuration, you can run:
{{Code|$ nix-shell -p tmux|lang=bash}}
This makes the tmux available in your current shell. You can then launch tmux by typing <code>tmux</code>.
 
==== System setup ====
To install tmux system-wide, making it available to all users, add the following to your configuration:{{File|3=environment.systemPackages = [
  pkgs.tmux
];|name=/etc/nixos/configuration.nix|lang=nix}}
Alternatively, enable the NixOS module to manage tmux declaratively:
{{File|3=programs.tmux.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}}After rebuilding your system with <code>nixos-rebuild switch</code>, tmux will be installed and accessible.
 
== Configuration ==


{{nixos:package|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:
<syntaxhighlight lang="nix">
{{File|3=programs.tmux = {
programs.tmux = {
   enable = true;
   enable = true;
   clock24 = true;
   clock24 = true;
Line 14: Line 26:
     ...
     ...
   '';
   '';
};
};|name=/etc/nixos/configuration.nix|lang=nix}}
</syntaxhighlight>


Note that <code>extraConfig</code> writes directly to <code>/etc/tmux.conf</code>
Note that <code>extraConfig</code> writes directly to <code>/etc/tmux.conf</code>


 
==== Using Plugins ====
=== 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.
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>:
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">
{{File|3=programs.tmux = {
programs.tmux = {
   enable = true;
   enable = true;
   extraConfig = ''
   extraConfig = ''
Line 33: Line 41:
     run-shell ${pkgs.tmuxPlugins.cpu}/share/tmux-plugins/cpu/cpu.tmux
     run-shell ${pkgs.tmuxPlugins.cpu}/share/tmux-plugins/cpu/cpu.tmux
   '';
   '';
};
};|name=/etc/nixos/configuration.nix|lang=nix}}
</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.