#tmux #yaml #menu #configuration #configurable #display-menu

app tmux-menu

使用yaml轻松配置tmux显示菜单

10个版本

0.1.10 2024年2月14日
0.1.9 2023年8月17日
0.1.5 2023年3月17日

#158配置

47 每月下载量

MIT 许可证

29KB
637

tmux-easy-menu v0.1.10

易于配置的tmux显示菜单

Alt Text

设置

cargo install tmux-menu

配置

要查看更多实际的配置文件,请查看./examples文件夹。

# On tmux.conf, add below line.
#
# bind-key k run-shell "tmux-menu show --menu $HOME/tmux-menu/examples/menu.yaml --working_dir #{pane_current_path}"
#                      
# =============================
#
title: "..."
border: "rounded"                   # Optional, possible options are: single, rounded, double, heavy, simple, padded, none
position:
  x: ...
  y: ...

items:
  - Seperate: {}                    # Draw seperate line

  - NoDim:                          # Add row, but unselectable
      name: "..."

  - Menu:                           # Add selectable row
      name: "..."
      shortcut: "..."               # Optional
#     ------------------
      # You can define next_menu or command
      next_menu: "..."              # Show this menu when this row selected

#       ... OR

      command: "command %%KEY%% --cwd %%PWD"    # Run command, %%PWD will replaced with cwd
      inputs:
        - KEY                       # This input will be replaced with '%%KEY%%' on command
#     ------------------
      background: false             # Run command in background, popup will closed immediately
      close_after_command: true     # Close popup after command exited. if false, you should type <C-c> to close popup.
      border: none                  # Select popup border type, optional, possible options are: single, rounded, double, heavy, simple, padded, none
      session: false                # Run commmand in new session. Useful for long running command. To hide popup while command running, use <C-d> to detach and close.
      session_name: name            # Session name, which will be used if session is true. This must be unique.
      position:
        x: ...
        y: ...
        w: ...
        h: ...

动态菜单

替代文本 替代文本 下面示例将展示在显示菜单上运行brew服务,并单击时重启它。

#!/bin/bash
# generate_brew_services_restart_menu.sh

TEMP_MENU_FILE="/tmp/temp_menu.yaml"
rm -f $TEMP_MENU_FILE
cat > $TEMP_MENU_FILE << EOM
title: " brew services "
items:
  - Seperate: {}
  - NoDim:
      name: " Running services "
  - NoDim:
      name: " (select to restart) "
  - Seperate: {}
EOM

brew services list | while read line
do
    program=$(echo $line | awk '{print $1}')
    status=$(echo $line | awk '{print $2}')

    if [ "$status" == "started" ]; then
        cat >> $TEMP_MENU_FILE <<- EOM
  - Menu:
      name: "$program"
      shortcut: ".."
      command: "brew services restart $program"
      background: true
EOM
    fi
done

tmux-menu show --menu $TEMP_MENU_FILE
rm -f $TEMP_MENU_FILE

并按以下方式添加菜单项

  - Menu:
      name: "restart brew services"
      shortcut: b
      command: "$PATH_TO_SCRIPT/generate_brew_services_restart_menu.sh"
      background: true

依赖项

~7–16MB
~205K SLoC