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 <surryh...@gmail.com>
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