[PATCH] copy client/session environment to local environment on session creation
This changes the way environment variables are handled: - a new session populates the local environment from the current client/session/server process (in case the config creates a session) - the global environment is empty by default - variables in the global environment override variables in the local environment --- I'm not sure what all the existing use cases are and which ones may break from this change. One thing I can think of is the config file parsing wrt to environment variable expansion. I guess we could use the environment variables the server inherited when it was started? --- cfg.c|2 +- cmd-command-prompt.c |3 ++- cmd-confirm-before.c |3 ++- cmd-if-shell.c |3 ++- cmd-new-session.c| 15 ++- cmd-respawn-pane.c |2 +- cmd-respawn-window.c |2 +- cmd-split-window.c |2 +- cmd-string.c | 30 +- control.c|3 ++- job.c|2 +- session.c|2 +- tmux.c |4 tmux.h |4 ++-- window-choose.c |3 ++- 15 files changed, 45 insertions(+), 35 deletions(-) diff --git a/cfg.c b/cfg.c index 1153de6..34a49e2 100644 --- a/cfg.c +++ b/cfg.c @@ -91,7 +91,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause) } /* Parse and run the command. */ - if (cmd_string_parse(buf, cmdlist, path, n, cause1) != 0) { + if (cmd_string_parse(NULL, buf, cmdlist, path, n, cause1) != 0) { free(copy); if (cause1 == NULL) continue; diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index 759d578..8c1393c 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -172,7 +172,8 @@ cmd_command_prompt_callback(void *data, const char *s) return (1); } - if (cmd_string_parse(new_template, cmdlist, NULL, 0, cause) != 0) { + if (cmd_string_parse(c-session-environ, new_template, cmdlist, + NULL, 0, cause) != 0) { if (cause != NULL) { *cause = toupper((u_char) *cause); status_message_set(c, %s, cause); diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 9266721..691810f 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -115,7 +115,8 @@ cmd_confirm_before_callback(void *data, const char *s) if (tolower((u_char) s[0]) != 'y' || s[1] != '\0') return (0); - if (cmd_string_parse(cdata-cmd, cmdlist, NULL, 0, cause) != 0) { + if (cmd_string_parse(c-session-environ, cdata-cmd, cmdlist, NULL, + 0, cause) != 0) { if (cause != NULL) { cmdq_error(c-cmdq, %s, cause); free(cause); diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 9b6dcf3..e79c0c4 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -123,7 +123,8 @@ cmd_if_shell_callback(struct job *job) if (cmd == NULL) return; - if (cmd_string_parse(cmd, cmdlist, NULL, 0, cause) != 0) { + if (cmd_string_parse(cmdq-client-session-environ, cmd, cmdlist, + NULL, 0, cause) != 0) { if (cause != NULL) { cmdq_error(cmdq, %s, cause); free(cause); diff --git a/cmd-new-session.c b/cmd-new-session.c index ad083a4..b0a5bd2 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -54,8 +54,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) struct window *w; struct environ env; struct termios tio, *tiop; - const char *newname, *target, *update, *errstr, *template; - char*cmd, *cause, *cp; + const char *newname, *target, *errstr, *template; + char*cmd, *cause, *cp, **var; int detached, already_attached, idx, cwd, fd = -1; u_intsx, sy; struct format_tree *ft; @@ -188,9 +188,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) /* Construct the environment. */ environ_init(env); - update = options_get_string(global_s_options, update-environment); - if (c != NULL) - environ_update(update, c-environ, env); + if (c != NULL c-session == NULL) + environ_copy(c-environ, env); + else if ((c0 = cmd_current_client(cmdq)) != NULL) + environ_copy(c0-environ, env); + else { + for (var = environ; *var != NULL; var++) + environ_put(env, *var); + } /* Create the new session. */ idx = -1 - options_get_number(global_s_options, base-index); diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c index bcde275..f92fbe6
Re: [PATCH] cmd_string_parse: use session environment if available
Just found a problem: sourcing the tmux configuration expands the environment variables, too, and I don't see any way that allows escaping. That means ':new-window -c $PWD' on the prompt works but binding the same will resolve $PWD when parsing the config, not when pressing the keys. Any recommendations how to solve this? Did one of those small cosmetic changes in the last minute and missed to remove the in environ_find(environ, ...). The attached patch fixes that. --- cfg.c|2 +- cmd-command-prompt.c |3 ++- cmd-confirm-before.c |3 ++- cmd-if-shell.c |3 ++- cmd-string.c | 38 +++--- control.c|3 ++- tmux.h |4 ++-- window-choose.c |3 ++- 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/cfg.c b/cfg.c index 1153de6..34a49e2 100644 --- a/cfg.c +++ b/cfg.c @@ -91,7 +91,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause) } /* Parse and run the command. */ - if (cmd_string_parse(buf, cmdlist, path, n, cause1) != 0) { + if (cmd_string_parse(NULL, buf, cmdlist, path, n, cause1) != 0) { free(copy); if (cause1 == NULL) continue; diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index 759d578..8c1393c 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -172,7 +172,8 @@ cmd_command_prompt_callback(void *data, const char *s) return (1); } - if (cmd_string_parse(new_template, cmdlist, NULL, 0, cause) != 0) { + if (cmd_string_parse(c-session-environ, new_template, cmdlist, + NULL, 0, cause) != 0) { if (cause != NULL) { *cause = toupper((u_char) *cause); status_message_set(c, %s, cause); diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 9266721..691810f 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -115,7 +115,8 @@ cmd_confirm_before_callback(void *data, const char *s) if (tolower((u_char) s[0]) != 'y' || s[1] != '\0') return (0); - if (cmd_string_parse(cdata-cmd, cmdlist, NULL, 0, cause) != 0) { + if (cmd_string_parse(c-session-environ, cdata-cmd, cmdlist, NULL, + 0, cause) != 0) { if (cause != NULL) { cmdq_error(c-cmdq, %s, cause); free(cause); diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 9b6dcf3..e79c0c4 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -123,7 +123,8 @@ cmd_if_shell_callback(struct job *job) if (cmd == NULL) return; - if (cmd_string_parse(cmd, cmdlist, NULL, 0, cause) != 0) { + if (cmd_string_parse(cmdq-client-session-environ, cmd, cmdlist, + NULL, 0, cause) != 0) { if (cause != NULL) { cmdq_error(cmdq, %s, cause); free(cause); diff --git a/cmd-string.c b/cmd-string.c index e793ea0..77dc8af 100644 --- a/cmd-string.c +++ b/cmd-string.c @@ -34,9 +34,9 @@ int cmd_string_getc(const char *, size_t *); voidcmd_string_ungetc(size_t *); voidcmd_string_copy(char **, char *, size_t *); -char *cmd_string_string(const char *, size_t *, char, int); -char *cmd_string_variable(const char *, size_t *); -char *cmd_string_expand_tilde(const char *, size_t *); +char *cmd_string_string(struct environ *, const char *, size_t *, char, int); +char *cmd_string_variable(struct environ *, const char *, size_t *); +char *cmd_string_expand_tilde(struct environ *, const char *, size_t *); int cmd_string_getc(const char *s, size_t *p) @@ -59,8 +59,8 @@ cmd_string_ungetc(size_t *p) * string, or NULL for empty command. */ int -cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file, -u_int line, char **cause) +cmd_string_parse(struct environ* environ, const char *s, +struct cmd_list **cmdlist, const char *file, u_int line, char **cause) { size_t p; int ch, i, argc, rval; @@ -84,17 +84,17 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file, ch = cmd_string_getc(s, p); switch (ch) { case '\'': - if ((t = cmd_string_string(s, p, '\'', 0)) == NULL) + if ((t = cmd_string_string(environ, s, p, '\'', 0)) == NULL) goto error; cmd_string_copy(buf, t, len); break; case '': - if ((t = cmd_string_string(s, p, '', 1)) == NULL) + if ((t = cmd_string_string(environ, s, p, '', 1)) == NULL) goto error; cmd_string_copy(buf, t, len);
[PATCH] cmd_string_parse: use session environment if available
This allows to use environment variables from the current session in command strings, e.g. to create a new window starting in $PWD. --- cfg.c|2 +- cmd-command-prompt.c |3 ++- cmd-confirm-before.c |3 ++- cmd-if-shell.c |3 ++- cmd-string.c | 38 +++--- control.c|3 ++- tmux.h |4 ++-- window-choose.c |3 ++- 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/cfg.c b/cfg.c index 1153de6..34a49e2 100644 --- a/cfg.c +++ b/cfg.c @@ -91,7 +91,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause) } /* Parse and run the command. */ - if (cmd_string_parse(buf, cmdlist, path, n, cause1) != 0) { + if (cmd_string_parse(NULL, buf, cmdlist, path, n, cause1) != 0) { free(copy); if (cause1 == NULL) continue; diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index 759d578..8c1393c 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -172,7 +172,8 @@ cmd_command_prompt_callback(void *data, const char *s) return (1); } - if (cmd_string_parse(new_template, cmdlist, NULL, 0, cause) != 0) { + if (cmd_string_parse(c-session-environ, new_template, cmdlist, + NULL, 0, cause) != 0) { if (cause != NULL) { *cause = toupper((u_char) *cause); status_message_set(c, %s, cause); diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 9266721..691810f 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -115,7 +115,8 @@ cmd_confirm_before_callback(void *data, const char *s) if (tolower((u_char) s[0]) != 'y' || s[1] != '\0') return (0); - if (cmd_string_parse(cdata-cmd, cmdlist, NULL, 0, cause) != 0) { + if (cmd_string_parse(c-session-environ, cdata-cmd, cmdlist, NULL, + 0, cause) != 0) { if (cause != NULL) { cmdq_error(c-cmdq, %s, cause); free(cause); diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 9b6dcf3..e79c0c4 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -123,7 +123,8 @@ cmd_if_shell_callback(struct job *job) if (cmd == NULL) return; - if (cmd_string_parse(cmd, cmdlist, NULL, 0, cause) != 0) { + if (cmd_string_parse(cmdq-client-session-environ, cmd, cmdlist, + NULL, 0, cause) != 0) { if (cause != NULL) { cmdq_error(cmdq, %s, cause); free(cause); diff --git a/cmd-string.c b/cmd-string.c index e793ea0..04c6b09 100644 --- a/cmd-string.c +++ b/cmd-string.c @@ -34,9 +34,9 @@ int cmd_string_getc(const char *, size_t *); voidcmd_string_ungetc(size_t *); voidcmd_string_copy(char **, char *, size_t *); -char *cmd_string_string(const char *, size_t *, char, int); -char *cmd_string_variable(const char *, size_t *); -char *cmd_string_expand_tilde(const char *, size_t *); +char *cmd_string_string(struct environ *, const char *, size_t *, char, int); +char *cmd_string_variable(struct environ *, const char *, size_t *); +char *cmd_string_expand_tilde(struct environ *, const char *, size_t *); int cmd_string_getc(const char *s, size_t *p) @@ -59,8 +59,8 @@ cmd_string_ungetc(size_t *p) * string, or NULL for empty command. */ int -cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file, -u_int line, char **cause) +cmd_string_parse(struct environ* environ, const char *s, +struct cmd_list **cmdlist, const char *file, u_int line, char **cause) { size_t p; int ch, i, argc, rval; @@ -84,17 +84,17 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file, ch = cmd_string_getc(s, p); switch (ch) { case '\'': - if ((t = cmd_string_string(s, p, '\'', 0)) == NULL) + if ((t = cmd_string_string(environ, s, p, '\'', 0)) == NULL) goto error; cmd_string_copy(buf, t, len); break; case '': - if ((t = cmd_string_string(s, p, '', 1)) == NULL) + if ((t = cmd_string_string(environ, s, p, '', 1)) == NULL) goto error; cmd_string_copy(buf, t, len); break; case '$': - if ((t = cmd_string_variable(s, p)) == NULL) + if ((t = cmd_string_variable(environ, s, p)) == NULL) goto error; cmd_string_copy(buf, t, len); break; @@ -140,7
Re: support for version blocks in tmux.conf
Maybe you could use a shell script wrapper around tmux to run `tmux -f ~/.tmux-1.6.conf` and `tmux -f ~/.tmux-1.5.conf`? These files could include a comman .tmux.conf too to keep the version specific files small. -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: BUG: double width characters cause previous character to be lost
Nicholas Marriott nicholas.marri...@gmail.com wrote: Try this please, see if it fixes your problem and if you see any ill effects: This fixes the problem for my test case. -- RSA(R) Conference 2012 Mar 27 - Feb 2 Save $400 by Jan. 27 Register now! http://p.sf.net/sfu/rsa-sfdev2dev2 ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
Nicholas Marriott nicholas.marri...@gmail.com wrote: Thanks for this. The OpenBSD kernel bits are in so I've applied your diff with some minor tweaks and the required bits for osdep-openbsd.c. I really like this feature, currently I'm using a shell function to change the directory and additionally set the default-path. Maybe this will render this function unnecessary. However, I'm not too sure yet if I always like this feature. Is it easily possible to disable this feature for new sessions, i.e. by putting something in the tmux.conf? Additionally, I think it would be nice to be able to create windows either with the path of the current window or with the path of the session. Can this be accomplished yet? -- Learn Windows Azure Live! Tuesday, Dec 13, 2011 Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
BUG: double width characters cause previous character to be lost
Hi, I just noticed the following bug when playing around with double width characters: When using an urxvt terminal with width of 80 the following command prints bar on one line and the double width character on the next line: printf %79s《\n bar In tmux the same produces only ba on the first line and the double width character on the second line. I'm not actually using double width characters much and I'm not too familiar with the relevant code of tmux (yet), therefore I've not further searched for the code causing this bug. -- Learn Windows Azure Live! Tuesday, Dec 13, 2011 Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: BUG: double width characters cause previous character to be lost
Nicholas Marriott nicholas.marri...@gmail.com wrote: please send a file with the problem output since your email does not include the actual UTF-8 Just take any double width character, I used \u300a as an example. File attached for 80 column terminal. bar《 -- Learn Windows Azure Live! Tuesday, Dec 13, 2011 Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] honor and export $PWD
Nicholas Marriott nicholas.marri...@gmail.com wrote: If you start PWD with it already in the environment, it is marked as exported - this is the same as any other variable: Ah, ok. Anyway it shows that ksh uses $PWD as any other shell, even though it doesn't export it by default. For your use, you want to be able to add * to update-environment. Particularly if that included PWD too. * should match anything, -* should remove anything in the new but not global environment add an unset (-FOO) for anything that is in the global environment but not the new. Ok, that sounds reasonable. So you're suggesting to extend update-environment to include a filter (i.e. removing elements from the environment for a session). But there would also be a different list of environment variables to be updated for new sessions than for attaching to an existing session. For the $PWD part: you'd suggest to use $PWD instead of all the cwd member? This would also mean that windows have their own environment as the PWD should not be changed. What about the default-path option? Imo it is just redundant to the global PWD value or the session PWD value. Do you agree that the value of $PWD should be copied from the surrounding environment, if it points to the correct directory? -- Cloud Services Checklist: Pricing and Packaging Optimization This white paper is intended to serve as a reference, checklist and point of discussion for anyone considering optimizing the pricing and packaging model of a cloud services business. Read Now! http://www.accelacomm.com/jaw/sfnl/114/51491232/ ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
home/end in command prompt
Hi, I'd like to suggest that the home and end keys move the cursor to start of line and end of line as usual in command prompt mode. --- mode-key.c |4 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/mode-key.c b/mode-key.c index e45f1c6..140f004 100644 --- a/mode-key.c +++ b/mode-key.c @@ -141,6 +141,8 @@ const struct mode_key_entry mode_key_vi_edit[] = { { KEYC_LEFT,0, MODEKEYEDIT_CURSORLEFT }, { KEYC_RIGHT, 0, MODEKEYEDIT_CURSORRIGHT }, { KEYC_UP, 0, MODEKEYEDIT_HISTORYUP }, + { KEYC_HOME,0, MODEKEYEDIT_STARTOFLINE }, + { KEYC_END, 0, MODEKEYEDIT_ENDOFLINE }, { '$', 1, MODEKEYEDIT_ENDOFLINE }, { '0', 1, MODEKEYEDIT_STARTOFLINE }, @@ -289,6 +291,8 @@ const struct mode_key_entry mode_key_emacs_edit[] = { { KEYC_LEFT,0, MODEKEYEDIT_CURSORLEFT }, { KEYC_RIGHT, 0, MODEKEYEDIT_CURSORRIGHT }, { KEYC_UP, 0, MODEKEYEDIT_HISTORYUP }, + { KEYC_HOME,0, MODEKEYEDIT_STARTOFLINE }, + { KEYC_END, 0, MODEKEYEDIT_ENDOFLINE }, { 0, -1, 0 } }; -- 1.7.7.3 -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
set-titles not working with urxvt
Hi, tmux does not set the title for me when using urxvt. It does work in xterm. I'm using: - Debian squeeze 64 Bit - rxvt-unicode (urxvt) v9.07 - released: 2009-12-27 (TERM=rxvt-unicode) - XTerm(261) (TERM=xterm) I've created a new user without any configuration files to verify that the problem is not depending on my Xresources or any other per-user configuration files. The 1.3 version in debian squeeze does not have this problem. When I compiled the latest SVN version (2642) the problem showed up. I've run git bisect to find the commit and it seems to be introduced in commit 2492: Sync OpenBSD patchset 904: Use the tsl and fsl terminfo(5) capabilities to update terminal title and automatically fill them in on terminals with the XT capability (which means their title setting is xterm-compatible). From hsim at gmx.li. -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users