From e69b1e8da39c7da1e1b67a400f2e22b2b09042cc Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Wed, 18 Dec 2024 11:59:37 +0300 Subject: [PATCH] Tmux: Rewrite with replaceVars. --- home/file/default.nix | 2 +- home/file/tmux/default.nix | 19 +++++- home/file/tmux/module/Config.nix | 9 --- home/file/tmux/module/Copy.nix | 10 ---- home/file/tmux/module/Env.nix | 11 ---- home/file/tmux/module/Scroll.nix | 7 --- home/file/tmux/module/Session.nix | 13 ----- home/file/tmux/module/Split.nix | 33 ----------- home/file/tmux/module/Status.nix | 20 ------- home/file/tmux/module/Style.nix | 36 ------------ home/file/tmux/module/Window.nix | 16 ------ home/file/tmux/tmux.conf | 96 +++++++++++++++++++++++++++++++ home/file/waybar/default.nix | 1 + 13 files changed, 115 insertions(+), 158 deletions(-) delete mode 100644 home/file/tmux/module/Config.nix delete mode 100644 home/file/tmux/module/Copy.nix delete mode 100644 home/file/tmux/module/Env.nix delete mode 100644 home/file/tmux/module/Scroll.nix delete mode 100644 home/file/tmux/module/Session.nix delete mode 100644 home/file/tmux/module/Split.nix delete mode 100644 home/file/tmux/module/Status.nix delete mode 100644 home/file/tmux/module/Style.nix delete mode 100644 home/file/tmux/module/Window.nix create mode 100644 home/file/tmux/tmux.conf diff --git a/home/file/default.nix b/home/file/default.nix index 84225f05..646ee5fc 100644 --- a/home/file/default.nix +++ b/home/file/default.nix @@ -38,7 +38,7 @@ in ".config/nvim/init.vim".text = nvim.text; ".config/swappy/config".source = swappy.config; ".config/sway/config".text = sway.text; - ".config/tmux/tmux.conf".text = tmux.text; + ".config/tmux/tmux.conf".source = tmux.config; ".config/waybar/config".source = waybar.config; ".config/waybar/style.css".source = waybar.style; ".config/yazi/init.lua".source = yazi.init; diff --git a/home/file/tmux/default.nix b/home/file/tmux/default.nix index 7f756ad3..0be8ab8f 100644 --- a/home/file/tmux/default.nix +++ b/home/file/tmux/default.nix @@ -1,4 +1,19 @@ -{ util, config, ... }@args: +{ config, pkgs, ... }: +let + accent = config.module.style.color.accent; + bg = config.module.style.color.bg.regular; + fg = config.module.style.color.fg.light; + selectionBg = config.module.style.color.selection; + selectionFg = config.module.style.color.fg.dark; +in { - text = util.catText (util.ls ./module) args; + config = pkgs.replaceVars ./tmux.conf { + inherit + accent + bg + fg + selectionBg + selectionFg + ; + }; } diff --git a/home/file/tmux/module/Config.nix b/home/file/tmux/module/Config.nix deleted file mode 100644 index 3b7f4a7c..00000000 --- a/home/file/tmux/module/Config.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ ... }: -{ - text = '' - unbind-key C-b - set-option -g prefix C-[ - bind-key C-[ send-prefix - bind -n M-r source-file ~/.config/tmux/tmux.conf - ''; -} diff --git a/home/file/tmux/module/Copy.nix b/home/file/tmux/module/Copy.nix deleted file mode 100644 index 4377e195..00000000 --- a/home/file/tmux/module/Copy.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ ... }: -{ - text = '' - setw -g mode-keys vi - bind -n M-v copy-mode - bind -n M-p choose-buffer; - bind -T copy-mode-vi v send -X begin-selection - bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" - ''; -} diff --git a/home/file/tmux/module/Env.nix b/home/file/tmux/module/Env.nix deleted file mode 100644 index 513710ef..00000000 --- a/home/file/tmux/module/Env.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ ... }: -{ - text = '' - set -sg escape-time 0 - set-option -g default-terminal "tmux-256color" - set-option -g focus-events on - set-option -sa terminal-features "RGB" - set -g allow-passthrough on - set-option -g update-environment "SSH_CLIENT SSH_TTY DOCKER_CONFIG DOCKER_HOST DISPLAY XAUTHORITY BASH_PATH SWAY_SOCK TERM TERM_PROGRAM" - ''; -} diff --git a/home/file/tmux/module/Scroll.nix b/home/file/tmux/module/Scroll.nix deleted file mode 100644 index cf8a145b..00000000 --- a/home/file/tmux/module/Scroll.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ ... }: -{ - text = '' - bind -n M-K copy-mode -u - bind -n M-J send-keys Pagedown - ''; -} diff --git a/home/file/tmux/module/Session.nix b/home/file/tmux/module/Session.nix deleted file mode 100644 index 4cf290b1..00000000 --- a/home/file/tmux/module/Session.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ ... }: -{ - text = '' - bind -n M-z detach-client - bind -n M-Z detach-client -a - - bind -n M-, switch-client -p - bind -n M-. switch-client -n - bind -n M-g choose-session -Z - - set -g window-size smallest - ''; -} diff --git a/home/file/tmux/module/Split.nix b/home/file/tmux/module/Split.nix deleted file mode 100644 index 6bd1e752..00000000 --- a/home/file/tmux/module/Split.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ ... }: -let - stepHorizontal = 1; - stepVertical = 1; -in -{ - text = '' - bind -n M-\\ split-window -h -c "#{pane_current_path}" - bind -n M-- split-window -v -c "#{pane_current_path}" - bind -n M-= select-layout tiled - bind -n M-_ select-layout even-vertical - bind -n M-| select-layout even-horizontal - bind -n M-+ select-layout main-vertical - bind -n M-k resize-pane -U ${toString stepVertical} - bind -n M-j resize-pane -D ${toString stepVertical} - bind -n M-h resize-pane -L ${toString stepHorizontal} - bind -n M-l resize-pane -R ${toString stepHorizontal} - bind -n M-A swap-pane -U - bind -n M-W swap-pane -U - bind -n M-D swap-pane -D - bind -n M-S swap-pane -D - unbind '"' - unbind % - - bind -n M-a select-pane -L - bind -n M-d select-pane -R - bind -n M-w select-pane -U - bind -n M-s select-pane -D - - bind -n M-c kill-pane - bind -n M-C kill-pane -a - ''; -} diff --git a/home/file/tmux/module/Status.nix b/home/file/tmux/module/Status.nix deleted file mode 100644 index e319118a..00000000 --- a/home/file/tmux/module/Status.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ ... }: -{ - text = '' - bind-key -n M-f set-option -g status; - set -g status-left-length 50 - set -g status-position bottom - set -g status-justify left - - set -g status-left "#[bold] #H-#S #[default]" - set -g status-right "" - - set-window-option -g window-status-separator "" - - setw -g window-status-current-format " #W " - setw -g window-status-format " #W " - - set-window-option -g visual-bell off - setw -g window-status-bell-style "bold blink" - ''; -} diff --git a/home/file/tmux/module/Style.nix b/home/file/tmux/module/Style.nix deleted file mode 100644 index 1053d2f2..00000000 --- a/home/file/tmux/module/Style.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ config, ... }: -let - accent = config.module.style.color.accent; - bg = config.module.style.color.bg.regular; - fg = config.module.style.color.fg.light; - selectionBg = config.module.style.color.selection; - selectionFg = config.module.style.color.fg.dark; -in -{ - # ISSUE: No way to specify `choose` mode style. - # SEE: https://github.com/tmux/tmux/issues/4264 - text = '' - set -g mode-style "fg=#${fg} bg=#${bg} bold" - - setw -g window-status-current-style "fg=#${accent} bold" - setw -g window-status-style "" - - set -g pane-border-style "fg=#${bg}" - set -g pane-active-border-style "fg=#${accent}" - - set -g status-style "fg=#${fg}" - - set -g menu-style "fg=#${fg}" - set -g menu-selected-style "fg=#${fg} bg=#${bg} bold" - set -g menu-border-style "fg=#${bg}" - - set -g popup-style "fg=#${fg}" - set -g popup-border-style "fg=#${bg}" - - set -g display-panes-colour "#${bg}" - set -g display-panes-active-colour "#${accent}" - - set -g copy-mode-position-style "fg=#${selectionBg} bg=#${selectionFg} bold" - set -g copy-mode-selection-style "fg=#${selectionFg} bg=#${selectionBg} bold" - ''; -} diff --git a/home/file/tmux/module/Window.nix b/home/file/tmux/module/Window.nix deleted file mode 100644 index 5adfeb27..00000000 --- a/home/file/tmux/module/Window.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ ... }: -{ - text = '' - bind -n M-Escape new-window -c "#{pane_current_path}" - bind -n M-t new-window -c "#{pane_current_path}" - - bind -n M-x kill-window - bind -n M-X kill-window -a - - bind -n M-e next-window - bind -n M-q previous-window - - bind -n M-E swap-window -t +1\; select-window -t +1 - bind -n M-Q swap-window -t -1\; select-window -t -1 - ''; -} diff --git a/home/file/tmux/tmux.conf b/home/file/tmux/tmux.conf new file mode 100644 index 00000000..46563da8 --- /dev/null +++ b/home/file/tmux/tmux.conf @@ -0,0 +1,96 @@ +# Config. +unbind-key C-b +set-option -g prefix C-[ +bind-key C-[ send-prefix +bind -n M-r source-file ~/.config/tmux/tmux.conf + +# Copy. +setw -g mode-keys vi +bind -n M-v copy-mode +bind -n M-p choose-buffer; +bind -T copy-mode-vi v send -X begin-selection +bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" + +# Env. +set -sg escape-time 0 +set-option -g default-terminal "tmux-256color" +set-option -g focus-events on +set-option -sa terminal-features "RGB" +set -g allow-passthrough on +set-option -g update-environment "SSH_CLIENT SSH_TTY DOCKER_CONFIG DOCKER_HOST DISPLAY XAUTHORITY BASH_PATH SWAY_SOCK TERM TERM_PROGRAM" + +# Scroll. +bind -n M-K copy-mode -u +bind -n M-J send-keys Pagedown + +# Session. +bind -n M-z detach-client +bind -n M-Z detach-client -a +bind -n M-, switch-client -p +bind -n M-. switch-client -n +bind -n M-g choose-session -Z +set -g window-size smallest + +# Split. +bind -n M-\\ split-window -h -c "#{pane_current_path}" +bind -n M-- split-window -v -c "#{pane_current_path}" +bind -n M-= select-layout tiled +bind -n M-_ select-layout even-vertical +bind -n M-| select-layout even-horizontal +bind -n M-+ select-layout main-vertical +bind -n M-k resize-pane -U 1 +bind -n M-j resize-pane -D 1 +bind -n M-h resize-pane -L 1 +bind -n M-l resize-pane -R 1 +bind -n M-A swap-pane -U +bind -n M-W swap-pane -U +bind -n M-D swap-pane -D +bind -n M-S swap-pane -D +unbind '"' +unbind % +bind -n M-a select-pane -L +bind -n M-d select-pane -R +bind -n M-w select-pane -U +bind -n M-s select-pane -D +bind -n M-c kill-pane +bind -n M-C kill-pane -a + +# Status. +bind-key -n M-f set-option -g status; +set -g status-left-length 50 +set -g status-position bottom +set -g status-justify left +set -g status-left "#[bold] #H-#S #[default]" +set -g status-right "" +set-window-option -g window-status-separator "" +setw -g window-status-current-format " #W " +setw -g window-status-format " #W " +set-window-option -g visual-bell off +setw -g window-status-bell-style "bold blink" + +# Style. +set -g mode-style "fg=#@fg@ bg=#@bg@ bold" +setw -g window-status-current-style "fg=#@accent@ bold" +setw -g window-status-style "" +set -g pane-border-style "fg=#@bg@" +set -g pane-active-border-style "fg=#@accent@" +set -g status-style "fg=#@fg@" +set -g menu-style "fg=#@fg@" +set -g menu-selected-style "fg=#@fg@ bg=#@bg@ bold" +set -g menu-border-style "fg=#@bg@" +set -g popup-style "fg=#@fg@" +set -g popup-border-style "fg=#@bg@" +set -g display-panes-colour "#@bg@" +set -g display-panes-active-colour "#@accent@" +set -g copy-mode-position-style "fg=#@selectionBg@ bg=#@selectionFg@ bold" +set -g copy-mode-selection-style "fg=#@selectionFg@ bg=#@selectionBg@ bold" + +# Window. +bind -n M-Escape new-window -c "#{pane_current_path}" +bind -n M-t new-window -c "#{pane_current_path}" +bind -n M-x kill-window +bind -n M-X kill-window -a +bind -n M-e next-window +bind -n M-q previous-window +bind -n M-E swap-window -t +1\; select-window -t +1 +bind -n M-Q swap-window -t -1\; select-window -t -1 diff --git a/home/file/waybar/default.nix b/home/file/waybar/default.nix index 50252c06..5e08b082 100644 --- a/home/file/waybar/default.nix +++ b/home/file/waybar/default.nix @@ -21,6 +21,7 @@ let borderSize = "${toString config.module.style.window.border}px"; styleRaw = pkgs.writeText "waybar-style-raw" (util.readFiles (util.ls ./style)); + # NOTE: Another option is to use var() like this: https://git.azahi.cc/nixfiles/tree/modules/firefox/default.nix#n41 https://git.azahi.cc/nixfiles/tree/modules/firefox/userContent.css style = pkgs.replaceVars styleRaw { inherit accent