1

I have a command in my .tmux.conf file which checks to see if a directory exists, then displays a message if it doesn't; and another command which tries to run a shell script.

file: ~/.tmux.conf

# do a check and display message if non-zero exit
if-shell "! [-d $HOME/.tmux]" 'display-message "tmux plugins are not installed"'

# try run a shell script
run-shell ~/.tmux/plugins/tmux-resurrect/resurrect.tmux

The problem is that tmux won't display any messages that are generated during startup - which is the time I would expect diagnostic errors and warnings to be generated.

What I start tmux, I get an error message in tmux's pager

(null):0: no current session 

where it's clearly not liking being sent messages.

If I run the same commands by using source-file ~/.tmux-conf in the middle of a tmux session, all messages are reported successfully. How can I get tmux to report messages during startup?

0

It works for me from the command-line as follows:

tmux new-session \; if-shell "! [-d $HOME/.tmux]" 'display-message "tmux plugins are not installed"'
0

I know this is old, but I was also interested in displaying some sort of startup message and came across this question. After searching around I eventually found out about tmux hooks (introduced internally in tmux 2.2) which can be configured to display a one time startup message (read more here).

You can use the session-created hook to run tmux commands on a new session. display-message -p "message" outputs a message straight to the newly created window. So you can display a message like so:

MESSAGE='display-message -p "tmux plugins are not installed" ; \
         display-message -p "please press Leader + I to install" ; \
         set-hook -gu session-created ;'
if-shell "[ ! -d $HOME/.tmux ]" 'set-hook -g session-created ${MESSAGE}'

the set-hook -gu session-created unregisters this hook, so that this message is shown only on the first session created, and not all subsequent ones.

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.