1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[Script] Support a data option that get passed to next execution.

fixes: #1601
This commit is contained in:
Dave Davenport 2022-03-02 22:06:04 +01:00
parent 1d4a8227b2
commit 497d18d108
4 changed files with 23 additions and 0 deletions

View file

@ -7,6 +7,7 @@ then
fi fi
echo -en "\x00no-custom\x1ffalse\n" echo -en "\x00no-custom\x1ffalse\n"
echo -en "\x00data\x1fmonkey do, monkey did\n"
echo -en "\x00use-hot-keys\x1ftrue\n" echo -en "\x00use-hot-keys\x1ftrue\n"
echo -en "${ROFI_RETV}\x00icon\x1ffirefox\x1finfo\x1ftest\n" echo -en "${ROFI_RETV}\x00icon\x1ffirefox\x1finfo\x1ftest\n"
@ -14,3 +15,7 @@ if [ -n "${ROFI_INFO}" ]
then then
echo "my info: ${ROFI_INFO} " echo "my info: ${ROFI_INFO} "
fi fi
if [ -n "${ROFI_DATA}" ]
then
echo "my data: ${ROFI_DATA} "
fi

View file

@ -82,6 +82,10 @@ An integer number with the current state:
.PP .PP
Environment get set when selected entry get set with the property value of the 'info' row option, if set. Environment get set when selected entry get set with the property value of the 'info' row option, if set.
.SS \fB\fCROFI\_DATA\fR
.PP
Environment get set when script sets \fB\fCdata\fR option in header.
.SH Passing mode options .SH Passing mode options
.PP .PP
Extra options, like setting the prompt, can be set by the script. Extra options, like setting the prompt, can be set by the script.
@ -119,6 +123,8 @@ The following extra options exists:
\fBno\-custom\fP: If set to 'true'; only accept listed entries, ignore custom input. \fBno\-custom\fP: If set to 'true'; only accept listed entries, ignore custom input.
.IP \(bu 2 .IP \(bu 2
\fBuse\-hot\-keys\fP: If set to true, it enabled the Custom keybindings for script. Warning this breaks the normal rofi flow. \fBuse\-hot\-keys\fP: If set to true, it enabled the Custom keybindings for script. Warning this breaks the normal rofi flow.
.IP \(bu 2
\fBdata\fP: Passed data to the next execution of the script via \fBROFI\_DATA\fP\&.
.RE .RE

View file

@ -63,6 +63,10 @@ An integer number with the current state:
Environment get set when selected entry get set with the property value of the 'info' row option, if set. Environment get set when selected entry get set with the property value of the 'info' row option, if set.
### `ROFI_DATA`
Environment get set when script sets `data` option in header.
## Passing mode options ## Passing mode options
Extra options, like setting the prompt, can be set by the script. Extra options, like setting the prompt, can be set by the script.
@ -84,6 +88,7 @@ The following extra options exists:
* **delim**: Set the delimiter for for next rows. Default is '\n' and this option should finish with this. Only call this on first call of script, it is remembered for consecutive calls. * **delim**: Set the delimiter for for next rows. Default is '\n' and this option should finish with this. Only call this on first call of script, it is remembered for consecutive calls.
* **no-custom**: If set to 'true'; only accept listed entries, ignore custom input. * **no-custom**: If set to 'true'; only accept listed entries, ignore custom input.
* **use-hot-keys**: If set to true, it enabled the Custom keybindings for script. Warning this breaks the normal rofi flow. * **use-hot-keys**: If set to true, it enabled the Custom keybindings for script. Warning this breaks the normal rofi flow.
* **data**: Passed data to the next execution of the script via **ROFI_DATA**.
## Parsing row options ## Parsing row options

View file

@ -65,6 +65,7 @@ typedef struct {
/** Configuration settings. */ /** Configuration settings. */
char *message; char *message;
char *prompt; char *prompt;
char *data;
gboolean do_markup; gboolean do_markup;
char delim; char delim;
/** no custom */ /** no custom */
@ -134,6 +135,8 @@ static void parse_header_entry(Mode *sw, char *line, ssize_t length) {
pd->no_custom = (strcasecmp(value, "true") == 0); pd->no_custom = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "use-hot-keys") == 0) { } else if (strcasecmp(line, "use-hot-keys") == 0) {
pd->use_hot_keys = (strcasecmp(value, "true") == 0); pd->use_hot_keys = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "data") == 0) {
pd->data = g_strdup(value);
} }
} }
} }
@ -163,6 +166,9 @@ static DmenuScriptEntry *execute_executor(Mode *sw, char *arg,
if (entry && entry->info) { if (entry && entry->info) {
env = g_environ_setenv(env, "ROFI_INFO", entry->info, TRUE); env = g_environ_setenv(env, "ROFI_INFO", entry->info, TRUE);
} }
if (pd->data) {
env = g_environ_setenv(env, "ROFI_DATA", pd->data, TRUE);
}
if (g_shell_parse_argv(sw->ed, &argc, &argv, &error)) { if (g_shell_parse_argv(sw->ed, &argc, &argv, &error)) {
argv = g_realloc(argv, (argc + 2) * sizeof(char *)); argv = g_realloc(argv, (argc + 2) * sizeof(char *));
@ -342,6 +348,7 @@ static void script_mode_destroy(Mode *sw) {
g_free(rmpd->cmd_list); g_free(rmpd->cmd_list);
g_free(rmpd->message); g_free(rmpd->message);
g_free(rmpd->prompt); g_free(rmpd->prompt);
g_free(rmpd->data);
g_free(rmpd->urgent_list); g_free(rmpd->urgent_list);
g_free(rmpd->active_list); g_free(rmpd->active_list);
g_free(rmpd); g_free(rmpd);