From 37f704cc1973bfdb7fd76172d7f21f17489e08b5 Mon Sep 17 00:00:00 2001 From: Bryan Ramos Date: Sat, 18 May 2024 21:02:16 -0400 Subject: [PATCH] added tmux module --- .../desktop/modules/home-manager/home.nix | 2 + src/system/machines/vm/system.nix | 8 ++-- src/user/modules/bash/default.nix | 5 ++- src/user/modules/default.nix | 1 + .../gui/modules/wm/sway/config/shellHook.nix | 23 +++++++++-- .../gui/modules/wm/sway/config/sway.nix | 11 ++++- .../modules/gui/modules/wm/sway/default.nix | 2 +- src/user/modules/tmux/config/shellHook.nix | 9 ++++ src/user/modules/tmux/config/tmux.nix | 10 +++++ src/user/modules/tmux/default.nix | 41 +++++++++++++++++++ .../modules/utils/modules/vim/config/vimrc | 2 +- 11 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 src/user/modules/tmux/config/shellHook.nix create mode 100644 src/user/modules/tmux/config/tmux.nix create mode 100644 src/user/modules/tmux/default.nix diff --git a/src/system/machines/desktop/modules/home-manager/home.nix b/src/system/machines/desktop/modules/home-manager/home.nix index 6bc5c53..ebbb0df 100644 --- a/src/system/machines/desktop/modules/home-manager/home.nix +++ b/src/system/machines/desktop/modules/home-manager/home.nix @@ -23,6 +23,8 @@ gpg.enable = true; }; + tmux.enable = true; + utils = { enable = true; dev.enable = true; diff --git a/src/system/machines/vm/system.nix b/src/system/machines/vm/system.nix index 9495135..172c029 100644 --- a/src/system/machines/vm/system.nix +++ b/src/system/machines/vm/system.nix @@ -43,10 +43,10 @@ }; }; - fonts.packages = with pkgs; [ - terminus_font - terminus-nerdfont - ]; + #fonts.packages = with pkgs; [ + # terminus_font + # terminus-nerdfont + #]; security.sudo = { wheelNeedsPassword = false; diff --git a/src/user/modules/bash/default.nix b/src/user/modules/bash/default.nix index 6eb15bf..4ce8b1d 100644 --- a/src/user/modules/bash/default.nix +++ b/src/user/modules/bash/default.nix @@ -26,9 +26,10 @@ in eza = { enable = true; enableAliases = true; - } // optionalAttrs wm.enable { - icons = true; }; + #// optionalAttrs wm.enable { + # icons = true; + #}; }; }; } diff --git a/src/user/modules/default.nix b/src/user/modules/default.nix index 01abb97..69a284e 100644 --- a/src/user/modules/default.nix +++ b/src/user/modules/default.nix @@ -4,6 +4,7 @@ ./git ./gui ./security + ./tmux ./utils ]; } diff --git a/src/user/modules/gui/modules/wm/sway/config/shellHook.nix b/src/user/modules/gui/modules/wm/sway/config/shellHook.nix index 6591bcf..a8d0538 100644 --- a/src/user/modules/gui/modules/wm/sway/config/shellHook.nix +++ b/src/user/modules/gui/modules/wm/sway/config/shellHook.nix @@ -1,5 +1,22 @@ +{ lib, config, ... }: + +with lib; +let + tmux = config.modules.user.tmux; + +in '' -if [ -z "$DISPLAY" ] && [ "$(tty)" = "/dev/tty1" ]; then - exec sway -fi +case $- in + *i*) + if [ -z "$DISPLAY" ] && [ "$(tty)" = "/dev/tty1" ]; then + exec sway + fi + + ${optionalString tmux.enable '' + if [ -z "$DISPLAY" ] && [ -z "$TMUX" ]; then + exec tmux + fi + ''} + ;; +esac '' diff --git a/src/user/modules/gui/modules/wm/sway/config/sway.nix b/src/user/modules/gui/modules/wm/sway/config/sway.nix index d46e983..4143658 100644 --- a/src/user/modules/gui/modules/wm/sway/config/sway.nix +++ b/src/user/modules/gui/modules/wm/sway/config/sway.nix @@ -17,6 +17,10 @@ in ''; config = { + fonts = { + names = [ "Terminus" ]; + }; + output = { HDMI-A-1 = { resolution = "1920x1080"; @@ -49,8 +53,8 @@ in { position = "top"; statusCommand = ''while :; do echo "$(free -h | awk '/^Mem/ {print $3}') '|' $(date +'%I:%M:%S %p') '|' $(date +'%m-%d-%Y')"; sleep 1; done''; - fonts = { - names = [ "Noto Sans" ]; + fonts = { + names = [ "Terminus" ]; size = 10.0; }; colors = { @@ -82,6 +86,9 @@ in "${modifier}+Print" = ''exec sh -c 'grim -g "$(swaymsg -t get_tree | jq -j '"'"'.. | select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"'"'"')" ~/Pictures/screenshot-$(date +'%Y%m%d-%H%M%S').png' ''; "${modifier}+Shift+f" = "exec alacritty -e sh -c 'EDITOR=nvim ranger'"; "${modifier}+Shift+d" = "exec rofi -modi emoji -show emoji"; + "${modifier}+Shift+Return" = '' + exec alacritty --working-directory -e $(pwd) + ''; }; }; diff --git a/src/user/modules/gui/modules/wm/sway/default.nix b/src/user/modules/gui/modules/wm/sway/default.nix index f7c2696..e595f55 100644 --- a/src/user/modules/gui/modules/wm/sway/default.nix +++ b/src/user/modules/gui/modules/wm/sway/default.nix @@ -16,7 +16,7 @@ in }; programs.bash = { - profileExtra = import ./config/shellHook.nix; + profileExtra = import ./config/shellHook.nix { inherit config lib; }; shellAliases = { open = "xdg-open"; }; diff --git a/src/user/modules/tmux/config/shellHook.nix b/src/user/modules/tmux/config/shellHook.nix new file mode 100644 index 0000000..ff6cfd6 --- /dev/null +++ b/src/user/modules/tmux/config/shellHook.nix @@ -0,0 +1,9 @@ +'' +case $- in + *i*) + if [ -z "$DISPLAY" ] && [ -z "$TMUX" ]; then + exec tmux + fi + ;; +esac +'' diff --git a/src/user/modules/tmux/config/tmux.nix b/src/user/modules/tmux/config/tmux.nix new file mode 100644 index 0000000..d3ba11f --- /dev/null +++ b/src/user/modules/tmux/config/tmux.nix @@ -0,0 +1,10 @@ +'' +bind -n M-C source-file ~/.config/tmux/tmux.conf + +bind-key -n M-h select-pane -L +bind-key -n M-j select-pane -D +bind-key -n M-k select-pane -U +bind-key -n M-l select-pane -R + +bind-key -n M-q kill-pane +'' diff --git a/src/user/modules/tmux/default.nix b/src/user/modules/tmux/default.nix new file mode 100644 index 0000000..86ccd6c --- /dev/null +++ b/src/user/modules/tmux/default.nix @@ -0,0 +1,41 @@ +{ pkgs, lib, config, ... }: + +with lib; +let + cfg = config.modules.user.tmux; + gui = config.modules.user.gui.wm; + + wm = { + enable = builtins.any (mod: mod.enable or false) (builtins.attrValues gui); + }; + +in +{ options.modules.user.tmux = { enable = mkEnableOption "Enable tmux module"; }; + config = mkIf cfg.enable { + programs.bash = mkIf (!wm.enable) { + profileExtra = import ./config/shellHook.nix; + }; + + programs.tmux = { + enable = true; + newSession = true; + disableConfirmationPrompt = true; + keyMode = "vi"; + mouse = if wm.enable then true else false; + + prefix = "M"; + shell = "\${pkgs.bash}/bin/bash"; + + plugins = with pkgs.tmuxPlugins; [ + { + plugin = tilish; + extraConfig = '' + set -g @tilish-default 'tiled' + ''; + } + ]; + + extraConfig = import ./config/tmux.nix; + }; + }; +} diff --git a/src/user/modules/utils/modules/vim/config/vimrc b/src/user/modules/utils/modules/vim/config/vimrc index e8d3055..704e120 100644 --- a/src/user/modules/utils/modules/vim/config/vimrc +++ b/src/user/modules/utils/modules/vim/config/vimrc @@ -70,7 +70,7 @@ nnoremap ga :Git add nnoremap gc :Git commit nnoremap gd :Git diff -nnoremap e :Explore +nnoremap e :Ex nnoremap / :Rg nnoremap bd :bd