nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
7.07k stars 1.82k forks source link

bug: tmux power theme cannot be applied in tmux #4894

Open D3vil0p3r opened 10 months ago

D3vil0p3r commented 10 months ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

tmux_power_theme does not work when applied in extraConfig. It works only if I create manually a .tmux.conf file.

extraConfig of tmux HM module seems to not apply anything of tmux_power_theme as for example the theme, the upload and download speed, despite set to true.

default.nix

{pkgs, shell, username, ...}:
{
  home-manager.users.${username} = { pkgs, ... }: {

    programs.tmux = {
      enable = true;
      plugins = with pkgs.tmuxPlugins; [
        net-speed
        power-theme
        prefix-highlight
        sensible
        yank
      ];
      extraConfig = ''
        # start a non-login shell
        set -g default-command "$SHELL"

        # Set the base index for windows to 1 instead of 0
        set -g base-index 1
        setw -g pane-base-index 1

        # Plugin Customizaion
        set -g @tmux_power_theme 'everforest'
        set -g status-right   "#{playerctl_full}"
        set -g @tmux_power_show_upload_speed true
        set -g @tmux_power_show_download_speed true
        # 'L' for left only, 'R' for right only and 'LR' for both
        set -g @tmux_power_prefix_highlight_pos 'LR'
        set -g @tmux_power_date_format '%F'
        set -g @tmux_power_time_format '%T'

        # Set the prefix key to Ctrl+s
        set -g prefix C-s
        unbind C-b
        bind C-s send-prefix

        # Set a more informative status bar with key indication
        set -g status-right "#(tmux-power) #[fg=white,bold][#{?client_prefix,Prefix,}#{?vi,Vi,}#{?copy_mode,Copy,}#[default]]"

        # re-number windows when one is closed
        set -g renumber-windows on

        # Remapping prefix
        unbind-key C-b
        set-option -g prefix C-s # setting prefix from C-b to C-s
        bind-key C-s send-prefix # ensure that we can send Ctrl-s to other apps or the shell

        # Split panel with the current path
        unbind % 
        unbind '"'
        bind '\' split-window -h -c '#{pane_current_path}'           
        bind '-' split-window -v -c '#{pane_current_path}'

        # Use Alt-arrow keys without prefix key to switch panes
        bind -n M-Left select-pane -L
        bind -n M-Right select-pane -R
        bind -n M-Up select-pane -U
        bind -n M-Down select-pane -D

        # Resize panes using Shift+arrow keys
        bind -n S-Left resize-pane -L 5
        bind -n S-Right resize-pane -R 5
        bind -n S-Up resize-pane -U 5
        bind -n S-Down resize-pane -D 5

        # Shift arrow to switch windows
        # Switch to next window with prefix + n
        bind-key n next-window

        # Switch to last window with prefix + l
        bind-key l previous-window

        # Pressed key highlight
        set -g status-right '#{prefix_highlight} | %a %Y-%m-%d %H:%M'

        # Vim style pane selection
        bind h select-pane -L
        bind j select-pane -D
        bind k select-pane -U
        bind l select-pane -R

        # Use Alt-vim keys without prefix key to switch panes
        bind -n M-h select-pane -L
        bind -n M-j select-pane -D
        bind -n M-k select-pane -U
        bind -n M-l select-pane -R

        ## Capture current tmux buffer and copy it to system clipboard with prefix + 'Ctrl + c'
        bind C-c run "tmux save-buffer - | xclip -i -sel clipboard"

        ## Optional - paste from system clipboard to tmux session with prefix + 'Ctrl + v'

        bind C-v run "tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"

        #copy and paste vim style

        ## Enable vi-copy-mode
        setw -g mode-keys vi

        # Turn off mouse and use vim keys for navigations
        # turn this on if you want to use touchpad or mouse to scroll through terminal
        set -g mouse on
        #bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'"

        ## changing the key to enter copy mode from `[` to `ESC`
        unbind [
        bind Escape copy-mode

        ## unbind p and set it to paste from buffer
        #unbind p
        #bind p paste-buffer

        ## set keys for visual mode (v) and yank/copy (y)
        bind-key -Tcopy-mode-vi 'v' send -X begin-selection
        bind-key -Tcopy-mode-vi 'y' send -X copy-pipe-and-cancel 'xclip -in -selection clipboard'

        ## Copy using XCLIP
        bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"

        # Reload the configuration file
        unbind r
        bind r source-file ~/.tmux.conf \; display "Reloaded tmux config!"

        set-option -g status-interval 1
        set-option -g automatic-rename on
        set-option -g automatic-rename-format '#{b:pane_current_path}'
        set -g allow-rename on

        # activity notifications
        setw -g monitor-activity on
        setw -g visual-activity on

        # Set the scrollback buffer size to 50,000 lines
        set -g history-limit 50000

        # Enable vi mode for easier navigation
        set-window-option -g mode-keys vi

        # Improve terminal colors
        set -g default-terminal "screen-256color"
        set -ga terminal-overrides ",xterm-256color:Tc"
        #set -g default-terminal "tmux-256color"
        #set -ga terminal-overrides ",*256col*:Tc"

        # Set the window list format
        set -g window-status-format "#I:#W#F"

        # Set the active window format
        set -g window-status-current-format "#[fg=white,bold]#I:#W#F"

        # increase scrollback buffer to 99999
        set -g history-limit 99999

        # Set plugin installation path
        set -g @plugin 'tmux-plugins/tpm'
        set -g @plugin 'tmux-plugins/tmux-sensible'
        set -g @plugin_path '~/.tmux/plugins'

        ## For tmux-power
        set -g @plugin 'wfxr/tmux-power'
        set -g @plugin 'ofirgall/tmux-window-name'
        set -g @plugin 'jaclu/tmux-mouse-swipe'
        set -g @plugin 'ChanderG/tmux-notify'
        # Plugin: Tmux highlight the keys
        set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
        # Plugin: Tmux internet speed
        set -g @plugin 'wfxr/tmux-net-speed'
        # Plugin: Tmux Copycat
        set -g @plugin 'tmux-plugins/tmux-copycat'
        # Plugin: Tmux Yank
        set -g @plugin 'tmux-plugins/tmux-yank'
        # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
        #run '~/.tmux/plugins/tpm/tpm'
      '';
    };
  };
}

Maintainer CC

@emilazy

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.1.68, Athena OS, 24.05 (Uakari), 24.05.20231219.54aac08`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos-23.11"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
redcobra commented 10 months ago

I was having the same issue. I was able resolved it by putting the plugin settings in the extraConfig of the plugin itself instead of tmux.

{
    programs.tmux = {
        enable = true;
        terminal = "xterm-256color";
        historyLimit = 10000;
        plugins = with pkgs.tmuxPlugins; [
            {
                plugin = power-theme;
                extraConfig = ''
                    set -g @tmux_power_theme 'violet'
                '';
            }
            {
                plugin = resurrect;
                extraConfig = ''
                    set -g @resurrect-capture-pane-contents 'on'
                '';
            }
            {
                plugin = continuum;
                extraConfig = ''
                    set -g @continuum-restore 'on'
                '';
            }
            vim-tmux-navigator
        ];
        extraConfig = ''
            set-option -ga terminal-overrides ",xterm-256color:Tc"

            set -g prefix C-a
            unbind C-b
            bind-key C-a send-prefix

            unbind %
            bind \\ split-window -h

            unbind '"'
            bind - split-window -v

            unbind r
            bind r source-file ~/.config/tmux/tmux.conf

            bind -r j resize-pane -D 5
            bind -r k resize-pane -U 5
            bind -r l resize-pane -R 5
            bind -r h resize-pane -L 5

            bind -r m resize-pane -Z

            set -g mouse on

            set-window-option -g mode-keys vi

            bind-key -T copy-mode-vi 'v' send -X begin-selection
            bind-key -T copy-mode-vi 'y' send -X copy-selection

            unbind -T copy-mode-vi MouseDragEnd1Pane
        '';
    };
D3vil0p3r commented 10 months ago

I tried your solution and it works with the power theme color, but it does not work for:

set -g @tmux_power_show_upload_speed true
set -g @tmux_power_show_download_speed true
tgallacher commented 7 months ago

Try moving any line that modifies the status-right into the power-theme config as well, e.g.

plugins = with pkgs.tmuxPlugins; [
   {
        plugin = power-theme;
        extraConfig = ''
            set -g @tmux_power_theme 'violet'

            set -g status-right '#{prefix_highlight} | %a %Y-%m-%d %H:%M'
            set -g status-right ...
        '';
    }
    ...
];
extraConfig = ''
 ...
''

The problem is that the extraConfig content is placed after where the plugins (and their config) is dumped into tmux.conf. When modifying the status-right this ordering conflict can cause issues.

tgallacher commented 7 months ago

The problem I mentioned above is actually reported in #3555

stale[bot] commented 4 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

keponk commented 2 months ago

perhaps related. I have a similar issue with dracula plugin. The plugin does load but one of its sections seem to have issue accessing a non-existing tmp folder where it is expected to exists:

Screenshot 2024-08-27 101245

Perhaps some plugins require to be able to write to some tmp location for them to behave as expected.