#29 new session conf file

closed
nobody
None
2014-02-26
2009-05-28
Anonymous
No

i recently installed tmux to replace screen. all is good, except i had issues with the conf file. i thought i'd just be able to add 'new-window', etc., like with screen, and then run 'tmux' or 'tmux new' and it would work, but after pulling my hair out for a while i came to realise why it doesn't

the problem was recognised by your fine selves in the change log for tmux 0.3, where you explain the reasoning behind adding the start-server command: that ~/.tmux.conf is a server configuration file, not a session configuration file, and so you must completely specify session details and such and then start the server only and attach to the conf-created session, *and* know to do all this

i didn't know to do all this, it's not clearly explained, and as you said in the change log it needs a better solution

my solution is thus: introduce a session conf file, which is run each time a new session is created. then the commands would be in the form expected by screen converts (ie, don't have to create a new session in the conf file, nor specify the session id anywhere), and the command to start tmux would just be 'tmux', again as expected.

a logical name would be tmux-session.conf for the session conf file, but i think tmux.conf should be the session file and tmux-server.conf should be the server file as it's more logical. but this breaks compatibility so probably won't be desirable and accepted. would could then clearly state in the man page that users probably want to use the tmux-session.conf file

if you're happy with this, i'm more than willing to write the code myself. i just thought i'd propose it before potentially wasting time

Discussion

  • You make a fair point and this is a reasonable idea. However, a more powerful option may be to add the ability to set "hooks". So you would be able to define a set of commands to run when tmux events occur. For example, in your configuration file you could say something like:

    tmux add-hook "new-session" source-file $HOME/.tmux-session.conf

    To load a file every time a session was created.

    In fact, if there was also something like a if-shell command (not sure about the name but it'll do to show the idea), you could even make a hook there by default:

    tmux add-hook "new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file $HOME/.tmux-session.conf

    This would tie in well with the scripting ability I might add at some point, and shouldn't all that complicated although it might need a certain amount of care to implement (some commands may have reentrancy problems, particularly those affecting the status line).

    I don't necessarily think making the transition easy for screen users by changing the code is the right thing to do, it may be better served by improving the documentation - perhaps a how-do-I-do-$screenfeature-in-tmux FAQ or help file.

    If you want to do any of this it would be great, or I am happy enough to go with your original idea - I will add mine to the todo list and convert your stuff to it when I get time to implement it.

    I am happy to answer questions or review code although note I will be on holiday (out of contact) from approximately 6-24 June.

     
  • hey again

    so this only took 2 and a half months :)

    personally i think the hooks thing is feature bloat. i know it sounds cool and powerful but it doesn't seemed to me like it would be used and would just complicate the code. so i've just gone with my idea for the moment. it turned out to be pretty simple. hopefully it stays that way

    the following example ~/.tmux-session.conf works fine:

    new-window
    new-window
    select-window -t:0

    i've tried kill-server, kill-session, new-session, start-server, etc. and they are "gracefully" handled by the current code without seg faulting or anything else undesirable. i've only just hacked it up so i haven't actually tested it very much though

    if you like it, i'll do up something for the man page. i expect you'll ask for a flag to change the file name too :p i can't seem to attach the patch here. shall i just send it via email to nicm |at| openbsd?

     
  • i should have clarified. all you need now is:

    $ cat > ~/.tmux-session.conf
    new-window
    new-window
    select-window -t:0
    $ tmux

    :)

     
  • Please send the diff to me by email, don't worry about the man page until I've seen the code.

    The hooks thing isn't bloat, it will save having to add any more special-cases like this (what if someone wants to load a config file for each new window or pane as well? - this is a real possibility, someone wanted the set-remain-on-exit option after I changed the way options worked) and it shoudn't complicate the code that much, although until I've tried it I won't know for sure.

     
  • Ticket moved from /p/tmux/feature-requests/8/

     
  • Hooks are stalled, please can you resend this diff and I'll take another look and decide once and for all?

     
    • status: open --> closed
    • Milestone: -->