From ed7ac4d7348f23694262c0adf4299801eee6ca29 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Mon, 4 Mar 2024 12:15:12 +0300 Subject: [PATCH] Tmux : Use single file for syntax highlight. --- module/common/Tmux.nix | 22 +------ module/common/tmux/Buffer.nix | 17 ------ module/common/tmux/Environment.nix | 6 -- module/common/tmux/Pane.nix | 24 -------- module/common/tmux/Session.nix | 15 ----- module/common/tmux/Statusbar.nix | 22 ------- module/common/tmux/Window.nix | 19 ------ module/common/tmux/tmux.conf | 95 ++++++++++++++++++++++++++++++ 8 files changed, 96 insertions(+), 124 deletions(-) delete mode 100644 module/common/tmux/Buffer.nix delete mode 100644 module/common/tmux/Environment.nix delete mode 100644 module/common/tmux/Pane.nix delete mode 100644 module/common/tmux/Session.nix delete mode 100644 module/common/tmux/Statusbar.nix delete mode 100644 module/common/tmux/Window.nix create mode 100644 module/common/tmux/tmux.conf diff --git a/module/common/Tmux.nix b/module/common/Tmux.nix index e9a6a60..5cd2290 100644 --- a/module/common/Tmux.nix +++ b/module/common/Tmux.nix @@ -1,26 +1,6 @@ { ... }: { - imports = [ - ./tmux/Buffer.nix - ./tmux/Environment.nix - ./tmux/Pane.nix - ./tmux/Session.nix - ./tmux/Statusbar.nix - ./tmux/Window.nix - ]; - programs.tmux = { enable = true; - extraConfig = '' - # Remap to . - unbind-key C-b - set-option -g prefix C-t - bind-key C-t send-prefix - - # Disable escape delay. - set -sg escape-time 0 - - # Reload config. - bind -n M-r source-file /etc/tmux.conf - ''; + extraConfig = builtins.readFile ./tmux/tmux.conf; }; } diff --git a/module/common/tmux/Buffer.nix b/module/common/tmux/Buffer.nix deleted file mode 100644 index fa9c92e..0000000 --- a/module/common/tmux/Buffer.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ ... }: { - programs.tmux.extraConfig = '' - # Scroll. - bind -n M-p copy-mode -u - bind -n M-n send-keys Pagedown - - # Copy mode. - 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" - - # Selection style. - set -g mode-style 'fg=black,bg=yellow bold' - ''; -} diff --git a/module/common/tmux/Environment.nix b/module/common/tmux/Environment.nix deleted file mode 100644 index 9c9a997..0000000 --- a/module/common/tmux/Environment.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ ... }: { - programs.tmux.extraConfig = '' - # Update environment from client. - set-option -g update-environment "SSH_CLIENT SSH_TTY DOCKER_CONFIG DOCKER_HOST DISPLAY XAUTHORITY" - ''; -} diff --git a/module/common/tmux/Pane.nix b/module/common/tmux/Pane.nix deleted file mode 100644 index adb3be6..0000000 --- a/module/common/tmux/Pane.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ ... }: { - programs.tmux.extraConfig = '' - # Remap split keys. - 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-W resize-pane -U 1 - bind -n M-S resize-pane -D 1 - bind -n M-A resize-pane -L 1 - bind -n M-D resize-pane -R 1 - unbind '"' - unbind % - - # Swith panes with alt + hjkl. - 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 - - # Close pane. - bind -n M-c kill-pane - bind -n M-C kill-pane -a - ''; -} diff --git a/module/common/tmux/Session.nix b/module/common/tmux/Session.nix deleted file mode 100644 index 220f486..0000000 --- a/module/common/tmux/Session.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ ... }: { - programs.tmux.extraConfig = '' - # Detach. - bind -n M-z detach-client - bind -n M-Z detach-client -a - - # Switch sessions. - bind -n M-9 switch-client -p - bind -n M-0 switch-client -n - bind -n M-g choose-session - - # Resize to smallest client. - set -g window-size smallest - ''; -} diff --git a/module/common/tmux/Statusbar.nix b/module/common/tmux/Statusbar.nix deleted file mode 100644 index 18d7328..0000000 --- a/module/common/tmux/Statusbar.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ ... }: { - programs.tmux.extraConfig = '' - # Statusbar. - set -g status-interval 2 - set -g status-position bottom - set -g status-justify left - set -g status-style 'bg=color236 fg=color187' - - set -g status-left ' #[bold]#H-#S #(count=$(tmux list-clients -t #S | wc -l); [ $${count} -gt 1 ] && echo "($${count}) ")' - set -g status-left-length 50 - set -g status-right ' #(head -c -1 /sys/class/power_supply/BAT*/capacity 2> /dev/null && echo -n "% ")#[fg=color187,bg=color239] %Y-%m-%d #[bg=color138,fg=black,bold] %H:%M ' - set -g status-right-length 50 - - setw -g window-status-current-style 'fg=black bg=color143 bold' - setw -g window-status-current-format ' #[fg=black]#W#[fg=black]#F ' - - setw -g window-status-style 'fg=black bg=color138' - setw -g window-status-format ' #[fg=black]#W#[fg=black] ' - - setw -g window-status-bell-style 'fg=black bg=white bold' - ''; -} diff --git a/module/common/tmux/Window.nix b/module/common/tmux/Window.nix deleted file mode 100644 index af19306..0000000 --- a/module/common/tmux/Window.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ ... }: { - programs.tmux.extraConfig = '' - # Create new window. - bind -n M-Escape new-window -c "#{pane_current_path}" - bind -n M-t new-window -c "#{pane_current_path}" # NOTE: for compatibility reasons. - - # Close window. - bind -n M-x kill-window - bind -n M-X kill-window -a - - # Switch window. - bind -n M-e next-window - bind -n M-q previous-window - - # Move 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/module/common/tmux/tmux.conf b/module/common/tmux/tmux.conf new file mode 100644 index 0000000..ebf2c33 --- /dev/null +++ b/module/common/tmux/tmux.conf @@ -0,0 +1,95 @@ +# Remap to . +unbind-key C-b +set-option -g prefix C-t +bind-key C-t send-prefix + +# Disable escape delay. +set -sg escape-time 0 + +# Reload config. +bind -n M-r source-file /etc/tmux.conf + +# Scroll. +bind -n M-p copy-mode -u +bind -n M-n send-keys Pagedown + +# Copy mode. +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" + +# Selection style. +set -g mode-style 'fg=black,bg=yellow bold' + +# Update environment from client. +set-option -g update-environment "SSH_CLIENT SSH_TTY DOCKER_CONFIG DOCKER_HOST DISPLAY XAUTHORITY" + +# Remap split keys. +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-W resize-pane -U 1 +bind -n M-S resize-pane -D 1 +bind -n M-A resize-pane -L 1 +bind -n M-D resize-pane -R 1 +unbind '"' +unbind % + +# Swith panes with alt + hjkl. +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 + +# Close pane. +bind -n M-c kill-pane +bind -n M-C kill-pane -a + +# Detach. +bind -n M-z detach-client +bind -n M-Z detach-client -a + +# Switch sessions. +bind -n M-9 switch-client -p +bind -n M-0 switch-client -n +bind -n M-g choose-session + +# Resize to smallest client. +set -g window-size smallest + +# Statusbar. +set -g status-interval 2 +set -g status-position bottom +set -g status-justify left +set -g status-style 'bg=color236 fg=color187' + +set -g status-left ' #[bold]#H-#S #(count=$(tmux list-clients -t #S | wc -l); [ $${count} -gt 1 ] && echo "($${count}) ")' +set -g status-left-length 50 +set -g status-right ' #(head -c -1 /sys/class/power_supply/BAT*/capacity 2> /dev/null && echo -n "% ")#[fg=color187,bg=color239] %Y-%m-%d #[bg=color138,fg=black,bold] %H:%M ' +set -g status-right-length 50 + +setw -g window-status-current-style 'fg=black bg=color143 bold' +setw -g window-status-current-format ' #[fg=black]#W#[fg=black]#F ' + +setw -g window-status-style 'fg=black bg=color138' +setw -g window-status-format ' #[fg=black]#W#[fg=black] ' + +setw -g window-status-bell-style 'fg=black bg=white bold' + +# Create new window. +bind -n M-Escape new-window -c "#{pane_current_path}" +bind -n M-t new-window -c "#{pane_current_path}" # NOTE: for compatibility reasons. + +# Close window. +bind -n M-x kill-window +bind -n M-X kill-window -a + +# Switch window. +bind -n M-e next-window +bind -n M-q previous-window + +# Move 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