PATCH: Add optional titles to choose-list
Hi everyone, I wanted some kind of command alias mechanism for tmux, with which I was able to call long and tedious to type tmux commands quickly and often. Choose-list to the rescue, now the only thing needed was a way to give each tmux action a readable and meaningful name. Please find attached a patch, which uses any text up to a '#' in each choose-list item and displays it instead of the expanded template. I look forward to your feedback, on the idea in general, whether you consider it a useful addition, and improvements on how it was implemented. Kind regards, Alexis P.S. Please CC me for I am currently not subscribed to this list. >From 8984146d3b68d09133d318d4c7bca88127d6f458 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sat, 26 Oct 2013 19:38:56 +0200 Subject: [PATCH] Add optional titles to choose-list In order to display a custom title instead of the expanded template for an item in the choose-list prepend the item with the desired title followed by an '#'. For example: :choose-list -l \ 'calendar#neww -n calendar "remind -mc ~/.reminders|$PAGER"',\ 'chat#neww -n irc irssi',\ 'mail#neww -n mail mutt',\ 'rtfm#command-prompt -p "Which manpage do you want?" "neww \"man %%\""',\ '%%' will show the following choose-list: (1) calendar (2) chat (3) todos (4) rtfm --- tmux.1 | 3 +++ tmux.h | 1 + window-choose.c | 18 -- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tmux.1 b/tmux.1 index 1eb02fe..c3e9934 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1159,6 +1159,9 @@ to be selected. .Ar items can be a comma-separated list to display more than one item. If an item has spaces, that entry must be quoted. +Each item can specify a title that will be displayed instead +by separating the title from the item using +.Ql # . After an item is chosen, .Ql %% is replaced by the chosen item in the diff --git a/tmux.h b/tmux.h index 84ad164..333c589 100644 --- a/tmux.h +++ b/tmux.h @@ -872,6 +872,7 @@ struct window_choose_data { struct format_tree *ft; char*command; + char*name; }; struct window_choose_mode_item { diff --git a/window-choose.c b/window-choose.c index 572581a..45f32b1 100644 --- a/window-choose.c +++ b/window-choose.c @@ -93,7 +93,10 @@ window_choose_add(struct window_pane *wp, struct window_choose_data *wcd) ARRAY_EXPAND(&data->list, 1); item = &ARRAY_LAST(&data->list); - item->name = format_expand(wcd->ft, wcd->ft_template); + if (wcd->name != NULL) + item->name = wcd->name; + else + item->name = format_expand(wcd->ft, wcd->ft_template); item->wcd = wcd; item->pos = ARRAY_LENGTH(&data->list) - 1; item->state = 0; @@ -184,6 +187,7 @@ window_choose_data_create(int type, struct client *c, struct session *s) wcd->ft_template = NULL; wcd->command = NULL; + wcd->name = NULL; wcd->wl = NULL; wcd->pane_id = -1; @@ -902,7 +906,17 @@ window_choose_add_item(struct window_pane *wp, struct client *c, wcd = window_choose_data_create(TREE_OTHER, c, c->session); wcd->idx = wl->idx; - wcd->ft_template = xstrdup(template); + char* ft_template = template; + char* entry = xstrdup(template); + char* name = strsep(&entry, "#"); + if (name != NULL && *name != '\0') { + char* item = strsep(&entry, "#"); + if (item != NULL && *item != '\0') + ft_template = item; + } + wcd->name = name; + wcd->ft_template = xstrdup(ft_template); + format_add(wcd->ft, "line", "%u", idx); format_session(wcd->ft, wcd->start_session); format_winlink(wcd->ft, wcd->start_session, wl); -- 1.8.3.4 (Apple Git-47) -- October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: PATCH: Add optional titles to choose-list
Hello Thomas, thank you for your reply and having a look at the patch. Too bad that choose-list is quite likely to go, I found it quite handy. I came up with another solution, which I'd like to present here quickly should anyone desire a similar functionality: Bind a key to create a new tmux window and run a simple shell script, e.g.: bind-key C-e neww ~/bin/tmux-run-action The simple shell script presents a list of items using select (zsh builtin). Each item maps to a function name in said script and when an item is chosen the correlating function is executed. Find below a first version of the simple script, which could be improved by either using dialog et al. or adding a console based version of dmenu¹ (should that exist). I do hope that you will overcome your other personal problems real soon. Wishing you all the best, Alexis ¹ http://tools.suckless.org/dmenu/ http://www.youtube.com/watch?v=Iw6sbQ5NLjM The video does not really show the difference between dmenu, which is a program, that presents a list of items and returns the text of the chosen item and dmenu_run, which uses dmenu to present a list of programs available on the system and then runs the selected program. ===[ BEGIN ~/bin/tmux-run-action] === #!/bin/zsh function mail { tmux neww -t 2 -n mail mutt } function calendar { tmux neww -n calendar wyrd } function irc { tmux neww -n irc irssi } function rtfm { tmux command-prompt -p "Which manpage do you want?" "neww \"man %%\"" } PS3="Run Action: " select action in mail calendar irc rtfm do exec $action break done ===[ END ~/bin/tmux-run-action] === -- Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
linux build failure
I'm trying to build tmux-1.5 using libevent-2.0.13-stable and get the following make errors: gcc -D_GNU_SOURCE -std=c99 -o tmux arguments.o attributes.o cfg.o client.o clock.o cmd-attach-session.o cmd-bind-key.o cmd-break-pane.o cmd-capture-pane.o cmd-choose-buffer.o cmd-choose-client.o cmd-choose-session.o cmd-choose-window.o cmd-clear-history.o cmd-clock-mode.o cmd-command-prompt.o cmd-confirm-before.o cmd-copy-mode.o cmd-delete-buffer.o cmd-detach-client.o cmd-display-message.o cmd-display-panes.o cmd-find-window.o cmd-has-session.o cmd-if-shell.o cmd-join-pane.o cmd-kill-pane.o cmd-kill-server.o cmd-kill-session.o cmd-kill-window.o cmd-link-window.o cmd-list-buffers.o cmd-list-clients.o cmd-list-commands.o cmd-list-keys.o cmd-list-panes.o cmd-list-sessions.o cmd-list-windows.o cmd-list.o cmd-load-buffer.o cmd-lock-server.o cmd-move-window.o cmd-new-session.o cmd-new-window.o cmd-paste-buffer.o cmd-pipe-pane.o cmd-refresh-client.o cmd-rename-session.o cmd-rename-window.o cmd-resize-pane.o cmd-respawn-pane.o cmd-respawn-window.o cmd-rotate-window.o cmd-run-shell.o cmd-save-buffer.o cmd-select-layout.o cmd-select-pane.o cmd-select-window.o cmd-send-keys.o cmd-send-prefix.o cmd-server-info.o cmd-set-buffer.o cmd-set-environment.o cmd-set-option.o cmd-show-buffer.o cmd-show-environment.o cmd-show-messages.o cmd-show-options.o cmd-source-file.o cmd-split-window.o cmd-start-server.o cmd-string.o cmd-suspend-client.o cmd-swap-pane.o cmd-swap-window.o cmd-switch-client.o cmd-unbind-key.o cmd-unlink-window.o cmd.o colour.o environ.o grid-utf8.o grid-view.o grid.o input-keys.o input.o job.o key-bindings.o key-string.o layout-custom.o layout-set.o layout.o log.o mode-key.o names.o options-table.o options.o paste.o resize.o screen-redraw.o screen-write.o screen.o server-client.o server-fn.o server-window.o server.o session.o signal.o status.o tmux.o tty-acs.o tty-keys.o tty-term.o tty.o utf8.o window-choose.o window-clock.o window-copy.o window.o xmalloc.o xterm-keys.o osdep-linux.o imsg.o imsg-buffer.o closefrom.o strlcat.o strlcpy.o fgetln.o getopt.o vis.o unvis.o strtonum.o -lutil -lm -lcurses -levent -lrt cmd-load-buffer.o: In function `cmd_load_buffer_callback': cmd-load-buffer.c:(.text+0x414): undefined reference to `evbuffer_get_length' cmd-pipe-pane.o: In function `cmd_pipe_pane_exec': cmd-pipe-pane.c:(.text+0x34c): undefined reference to `evbuffer_get_length' cmd-run-shell.o: In function `cmd_run_shell_callback': cmd-run-shell.c:(.text+0x17f): undefined reference to `evbuffer_get_length' cmd-run-shell.c:(.text+0x1b5): undefined reference to `evbuffer_pullup' input.o: In function `input_parse': input.c:(.text+0x122): undefined reference to `evbuffer_get_length' input.c:(.text+0x1c3): undefined reference to `evbuffer_pullup' input.c:(.text+0x1d1): undefined reference to `evbuffer_get_length' server-client.o: In function `server_client_check_exit': server-client.c:(.text+0x147e): undefined reference to `evbuffer_get_length' server-client.c:(.text+0x14b4): undefined reference to `evbuffer_get_length' server-client.o: In function `server_client_check_backoff': server-client.c:(.text+0x1524): undefined reference to `evbuffer_get_length' server.o: In function `server_start': server.c:(.text+0x256): undefined reference to `event_reinit' status.o: In function `status_job_callback': status.c:(.text+0x22d0): undefined reference to `evbuffer_get_length' status.c:(.text+0x2306): undefined reference to `evbuffer_pullup' tty-keys.o: In function `tty_keys_next': tty-keys.c:(.text+0x3da): undefined reference to `evbuffer_pullup' tty-keys.c:(.text+0x3f1): undefined reference to `evbuffer_get_length' window.o: In function `window_pane_read_callback': window.c:(.text+0x3586): undefined reference to `evbuffer_get_length' window.c:(.text+0x35ca): undefined reference to `evbuffer_pullup' window.c:(.text+0x360b): undefined reference to `evbuffer_get_length' collect2: ld returned 1 exit status make: *** [tmux] Error 1 with LD_LIBRARY_PATH set to /usr/local/lib:/lib:/usr/lib:/usr/lib/X11 libevent-2.0.13-stable is installed in /usr/local/lib Is this a known issue? I did a quick manual scan of the list archive (I do not subscribe) for the last 3 months and didn't see anything. -- Alexis Layton Permabit Technology Corp. -- All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of 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-d2dcopy2 ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users