diff --git a/home/opdavies/hosts/PW05CH3L.nix b/home/opdavies/hosts/PW05CH3L.nix index a7bb59da..23ee440d 100644 --- a/home/opdavies/hosts/PW05CH3L.nix +++ b/home/opdavies/hosts/PW05CH3L.nix @@ -6,11 +6,6 @@ }: { - homeManagerModules = { - tmux.enable = true; - tmux-sessionizer.enable = true; - }; - home = let remoteIpAddress = "192.168.1.111"; diff --git a/home/opdavies/hosts/lemp11.nix b/home/opdavies/hosts/lemp11.nix index c49b4a04..ffcd4415 100644 --- a/home/opdavies/hosts/lemp11.nix +++ b/home/opdavies/hosts/lemp11.nix @@ -1,7 +1 @@ -{ ... }: - -{ - homeManagerModules = { - tmux-sessionizer.enable = true; - }; -} +{ } diff --git a/home/opdavies/hosts/t480.nix b/home/opdavies/hosts/t480.nix index 178aca38..ee73bb15 100644 --- a/home/opdavies/hosts/t480.nix +++ b/home/opdavies/hosts/t480.nix @@ -1,11 +1,6 @@ { config, pkgs, ... }: { - homeManagerModules = { - tmux.enable = true; - tmux-sessionizer.enable = true; - }; - home.packages = with pkgs; [ backup-websites displayselect diff --git a/home/opdavies/hosts/t490.nix b/home/opdavies/hosts/t490.nix index 1b8c01fd..a9db00d6 100644 --- a/home/opdavies/hosts/t490.nix +++ b/home/opdavies/hosts/t490.nix @@ -1,11 +1,6 @@ { pkgs, ... }: { - homeManagerModules = { - tmux.enable = true; - tmux-sessionizer.enable = true; - }; - home.packages = with pkgs; [ displayselect isync diff --git a/hosts/PW05CH3L/configuration.nix b/hosts/PW05CH3L/configuration.nix index 084ed3cc..ef319ec3 100644 --- a/hosts/PW05CH3L/configuration.nix +++ b/hosts/PW05CH3L/configuration.nix @@ -7,6 +7,7 @@ ../../modules/mixins/docker.nix ../../modules/mixins/fzf.nix ../../modules/mixins/phpactor + ../../modules/mixins/tmux.nix ../common ../../users/opdavies diff --git a/hosts/t480/configuration.nix b/hosts/t480/configuration.nix index 0aef3abf..3e75948f 100644 --- a/hosts/t480/configuration.nix +++ b/hosts/t480/configuration.nix @@ -20,6 +20,7 @@ ../../modules/mixins/pipewire.nix ../../modules/mixins/screenkey.nix ../../modules/mixins/thunar.nix + ../../modules/mixins/tmux.nix ../../modules/profiles/dwm ../../modules/profiles/xbanish.nix diff --git a/modules/home-manager/cli/default.nix b/modules/home-manager/cli/default.nix index ef52aa76..d2d9e8bd 100644 --- a/modules/home-manager/cli/default.nix +++ b/modules/home-manager/cli/default.nix @@ -5,8 +5,6 @@ ./bin ./git.nix ./starship.nix - ./tmux.nix - ./tmux-sessionizer.nix ./zsh ]; } diff --git a/modules/home-manager/cli/tmux-sessionizer.nix b/modules/home-manager/cli/tmux-sessionizer.nix deleted file mode 100644 index 72979f41..00000000 --- a/modules/home-manager/cli/tmux-sessionizer.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: - -with lib; - -{ - options.homeManagerModules.tmux-sessionizer.enable = mkEnableOption "Enable tmux-sessionizer"; - - config = mkIf config.homeManagerModules.tmux-sessionizer.enable { - home.packages = with pkgs; [ tmux-sessionizer ]; - - home.file."${config.xdg.configHome}/tmux-sessionizer/default".source = "${ - pkgs.writeShellApplication { - name = ".tmux-sessionizer"; - - runtimeInputs = with pkgs; [ - tmux - ]; - - text = '' - set +o errexit - set +o nounset - - if [[ "$PWD" == "$XDG_REPOS_DIR/os" || "$PWD" == "$XDG_REPOS_DIR/personal" ]]; then - clear - - return - fi - - tmux new-window -d -n scratch - nvim . - clear - ''; - } - }/bin/.tmux-sessionizer"; - }; -} diff --git a/modules/home-manager/cli/tmux.nix b/modules/home-manager/cli/tmux.nix deleted file mode 100644 index bdc2ac57..00000000 --- a/modules/home-manager/cli/tmux.nix +++ /dev/null @@ -1,97 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: - -with lib; - -let - inherit (pkgs) tmuxPlugins; -in -{ - options.homeManagerModules.tmux.enable = mkEnableOption "Enable tmux"; - - config = mkIf config.homeManagerModules.tmux.enable { - programs.tmux = { - enable = true; - - terminal = "tmux-256color"; - - extraConfig = '' - set-option -g status-keys "vi" - set-option -sa terminal-features "''${TERM}:RGB" - - bind -n S-Left resize-pane -L 2 - bind -n S-Right resize-pane -R 2 - bind -n S-Down resize-pane -D 1 - bind -n S-Up resize-pane -U 1 - - bind -n C-Left resize-pane -L 10 - bind -n C-Right resize-pane -R 10 - bind -n C-Down resize-pane -D 5 - bind -n C-Up resize-pane -U 5 - - # Status line customisation - set-option -g status-left "" - set-option -g status-right " #{session_name}" - set-option -g status-right-length 100 - set-option -g status-style "fg=#7C7D83 bg=default" - set-option -g window-status-activity-style none - set-option -g window-status-current-style "fg=#E9E9EA" - - bind c new-window -c "#{pane_current_path}" - - set -g base-index 1 - set -g pane-base-index 1 - set -g renumber-windows on - - # Break a pane into a new window. - bind-key b break-pane -d - bind-key J command-prompt -p "join pane from: " "join-pane -h -s '%%'" - - bind-key C-j choose-tree - - set-window-option -g mode-keys vi - bind -T copy-mode-vi v send-keys -X begin-selection - bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' - - bind C-j split-window -v "tmux list-sessions | sed -E 's/:.*$//' | grep -v \"^$(tmux display-message -p '#S')\$\" | fzf --reverse | xargs tmux switch-client -t" - - bind-key K run-shell 'tmux switch-client -n \; kill-session -t "$(tmux display-message -p "#S")" || tmux kill-session' - - # Allow clearing screen with ctrl-l by using C-l - bind C-l send-keys "C-l" - bind C-k send-keys "C-k" - - # Enable mouse support. - setw -g mouse on - - # Remove delay when switching Vim modes. - set -sg escape-time 0 - - set-option -g pane-active-border-style "fg=#1f2335" - set-option -g pane-border-style "fg=#1f2335" - - # Vim-like pane navigation. - bind ^ last-window - bind h select-pane -L - bind j select-pane -D - bind k select-pane -U - bind l select-pane -R - - bind-key -r f run-shell "tmux new-window tmux-sessionizer" - - bind-key -r D new-window -c "#{pane_current_path}" "[[ -e TODO.md ]] && nvim TODO.md || nvim ~/Documents/wiki/todo.txt" - bind-key -r N new-window "notes" - bind-key -r W split-window -h -c ~/Documents/wiki "nvim '+Telescope find_files'" - ''; - - plugins = [ - tmuxPlugins.vim-tmux-navigator - tmuxPlugins.yank - ]; - }; - }; -} diff --git a/modules/mixins/tmux.nix b/modules/mixins/tmux.nix new file mode 100644 index 00000000..7420a4d6 --- /dev/null +++ b/modules/mixins/tmux.nix @@ -0,0 +1,117 @@ +{ pkgs, ... }: + +{ + programs.tmux = { + enable = true; + + terminal = "tmux-256color"; + + extraConfig = '' + set-option -g status-keys "vi" + set-option -sa terminal-features "''${TERM}:RGB" + + bind -n S-Left resize-pane -L 2 + bind -n S-Right resize-pane -R 2 + bind -n S-Down resize-pane -D 1 + bind -n S-Up resize-pane -U 1 + + bind -n C-Left resize-pane -L 10 + bind -n C-Right resize-pane -R 10 + bind -n C-Down resize-pane -D 5 + bind -n C-Up resize-pane -U 5 + + # Status line customisation + set-option -g status-left "" + set-option -g status-right " #{session_name}" + set-option -g status-right-length 100 + set-option -g status-style "fg=#7C7D83 bg=default" + set-option -g window-status-activity-style none + set-option -g window-status-current-style "fg=#E9E9EA" + + bind c new-window -c "#{pane_current_path}" + + set -g base-index 1 + set -g pane-base-index 1 + set -g renumber-windows on + + # Break a pane into a new window. + bind-key b break-pane -d + bind-key J command-prompt -p "join pane from: " "join-pane -h -s '%%'" + + bind-key C-j choose-tree + + set-window-option -g mode-keys vi + bind -T copy-mode-vi v send-keys -X begin-selection + bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' + + bind C-j split-window -v "tmux list-sessions | sed -E 's/:.*$//' | grep -v \"^$(tmux display-message -p '#S')\$\" | fzf --reverse | xargs tmux switch-client -t" + + bind-key K run-shell 'tmux switch-client -n \; kill-session -t "$(tmux display-message -p "#S")" || tmux kill-session' + + # Allow clearing screen with ctrl-l by using C-l + bind C-l send-keys "C-l" + bind C-k send-keys "C-k" + + # Enable mouse support. + setw -g mouse on + + # Remove delay when switching Vim modes. + set -sg escape-time 0 + + set-option -g pane-active-border-style "fg=#1f2335" + set-option -g pane-border-style "fg=#1f2335" + + # Vim-like pane navigation. + bind ^ last-window + bind h select-pane -L + bind j select-pane -D + bind k select-pane -U + bind l select-pane -R + + bind-key -r f run-shell "tmux new-window tmux-sessionizer" + + bind-key -r D new-window -c "#{pane_current_path}" "[[ -e TODO.md ]] && nvim TODO.md || nvim ~/Documents/wiki/todo.txt" + bind-key -r N new-window "notes" + bind-key -r W split-window -h -c ~/Documents/wiki "nvim '+Telescope find_files'" + ''; + + plugins = with pkgs.tmuxPlugins; [ + vim-tmux-navigator + yank + ]; + }; + + home-manager.users.opdavies = + { config, ... }: + with pkgs; + { + home.packages = [ + tmux-sessionizer + ]; + + xdg.configFile."tmux-sessionizer/default".source = "${ + writeShellApplication { + name = ".tmux-sessionizer"; + + runtimeInputs = [ + tmux + ]; + + text = '' + set +o errexit + set +o nounset + + if [[ "$PWD" == "${config.xdg.userDirs.extraConfig.XDG_REPOS_DIR}/os" || "$PWD" == "${config.xdg.userDirs.extraConfig.XDG_REPOS_DIR}/personal" ]]; then + clear + + return + fi + + tmux new-window -d -n scratch + nvim . + clear + ''; + } + }/bin/.tmux-sessionizer"; + }; +}