Hi,
The pane_default_command test was incomplete in that patch. Here I
corrected it, and also implemented the feature I mentioned in the
previous mail. With this conditional replacement support variables as
values with #variable_name. And with this, I finally can get tmux
automatic renaming work as I wanted :D
Here is the patch:
diff --git a/format.c b/format.c
index 19f322a..9d151fe 100644
--- a/format.c
+++ b/format.c
@@ -150,7 +150,7 @@ format_replace(struct format_tree *ft,
const char *key, size_t keylen, char **buf, size_t *len, size_t *off)
{
char *copy, *ptr;
- const char *value;
+ const char *value, *rvalue;
size_t valuelen;
/* Make a copy of the key. */
@@ -181,6 +181,12 @@ format_replace(struct format_tree *ft,
goto fail;
value = ptr + 1;
}
+
+ if (*value == '#') {
+ rvalue = format_find(ft, value + 1);
+ if (rvalue != NULL)
+ value = rvalue;
+ }
} else {
value = format_find(ft, copy);
if (value == NULL)
@@ -365,6 +371,9 @@ format_window_pane(struct format_tree *ft, struct
window_pane *wp)
unsigned long long size;
u_int i;
u_int idx;
+ char *command_name;
+
+ command_name = pane_command_name(wp->window->active);
size = 0;
for (i = 0; i < gd->hsize; i++) {
@@ -392,8 +401,13 @@ format_window_pane(struct format_tree *ft, struct
window_pane *wp)
if (wp->cwd != NULL)
format_add(ft, "pane_start_path", "%s", wp->cwd);
format_add(ft, "pane_current_path", "%s", osdep_get_cwd(wp->fd));
+ format_add(ft, "pane_current_program", "%s", command_name);
+ format_add(ft, "pane_default_command", "%d",
+ !strcmp(basename(wp->shell), command_name));
format_add(ft, "pane_pid", "%ld", (long) wp->pid);
format_add(ft, "pane_tty", "%s", wp->tty);
+
+ free(command_name);
}
void
On Tue, Dec 11, 2012 at 1:09 AM, Patricio Palladino
<[email protected]> wrote:
> Hello,
>
> On Tue, Dec 11, 2012 at 12:33 AM, Ben Boeckel <[email protected]> wrote:
>> On Mon, Dec 10, 2012 at 05:13:43 GMT, Patricio Palladino wrote:
>> I use the following setup:
>>
>> In .tmux.conf (ignoring colors):
>>
>> setw -g window-status-format '#I.#P#F:#T-#W'
>>
>> At shell startup:
>>
>> tmux_title () {
>> if [ -z "$TMUX" ]; then
>> return 1
>> fi
>>
>> if [ "$#" -eq 0 ]; then
>> tmux display-message -p -t "$TMUX_PANE" -F "#{pane_title}"
>> else
>> local title
>>
>> title="$1"
>> shift
>>
>> printf "\033]2;$title\033\\"
>> fi
>> }
>>
>> # Initialize to nothing iff it isn't already set.
>> if [ "$( tmux_title )" = "$HOSTNAME" ]; then
>> tmux_title ""
>> fi
>>
>> I then have a command "cdb" which uses "bookmarks" to change to a
>> project's directory, clear the directory stack, and to use the
>> tmux_title function to set the title on the pane.
>>
>> By default windows in the status bar look like:
>>
>> 1.0-:-irssi
>>
>> and after using cdb it is:
>>
>> 3.0-:uzbl-zsh
>
> Nice setup. But I find difficult to remember to alwas use a diffent
> command to "cd".
>
> I implementented the automatic-rename-format feature (with a default
> format acting exactly the same as before this patch). I addded the
> pane_default_command (1 or 0) and pane_current_program format
> variables.
>
> diff --git a/format.c b/format.c
> index 19f322a..da260f4 100644
> --- a/format.c
> +++ b/format.c
> @@ -365,6 +365,7 @@ format_window_pane(struct format_tree *ft, struct
> window_pane *wp)
> unsigned long long size;
> u_int i;
> u_int idx;
> + char *command_name;
>
> size = 0;
> for (i = 0; i < gd->hsize; i++) {
> @@ -392,8 +393,14 @@ format_window_pane(struct format_tree *ft, struct
> window_pane *wp)
> if (wp->cwd != NULL)
> format_add(ft, "pane_start_path", "%s", wp->cwd);
> format_add(ft, "pane_current_path", "%s", osdep_get_cwd(wp->fd));
> + command_name = pane_command_name(wp->window->active);
> + format_add(ft, "pane_current_program", "%s", command_name);
> + format_add(ft, "pane_default_command", "%d",
> + wp->cmd != NULL && *wp->cmd == '\0');
> format_add(ft, "pane_pid", "%ld", (long) wp->pid);
> format_add(ft, "pane_tty", "%s", wp->tty);
> +
> + free(command_name);
> }
>
> void
> diff --git a/names.c b/names.c
> index 72f1ad1..2426610 100644
> --- a/names.c
> +++ b/names.c
> @@ -47,8 +47,12 @@ queue_window_name(struct window *w)
> void
> window_name_callback(unused int fd, unused short events, void *data)
> {
> - struct window *w = data;
> - char *name, *wname;
> + struct window *w = data;
> + struct winlink *wl;
> + struct format_tree *ft;
> + struct session *s, *s2;
> + char *name, *wname;
> + const char *name_template;
>
> if (w->active == NULL)
> return;
> @@ -60,25 +64,25 @@ window_name_callback(unused int fd, unused short
> events, void *data)
> }
> queue_window_name(w);
>
> + ft = format_create();
> + RB_FOREACH(s2, sessions, &sessions) {
> + if ((wl = winlink_find_by_window(&s2->windows, w)) == NULL)
> + continue;
> + s = s2;
> + }
> +
> + if (wl != NULL && s != NULL)
> + format_winlink(ft, s, wl);
> +
> + format_window_pane(ft, w->active);
> +
> + name_template = options_get_string(&w->options,
> + "automatic-rename-format");
> +
> if (w->active->screen != &w->active->base)
> - name = NULL;
> - else
> - name = osdep_get_name(w->active->fd, w->active->tty);
> - if (name == NULL)
> wname = default_window_name(w);
> - else {
> - /*
> - * If tmux is using the default command, it will be a login
> - * shell and argv[0] may have a - prefix. Remove this if it is
> - * present. Ick.
> - */
> - if (w->active->cmd != NULL && *w->active->cmd == '\0' &&
> - name != NULL && name[0] == '-' && name[1] != '\0')
> - wname = parse_window_name(name + 1);
> - else
> - wname = parse_window_name(name);
> - free(name);
> - }
> + else
> + wname = format_expand(ft, name_template);
>
> if (w->active->fd == -1) {
> xasprintf(&name, "%s[dead]", wname);
> @@ -91,6 +95,7 @@ window_name_callback(unused int fd, unused short
> events, void *data)
> server_status_window(w);
> }
> free(wname);
> + format_free(ft);
> }
>
> char *
> @@ -129,3 +134,24 @@ parse_window_name(const char *in)
> free(copy);
> return (name);
> }
> +
> +char *
> +pane_command_name(struct window_pane *pane) {
> + char *name, *pname;
> +
> + name = osdep_get_name(pane->fd, pane->tty);
> +
> + /*
> + * If tmux is using the default command, it will be a login
> + * shell and argv[0] may have a - prefix. Remove this if it is
> + * present. Ick.
> + */
> + if (pane->cmd != NULL && *pane->cmd == '\0' &&
> + name != NULL && name[0] == '-' && name[1] != '\0')
> + pname = parse_window_name(name + 1);
> + else
> + pname = parse_window_name(name);
> + free(name);
> +
> + return (pname);
> +}
> diff --git a/options-table.c b/options-table.c
> index 4d1edbd..fa6d052 100644
> --- a/options-table.c
> +++ b/options-table.c
> @@ -469,6 +469,10 @@ const struct options_table_entry window_options_table[]
> = {
> .default_num = 1
> },
>
> + { .name = "automatic-rename-format",
> + .type = OPTIONS_TABLE_STRING,
> + .default_str = "#{pane_current_program}"
> + },
>
> { .name = "c0-change-trigger",
> .type = OPTIONS_TABLE_NUMBER,
> diff --git a/tmux.h b/tmux.h
> index 7de43a8..0f959de 100644
> --- a/tmux.h
> +++ b/tmux.h
> @@ -2243,6 +2243,7 @@ struct
> window_choose_data *window_choose_add_item(struct window_pane *,
> /* names.c */
> void queue_window_name(struct window *);
> char *default_window_name(struct window *);
> +char *pane_command_name(struct window_pane *);
>
> /* signal.c */
> void set_signals(void(*)(int, short, void *));
>
>
> But I still can't have automatic renaming work as I wanted because
> conditional formatting is doesn't allow variables and I would like
> something like this:
> "#{?pane_default_command,#pane_current_path,#pane_current_program}"
>
> If you agree, I can implement that feature too. I wouldn't make it
> completely recursive, just let the user put variables as the possible
> values (not more conditionals).
>
> Patricio
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
tmux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-users