0

I'm wanting to build a TPM based plugin but the example provided is extremely minimal, doesn't explain how to do things (like creating commmands that can be used in the tmux status bar, or how to have args passed to the plugin for example).

Is there a super annotated plugin I can look at to get a better idea of how it works? or some better information about this?

  • @meuh of course you can add new ones, how else do they add status bar commands to display battery level, internet status, cpu usage, etc? – Thermatix Aug 11 '18 at 16:32
3

A tmux plugin is just a shell script in a conventional place (~/.tmux/plugins/) that the plugin manager will look for and run using the built-in tmux run-shell command. It is just packaging for cleanliness. The shell script implements everything else with the standard built-in tmux commands. You cannot add any new ones. See man tmux for all the commands.

If you look at the cpu plugin, it allows you to have new status line options like #{cpu_percentage}. To do this it uses

tmux show-option -gqv status-right

to find your wanted configuration string, and replaces matching options by a call to one of the other shell scripts provided by the plugin, namely in this case

#(~/.tmux/plugins/tmux-cpu/scripts/cpu_percentage.sh)

The form #() is standard built-in tmux syntax to run a shell command from the value of status-right and other variables. See the man page under section FORMATS.

The updated status-right string is given back to tmux with tmux set-option -qg status-right.

| improve this answer | |
  • Awesome! that's what I was looking for, one thing though, How do I pass stuff like, pane_id or pane_current_path to the scripts or figure out which pane was active when a command was run? – Thermatix Aug 11 '18 at 17:44
  • 1
    I'm not a tmux expert, and there are lots of tmux commands I don't know, so you may need to post more specific questions with exact details of what you would like to do, but for example, tmux display -p '#{pane_index}' from a shell script will print the current pane number (0 or 1 etc). – meuh Aug 11 '18 at 18:18
  • Thanks @meuh!, that's what I was looking for, I think that's what I need to get what I want working, you've been a super big help! – Thermatix Aug 11 '18 at 18:35
  • I get it, I GET IT, I get how they addd stuff like #{cpu_icon}, it's super dirty, but I get it!, #{cpu_icon} doesn't get replaced in tmux, instead the script gets executed in shell script and will replace #{cpu_icon} with the output of cpu_icon.sh using shell style ${variable//pattern/replacement}. – Thermatix Aug 11 '18 at 20:12
  • 1
    Apologies, it doesn't replace with the output, rather it replaces it #{cpu} with #(~/path/to/cpu.sh) – Thermatix Aug 11 '18 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.