2016-10-21 21:32:03 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inherit (pkgs) stdenv;
|
|
|
|
|
|
|
|
cfg = config.programs.tmux;
|
|
|
|
|
2016-12-18 13:04:31 +00:00
|
|
|
tmux = pkgs.runCommand pkgs.tmux.name
|
|
|
|
{ buildInputs = [ pkgs.makeWrapper ]; }
|
|
|
|
''
|
|
|
|
source $stdenv/setup
|
|
|
|
|
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper ${pkgs.tmux}/bin/tmux $out/bin/tmux \
|
|
|
|
--set __ETC_BASHRC_SOURCED "" \
|
|
|
|
--set __ETC_ZPROFILE_SOURCED "" \
|
|
|
|
--set __ETC_ZSHENV_SOURCED "" \
|
|
|
|
--set __ETC_ZSHRC_SOURCED "" \
|
|
|
|
--add-flags -f --add-flags /etc/tmux.conf
|
|
|
|
'';
|
|
|
|
|
2017-01-02 07:21:27 +00:00
|
|
|
text = import ../lib/write-text.nix {
|
2016-11-06 22:38:42 +00:00
|
|
|
inherit lib;
|
|
|
|
mkTextDerivation = name: text: pkgs.writeText "tmux-options-${name}" text;
|
|
|
|
};
|
|
|
|
|
|
|
|
tmuxOptions = concatMapStringsSep "\n" (attr: attr.text) (attrValues cfg.tmuxOptions);
|
2016-10-21 21:32:03 +00:00
|
|
|
|
2016-11-07 21:47:17 +00:00
|
|
|
fzfTmuxSession = pkgs.writeScript "fzf-tmux-session" ''
|
|
|
|
#! ${stdenv.shell}
|
|
|
|
set -e
|
|
|
|
|
|
|
|
session=$(tmux list-sessions -F '#{session_name}' | fzf --query="$1" --exit-0)
|
|
|
|
tmux switch-client -t "$session"
|
|
|
|
'';
|
|
|
|
|
2016-10-21 21:32:03 +00:00
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
|
2016-12-12 22:38:53 +00:00
|
|
|
programs.tmux.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to configure tmux.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-10-21 21:32:03 +00:00
|
|
|
programs.tmux.enableSensible = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = true;
|
|
|
|
description = ''
|
2016-12-18 12:52:03 +00:00
|
|
|
Enable sensible configuration options for tmux.
|
2016-10-21 21:32:03 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-10-30 13:16:34 +00:00
|
|
|
programs.tmux.enableMouse = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = true;
|
|
|
|
description = ''
|
2016-12-18 12:52:03 +00:00
|
|
|
Enable mouse support for tmux.
|
2016-10-30 13:16:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-07 21:47:17 +00:00
|
|
|
programs.tmux.enableFzf = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = true;
|
|
|
|
description = ''
|
2016-12-18 12:52:03 +00:00
|
|
|
Enable fzf keybindings for selecting tmux sessions and panes.
|
2016-11-07 21:47:17 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-10-21 21:32:03 +00:00
|
|
|
programs.tmux.enableVim = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = true;
|
|
|
|
description = ''
|
2016-12-18 12:52:03 +00:00
|
|
|
Enable vim style keybindings for copy mode, and navigation of tmux panes.
|
2016-10-21 21:32:03 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-06 22:38:42 +00:00
|
|
|
programs.tmux.tmuxOptions = mkOption {
|
2016-10-21 21:32:03 +00:00
|
|
|
internal = true;
|
2016-11-06 22:38:42 +00:00
|
|
|
type = types.attrsOf (types.submodule text);
|
2016-10-21 21:32:03 +00:00
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
|
2016-12-18 12:52:03 +00:00
|
|
|
programs.tmux.tmuxConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
2016-10-21 21:32:03 +00:00
|
|
|
};
|
|
|
|
|
2016-12-12 22:38:53 +00:00
|
|
|
config = mkIf cfg.enable {
|
2016-10-21 21:32:03 +00:00
|
|
|
|
2016-12-18 13:04:31 +00:00
|
|
|
environment.systemPackages =
|
|
|
|
[ # Include wrapped tmux package.
|
|
|
|
tmux
|
|
|
|
];
|
|
|
|
|
2016-12-18 12:52:03 +00:00
|
|
|
environment.etc."tmux.conf".text = ''
|
|
|
|
${tmuxOptions}
|
|
|
|
${cfg.tmuxConfig}
|
|
|
|
|
|
|
|
source-file -q /etc/tmux.conf.local
|
|
|
|
'';
|
|
|
|
|
2016-11-06 22:38:42 +00:00
|
|
|
programs.tmux.tmuxOptions.login-shell.text = if stdenv.isDarwin then ''
|
2017-01-10 19:59:19 +00:00
|
|
|
set -g default-command "${pkgs.reattach-to-user-namespace}/bin/reattach-to-user-namespace ${config.environment.loginShell}"
|
2016-11-03 22:28:33 +00:00
|
|
|
'' else ''
|
2016-12-18 13:04:31 +00:00
|
|
|
set -g default-command "${config.environment.loginShell}"
|
2016-11-03 22:28:33 +00:00
|
|
|
'';
|
2016-10-21 21:32:03 +00:00
|
|
|
|
2016-12-18 12:52:03 +00:00
|
|
|
programs.tmux.tmuxOptions.sensible.text = mkIf cfg.enableSensible ''
|
2016-10-21 21:32:03 +00:00
|
|
|
set -g default-terminal "screen-256color"
|
|
|
|
setw -g aggressive-resize on
|
|
|
|
|
|
|
|
set -g base-index 1
|
|
|
|
set -g renumber-windows on
|
|
|
|
|
|
|
|
set -g status-keys emacs
|
|
|
|
set -s escape-time 0
|
|
|
|
|
|
|
|
bind c new-window -c '#{pane_current_path}'
|
|
|
|
bind % split-window -v -c '#{pane_current_path}'
|
|
|
|
bind '"' split-window -h -c '#{pane_current_path}'
|
|
|
|
|
|
|
|
# TODO: make these interactive
|
|
|
|
bind C new-session
|
|
|
|
bind S switch-client -l
|
|
|
|
|
|
|
|
# set -g status-utf8 on
|
|
|
|
# set -g utf8 on
|
2016-12-18 12:52:03 +00:00
|
|
|
'';
|
2016-10-21 21:32:03 +00:00
|
|
|
|
2016-11-06 22:38:42 +00:00
|
|
|
programs.tmux.tmuxOptions.mouse.text = mkIf cfg.enableMouse ''
|
2016-10-30 13:16:34 +00:00
|
|
|
set -g mouse on
|
|
|
|
setw -g mouse on
|
|
|
|
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
|
|
|
|
'';
|
|
|
|
|
2016-11-07 21:47:17 +00:00
|
|
|
programs.tmux.tmuxOptions.fzf.text = mkIf cfg.enableFzf ''
|
|
|
|
bind-key -n M-p run "tmux split-window -p 40 -c '#{pane_current_path}' 'tmux send-keys -t #{pane_id} \"$(fzf -m | paste -sd\\ -)\"'"
|
|
|
|
bind-key -n M-s run "tmux split-window -p 40 'tmux send-keys -t #{pane_id} \"$(${fzfTmuxSession})\"'"
|
|
|
|
'';
|
|
|
|
|
2016-11-06 22:38:42 +00:00
|
|
|
programs.tmux.tmuxOptions.vim.text = mkIf cfg.enableVim (''
|
2016-10-21 21:32:03 +00:00
|
|
|
setw -g mode-keys vi
|
|
|
|
|
|
|
|
bind h select-pane -L
|
|
|
|
bind j select-pane -D
|
|
|
|
bind k select-pane -U
|
|
|
|
bind l select-pane -R
|
|
|
|
bind s split-window -v -c '#{pane_current_path}'
|
|
|
|
bind v split-window -h -c '#{pane_current_path}'
|
2016-10-30 13:16:34 +00:00
|
|
|
|
2017-06-04 17:20:19 +00:00
|
|
|
bind-key -T copy-mode-vi p send-keys -X copy-pipe-and-cancel "tmux paste-buffer"
|
|
|
|
bind-key -T copy-mode-vi v send-keys -X begin-selection
|
2016-11-05 15:54:04 +00:00
|
|
|
'' + optionalString stdenv.isLinux ''
|
2017-06-04 17:20:19 +00:00
|
|
|
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
|
2016-11-05 15:54:04 +00:00
|
|
|
'' + optionalString stdenv.isDarwin ''
|
2017-06-04 17:20:19 +00:00
|
|
|
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "${pkgs.reattach-to-user-namespace}/bin/reattach-to-user-namespace pbcopy"
|
2016-10-30 13:16:34 +00:00
|
|
|
'');
|
2016-10-21 21:32:03 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|