diff --git a/Examples/test_script_env.sh b/Examples/test_script_env.sh index b21a0b53..98b8212f 100755 --- a/Examples/test_script_env.sh +++ b/Examples/test_script_env.sh @@ -7,6 +7,7 @@ then fi echo -en "\x00no-custom\x1ffalse\n" +echo -en "\x00data\x1fmonkey do, monkey did\n" echo -en "\x00use-hot-keys\x1ftrue\n" echo -en "${ROFI_RETV}\x00icon\x1ffirefox\x1finfo\x1ftest\n" @@ -14,3 +15,7 @@ if [ -n "${ROFI_INFO}" ] then echo "my info: ${ROFI_INFO} " fi +if [ -n "${ROFI_DATA}" ] +then + echo "my data: ${ROFI_DATA} " +fi diff --git a/doc/rofi-script.5 b/doc/rofi-script.5 index 12ce7cde..3ea713c3 100644 --- a/doc/rofi-script.5 +++ b/doc/rofi-script.5 @@ -82,6 +82,10 @@ An integer number with the current state: .PP 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 .PP 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. .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. +.IP \(bu 2 +\fBdata\fP: Passed data to the next execution of the script via \fBROFI\_DATA\fP\&. .RE diff --git a/doc/rofi-script.5.markdown b/doc/rofi-script.5.markdown index 202737fd..d3482c86 100644 --- a/doc/rofi-script.5.markdown +++ b/doc/rofi-script.5.markdown @@ -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. +### `ROFI_DATA` + +Environment get set when script sets `data` option in header. + ## Passing mode options 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. * **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. + * **data**: Passed data to the next execution of the script via **ROFI_DATA**. ## Parsing row options diff --git a/source/modes/script.c b/source/modes/script.c index f8c1dc7f..cab78515 100644 --- a/source/modes/script.c +++ b/source/modes/script.c @@ -65,6 +65,7 @@ typedef struct { /** Configuration settings. */ char *message; char *prompt; + char *data; gboolean do_markup; char delim; /** 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); } else if (strcasecmp(line, "use-hot-keys") == 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) { 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)) { 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->message); g_free(rmpd->prompt); + g_free(rmpd->data); g_free(rmpd->urgent_list); g_free(rmpd->active_list); g_free(rmpd);