2023-04-25 18:55:15 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.my.programs.tmux;
|
2023-04-26 08:57:59 +02:00
|
|
|
|
2023-06-30 20:50:25 +02:00
|
|
|
fzf1 = pkgs.writeShellApplication {
|
|
|
|
name = "fzf1";
|
|
|
|
runtimeInputs = with pkgs; [ coreutils fzf ];
|
2023-04-26 08:57:59 +02:00
|
|
|
text = ''
|
|
|
|
#!/usr/bin/env bash
|
2023-04-28 08:11:44 +02:00
|
|
|
|
2023-06-30 20:50:25 +02:00
|
|
|
options=$(fzf --filter "''$*" < /dev/stdin)
|
2023-04-26 08:57:59 +02:00
|
|
|
|
2023-04-26 11:23:28 +02:00
|
|
|
if [[ -z $options ]]; then
|
2023-04-26 11:43:34 +02:00
|
|
|
exit 1
|
2023-04-26 11:23:28 +02:00
|
|
|
elif [[ $(wc -l <<< "$options") -eq 1 ]]; then
|
|
|
|
selected="$options"
|
2023-04-26 08:57:59 +02:00
|
|
|
else
|
2023-04-26 11:43:34 +02:00
|
|
|
selected=$(echo "$options" | fzf --query="$*")
|
2023-04-26 08:57:59 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $selected ]]; then
|
2023-04-26 11:43:34 +02:00
|
|
|
exit 0
|
2023-04-26 08:57:59 +02:00
|
|
|
fi
|
|
|
|
|
2023-06-30 20:50:25 +02:00
|
|
|
echo "$selected"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tmux-switch = pkgs.writeShellApplication {
|
|
|
|
name = "tmux-switch";
|
|
|
|
runtimeInputs = with pkgs; [ tmux ];
|
|
|
|
text = ''
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
if [[ -z ''${TMUX+x} ]]; then
|
|
|
|
tmux attach -t "$1"
|
|
|
|
else
|
|
|
|
tmux switch-client -t "$1"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-04 11:44:55 +02:00
|
|
|
tmux-sessionizer = pkgs.writeFishApplication {
|
2023-06-30 20:50:25 +02:00
|
|
|
name = "ts";
|
2023-07-04 11:44:55 +02:00
|
|
|
runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd fzf1 tmux-switch ];
|
|
|
|
text = readFile ./tmux-sessionizer/script.fish;
|
|
|
|
completions = readFile ./tmux-sessionizer/completions.fish;
|
2023-06-30 20:50:25 +02:00
|
|
|
};
|
|
|
|
|
2023-07-04 11:44:55 +02:00
|
|
|
tmux-attach = pkgs.writeFishApplication {
|
2023-06-30 20:50:25 +02:00
|
|
|
name = "ta";
|
2023-07-04 11:44:55 +02:00
|
|
|
runtimeInputs = with pkgs; [ tmux fzf1 tmux-switch ];
|
|
|
|
text = readFile ./tmux-attach/script.fish;
|
|
|
|
completions = readFile ./tmux-attach/completions.fish;
|
2023-04-26 08:57:59 +02:00
|
|
|
};
|
|
|
|
|
2023-04-25 18:55:15 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.programs.tmux = {
|
|
|
|
enable = mkEnableOption "tmux";
|
|
|
|
autoAttach = mkEnableOption "autoAttach";
|
2023-04-28 08:11:44 +02:00
|
|
|
keybinds = mkOption {
|
|
|
|
type = with types; attrsOf (attrsOf string);
|
|
|
|
default = { };
|
|
|
|
description = "Keybinds for tmux";
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
prefix = {
|
|
|
|
"-" = "split-window -v";
|
|
|
|
"|" = "split-window -h";
|
|
|
|
};
|
|
|
|
copy-mode-vi = {
|
|
|
|
"v" = "send -X begin-selection";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-04-25 18:55:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
my.shell.abbreviations.t = "tmux";
|
2023-04-26 08:57:59 +02:00
|
|
|
|
2023-06-30 20:50:25 +02:00
|
|
|
home-manager.users.moritz.home.packages = [
|
|
|
|
tmux-sessionizer
|
|
|
|
tmux-attach
|
|
|
|
];
|
2023-04-25 18:55:15 +02:00
|
|
|
home-manager.users.moritz.programs = {
|
2023-04-26 08:57:59 +02:00
|
|
|
tmux = {
|
|
|
|
enable = true;
|
|
|
|
clock24 = true;
|
|
|
|
customPaneNavigationAndResize = true;
|
|
|
|
keyMode = "vi";
|
|
|
|
mouse = true;
|
|
|
|
prefix = "C-Space";
|
|
|
|
sensibleOnTop = false;
|
|
|
|
plugins = with pkgs.tmuxPlugins; [
|
|
|
|
sensible
|
|
|
|
tmux-fzf
|
2023-04-28 08:12:15 +02:00
|
|
|
vim-tmux-navigator
|
2023-04-26 08:57:59 +02:00
|
|
|
yank
|
|
|
|
];
|
2023-04-28 08:11:44 +02:00
|
|
|
extraConfig =
|
|
|
|
let
|
|
|
|
mkKeybind = table: mapAttrsToList (keybind: value: "bind-key -T ${table} '${keybind}' ${value}");
|
|
|
|
keybinds = flatten (mapAttrsToList mkKeybind cfg.keybinds);
|
|
|
|
in
|
|
|
|
''
|
|
|
|
# Keybinds
|
|
|
|
${concatStringsSep "\n" keybinds}
|
|
|
|
'';
|
2023-04-26 08:57:59 +02:00
|
|
|
};
|
2023-04-25 18:55:15 +02:00
|
|
|
fzf.tmux.enableShellIntegration = true;
|
|
|
|
fish.interactiveShellInit =
|
|
|
|
let
|
|
|
|
insideVariables = [ "$TMUX" "$INSIDE_EMACS" "$EMACS" "$VIM" "$VSCODE_RESOLVING_ENVIRONMENT" ];
|
|
|
|
insideVariableMissing = concatStringsSep " && " (map (x: "test -z ${x}") insideVariables);
|
|
|
|
in
|
|
|
|
mkIf cfg.autoAttach
|
|
|
|
''
|
|
|
|
if ! fish_is_root_user && test "$TERM_PROGRAM" != 'vscode' && ${insideVariableMissing}
|
|
|
|
if test -z $tmux_autostarted
|
|
|
|
set -x tmux_autostarted true
|
2023-04-26 08:57:59 +02:00
|
|
|
ts
|
2023-04-25 18:55:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|