Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration changes aren't being read #15

Open
NovaViper opened this issue Jan 10, 2025 · 4 comments
Open

Configuration changes aren't being read #15

NovaViper opened this issue Jan 10, 2025 · 4 comments

Comments

@NovaViper
Copy link

Hey I'm trying to get the plugin to work with my config.yaml but it doesn't appear to even register the changes at all despite me having set -g @tmux-which-key-xdg-enable 1 in my tmux file (I have it declared in NixOS/Home-Manager).

{
  config,
  lib,
  myLib,
  pkgs,
  ...
}: let
  cfg = config.hm.programs.tmux;
  hm-config = config.hm;
in
{
    # Fixes issue where cava can't run under tmux
    home.shellAliases.cava = lib.mkIf config.modules.cava.enable "TERM=xterm-256color cava";

    hm.programs.fzf.tmux.enableShellIntegration = true;

    hm.programs.tmux = {
      enable = true;
      aggressiveResize = true;
      customPaneNavigationAndResize = true;
      baseIndex = 1;
      historyLimit = 5000;
      keyMode = "vi";
      mouse = true;
      #escapeTime = 0;
      shortcut = "a";
      terminal = "tmux-256color";
      resizeAmount = 15;
      tmuxp.enable = true;
      #newSession = true;
      #secureSocket = false;
      extraConfig = ''
        # -- more settings ---------------------------------------------------------------
        set -s set-clipboard on
        set -g set-titles on
        set -g set-titles-string "#S / #W / #(pwd)"
        set -g allow-passthrough on
        set -ga update-environment TERM
        set -ga update-environment TERM_PROGRAM

        set-option -g status-right-length 100

        # Enable sixel support
        set -as terminal-features 'contour:sixel'

        # Enable full RGB support
        set -as terminal-features ",*-256color:RGB"

        # Pane numbers, line messages duration and status line updates
        set -g display-panes-time 800
        set -g display-time 2000
        set -g status-interval 5

        # Monitor for terminal activity changes, and manage how the alerts are displayed
        set -g monitor-activity on
        set -g visual-activity both

        # update files on focus
        set -g focus-events on

        setw -g automatic-rename on
        # Renumber windows
        set -g renumber-windows on

        # Change status bar position
        set -g status-position bottom
        # -------------------------------------------------------------------------------------


        # -- keybindings -----------------------------------------------------------------
        # reload config file (change file location to your the tmux.conf you want to use)
        unbind R
        bind -N "Reload configuration" r source-file ${hm-config.xdg.configHome}/tmux/tmux.conf \; display "Reloaded!"

        unbind C-p
        unbind C-n

        # Setup clipboard binding keys
        unbind p
        bind -N "Paste the most recent paste buffer" p paste-buffer
        bind -N "Go back to previous window" P previous-window

        # Tmux-copycat functionality
        # https://github.com/tmux-plugins/tmux-copycat/issues/148#issuecomment-997929971
        bind -N "Copy selection" -T copy-mode-vi y send -X copy-selection-no-clear
        bind -N "Search backwards" / copy-mode \; send ?
        # Somewhat tmux-copycat select url functionality (requires 3.1+)
        bind -N "Select URL" C-u copy-mode \; send -X search-backward "(https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*"

        # Join pane bindings
        bind -N "Join panes horizitonally" = choose-window 'join-pane -h -s "%%"'
        bind -N "Join panes vertically" + choose-window 'join-pane -s "%%"'

        # Split pane bindings
        unbind '"'
        unbind %
        unbind n
        unbind p
        bind -N "Split panes horizontally" \\ split-window -h -c "#{pane_current_path}"
        bind -N "Split panes horizontally, full window length" | split-window -fh -c "#{pane_current_path}"
        bind -N "Split panes vertically" - split-window -v -c "#{pane_current_path}"
        bind -N "Split panes vertically, full window length" _ split-window -fv -c "#{pane_current_path}"

        # Manage Session/Window
        bind -N "Switch to next window" > next-window
        bind -N "Switch to previous window" < previous-window
        bind -N "Create new window" c new-window -c "#{pane_current_path}"
        bind -N "Create new session" C-c new-session
        bind -N "Toggle between current and previous session" C-Space switch-client -l
        bind -N "Jump to marked session" \` switch-client -t'{marked}'
        unbind &
        ${
          if cfg.disableConfirmationPrompt
          then ''
            bind -N "Kill the active pane" x kill-pane
            bind -N "Kill the current window" X kill-window
            bind -N "Kill the current session" C-x kill-session
          ''
          else ''
            bind -N "Kill the current window" X confirm-before -p "kill-window #W? (y/n)" kill-window
            bind -N "Kill the current session" C-x confirm-before -p "kill-session #W? (y/n)" kill-session
          ''
        }

        #Example
        #bind -N "Example note" h split-window -h "vim ~/scratch/notes.md"
        # -------------------------------------------------------------------------------------
      '';
      plugins = with pkgs.tmuxPlugins; [
        sensible
        {
          plugin = yank;
          extraConfig = ''
            # Enable Mouse support for tmux-yank
            set -g @yank_with_mouse on
          '';
        }
        open
        fuzzback
        extrakto
        (lib.mkIf hm-config.programs.fzf.enable tmux-fzf)
        {
          plugin = dracula;
          extraConfig = ''
            # Theme settings
            # available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, tmux-ram-usage, network, network-bandwidth, network-ping, attached-clients, network-vpn, weather, time, spotify-tui, kubernetes-context, synchronize-panes
            set -g @dracula-plugins "battery cpu-usage ram-usage time"

            # Show powerline symbols
            set -g @dracula-show-powerline true

            # Enable window flags
            set -g @dracula-show-flags true

            # Switch left icon, can accept `session`, `smiley`, `window`, or any character.
            set -g @dracula-show-left-icon smiley

            # Hide empty plugins
            set -g @dracula-show-empty-plugins false

            # Theme color settings
            # available colors: white, gray, dark_gray, light_purple, dark_purple, cyan, green, orange, red, pink, yellow
            # set -g @dracula-[plugin-name]-colors "[background] [foreground]"
            set -g @dracula-gpu-usage-colors "red white"
          '';
        }
        {
          plugin = which-key;
          extraConfig = ''
            set -g @tmux-which-key-xdg-enable 1
            set -g @tmux-which-key-disable-autobuild 1
          '';
        }
      ];
    };
  }

Config.yaml (it's not gonna be the final one but just trying to make it function)

# yaml-language-server: $schema=config.schema.yaml
command_alias_start_index: 200
keybindings:
  # root_table: C-Space
  prefix_table: Space
title:
  style: align=centre,bold
  prefix: tmux
  prefix_style: fg=red,align=centre,bold
position:
  x: R
  y: P
custom_variables:
  - name: log_info
    value: "#[fg=green,italics] [info]#[default]#[italics]"
macros:
  - name: reload-config
    commands:
      - display "#{log_info} Loading config... "
      - source-file $HOME/.tmux.conf
      - display -p "\n\n... Press ENTER to continue"
  - name: restart-pane
    commands:
      - display "#{log_info} Restarting pane"
      - "respawnp -k -c #{pane_current_path}"
items:
  - name: Run
    key: space
    command: command-prompt
@NovaViper
Copy link
Author

NovaViper commented Jan 10, 2025

Also im noticing the menu tries to rebuild and it fails with this error (this happens when I don't include set -g @tmux-which-key-disable-autobuild 1

[tmux-which-key] Rebuilding menu ...
'/nix/store/g7ls364m6bnnriffyqw3xdk98p7l8vrm-tmuxplugin-which-key-unstable-2024-06-08/share/tmux-plugins/which-key/plugin.sh.tmux' returned 1

And if I try to put any of the xdg settings like so

        {
          plugin = which-key;
          extraConfig = ''
            set -g @tmux-which-key-xdg-enable 1
            set -g @tmux-which-key-xdg-plugin-path=tmux/plugins/tmux-which-key
          '';
        }

It errors saying "empty value"

@higherorderfunctor
Copy link
Contributor

@NovaViper You have to convert it from yaml -> tmux which you will have to do in a derivation since the autobuild will try to do in the /nix/store which is read-only. The yaml is never read at runtime.

See https://github.com/alexwforsythe/tmux-which-key/pull/9/files which was never merged that includes a home manager module to take care of all this. It can do the conversion from yaml or you configure everything directly in nix. It also includes an app to convert the default config to nix also if you want.

Feel free to upstream the home manager module if you want. I am now using zellij instead of tmux, but this plugin still works in my tmux config https://github.com/higherorderfunctor/nixos-config/blob/042d8dc09a03a266359a872fe24582b0761438b4/home/caubut/features/cli/tmux/default.nix#L24-L27.

Note that I am using the flake.nix in my branch for the MR as the input: https://github.com/higherorderfunctor/nixos-config/blob/042d8dc09a03a266359a872fe24582b0761438b4/flake.nix#L140-L144.

@higherorderfunctor
Copy link
Contributor

higherorderfunctor commented Jan 10, 2025

This is the actual config format used at runtime: https://github.com/alexwforsythe/tmux-which-key/blob/main/plugin/init.example.tmux

There is a python script to convert from yaml to tmux which the home manager module wraps in a derivation: https://github.com/alexwforsythe/tmux-which-key/pull/9/files#diff-f3ff5cfee44f7b78091278fbbd2378a1de43ce295e8bedf7e0fc794d230c53c2R48-R82

I add the yaml to the xdg config directory, but it is not actually used.

      xdg = {
        configFile."${pluginPath}/config.yaml".source = configYaml; # just for reference
        dataFile."${pluginPath}/init.tmux".source = configTmux; # the actual runtime config used
      };

The runtime config is in ~/.local/share.

$ cat ~/.local/share/tmux-plugins/tmux-which-key/init.tmux
#
# Generated by generate_plugin.py.
#
# init.tmux: called by plugin.sh.tmux to initialize the plugin.
#

display -p '[tmux-which-key] Loading plugin ...'

#
# User options
#

set -g @wk_cfg_key_root_table "C-Space"
set -g @wk_cfg_key_prefix_table "Space"
set -g @wk_cfg_title_style "align=centre,bold"
set -g @wk_cfg_title_prefix "tmux"
set -g @wk_cfg_title_prefix_style "fg=green,align=centre,bold"
set -g @wk_cfg_pos_x "R"
set -g @wk_cfg_pos_y "P"

#
# Custom variables
#

setenv -h log_info "#[fg=green,italics] [info]#[default]#[italics]"

#
# Menus
#

set -g @wk_menu_copy \
'Copy "c" copy-mode \
"List buffers" "#" list-buffers'

set -g @wk_menu_layout \
'Next "l" "nextl ; show-wk-menu #{@wk_menu_layout}" \
Tiled "t" "selectnl tiled" \
Horizontal "h" "selectl even-horizontal" \
Vertical "v" "selectl even-vertical" \
"Horizontal main" "H" "selectl main-horizontal" \
"Vertical main" "V" "selectl main-vertical"'

set -g @wk_menu_windows \
'Last "tab" last-window \
Choose "w" "choose-tree -Zw" \
Previous "p" previous-window \
Next "n" next-window \
New "c" "neww -c #{pane_current_path}" \
"" \
"+Layout" "l" "show-wk-menu #{@wk_menu_layout}" \
"Split horiztonal" "/" "splitw -h -c #{pane_current_path}" \
"Split vertical" "-" "splitw -v -c #{pane_current_path}" \
Rotate "o" "rotatew ; show-wk-menu #{@wk_menu_windows}" \
"Rotate reverse" "O" "rotatew -D ; show-wk-menu #{@wk_menu_windows}" \
"" \
Rename "R" "command-prompt -I \"#W\" \"renamew -- \\"%%\\"\"" \
Kill "X" "confirm -p \"Kill window #W? (y/n)\" killw"'

set -g @wk_menu_resize \
'Left "h" "resizep -L ; show-wk-menu #{@wk_menu_resize}" \
Down "j" "resizep -D ; show-wk-menu #{@wk_menu_resize}" \
Up "k" "resizep -U ; show-wk-menu #{@wk_menu_resize}" \
Right "l" "resizep -R ; show-wk-menu #{@wk_menu_resize}" \
"Left more" "H" "resizep -L 10 ; show-wk-menu #{@wk_menu_resize}" \
"Down more" "J" "resizep -D 10 ; show-wk-menu #{@wk_menu_resize}" \
"Up more" "K" "resizep -U 10 ; show-wk-menu #{@wk_menu_resize}" \
"Right more" "L" "resizep -R 10 ; show-wk-menu #{@wk_menu_resize}"'

set -g @wk_menu_panes \
'Last "tab" lastp \
Choose "p" "displayp -d 0" \
"" \
Left "h" "selectp -L" \
Down "j" "selectp -D" \
Up "k" "selectp -U" \
Right "l" "selectp -R" \
"" \
Zoom "z" "resizep -Z" \
"+Resize" "r" "show-wk-menu #{@wk_menu_resize}" \
"Swap left" "H" "swapp -t \"{left-of}\"" \
"Swap down" "J" "swapp -t \"{down-of}\"" \
"Swap up" "K" "swapp -t \"{up-of}\"" \
"Swap right" "L" "swapp -t \"{right-of}\"" \
Break "!" break-pane \
"" \
Mark "m" "selectp -m" \
Unmark "M" "selectp -M" \
Capture "C" capture-pane \
"Respawn pane" "R" restart-pane \
Kill "X" "confirm -p \"Kill pane #P? (y/n)\" killp"'

set -g @wk_menu_buffers \
'Choose "b" "choose-buffer -Z" \
List "l" lsb \
Paste "p" pasteb'

set -g @wk_menu_sessions \
'Choose "s" "choose-tree -Zs" \
New "N" new \
Rename "r" rename'

set -g @wk_menu_plugins \
'Install "i" "run-shell $TMUX_PLUGIN_MANAGER_PATH/tpm/bindings/install_plugins" \
Update "u" "run-shell $TMUX_PLUGIN_MANAGER_PATH/tpm/bindings/update_plugins" \
Clean "c" "run-shell $TMUX_PLUGIN_MANAGER_PATH/tpm/bindings/clean_plugins"'

set -g @wk_menu_client \
'Choose "c" "choose-client -Z" \
Last "l" "switchc -l" \
Previous "p" "switchc -p" \
Next "n" "switchc -n" \
"" \
Refresh "R" refresh \
"+Plugins" "P" "show-wk-menu #{@wk_menu_plugins}" \
Detach "D" detach \
Suspend "Z" suspendc \
"" \
"Reload config" "r" reload-config \
Customize "," "customize-mode -Z"'

set -g @wk_menu_root \
'Run "space" command-prompt \
"Last window" "tab" last-window \
"Last pane" "`" last-pane \
Copy "c" "show-wk-menu #{@wk_menu_copy}" \
"" \
"+Windows" "w" "show-wk-menu #{@wk_menu_windows}" \
"+Panes" "p" "show-wk-menu #{@wk_menu_panes}" \
"+Buffers" "b" "show-wk-menu #{@wk_menu_buffers}" \
"+Sessions" "s" "show-wk-menu #{@wk_menu_sessions}" \
"+Client" "C" "show-wk-menu #{@wk_menu_client}" \
"" \
Time "T" clock-mode \
"Show messages" "\~" show-messages \
"+Keys" "?" "list-keys -N"'

#
# Macros
#

set -gF @wk_cmd_show \
"display-menu \
-x '#{@wk_cfg_pos_x}' \
-y '#{@wk_cfg_pos_y}' \
-T '#[#{@wk_cfg_title_style}]#[#{@wk_cfg_title_prefix_style}]#{@wk_cfg_title_prefix}#[#{@wk_cfg_title_style}]'"

set -gF command-alias[200] show-wk-menu=\
'#{@wk_cmd_show}'

set -gF command-alias[201] show-wk-menu-root=\
'#{@wk_cmd_show} #{@wk_menu_root}'

set -gF command-alias[202] reload-config=\
'display "#{log_info} Loading config... " ; \
source-file $HOME/.tmux.conf ; \
display -p "\n\n... Press ENTER to continue"'

set -gF command-alias[203] restart-pane=\
'display "#{log_info} Restarting pane" ; \
respawnp -k -c #{pane_current_path}'

#
# Keybindings
#

display -p "[tmux-which-key] Binding root table key to #{@wk_cfg_key_root_table} ..."
run-shell "tmux bind-key -Troot #{@wk_cfg_key_root_table} show-wk-menu-root"

display -p "[tmux-which-key] Binding prefix table key to #{@wk_cfg_key_prefix_table} ..."
run-shell "tmux bind-key -Tprefix #{@wk_cfg_key_prefix_table} show-wk-menu-root"

display -p '[tmux-which-key] Done'

@NovaViper
Copy link
Author

@NovaViper You have to convert it from yaml -> tmux which you will have to do in a derivation since the autobuild will try to do in the /nix/store which is read-only. The yaml is never read at runtime.

Ah that explains why I couldn't get it read the config file. I hadn't realized the home-manager module itself was rather complicated (due to having to rely on the build script); I don't see myself being able to maintain for the long term but I can at least get the package added into nixpkgs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants