tmux-menu

Crates.iotmux-menu
lib.rstmux-menu
version0.1.10
sourcesrc
created_at2023-03-02 05:28:58.867659
updated_at2024-02-14 02:28:59.534646
descriptionEasy configuration of tmux display-menu with yaml
homepage
repositoryhttps://github.com/Ja-sonYun/tmux-easy-menu
max_upload_size
id798656
size41,624
(Ja-sonYun)

documentation

README

tmux-easy-menu v0.1.10

Easy configurable tmux display-menu

Alt Text

Setup

cargo install tmux-menu

Configuration

To see more actual config files, checkout ./examples folder.

# 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: ...

Dynamic menu

Alt Text Alt Text Below example will show running brew services on display-menu, and restart it if clicked.

#!/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

and add menu item as below

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

cargo fmt