Created
May 20, 2020 19:15
-
-
Save DaveDavenport/67a6047ac25842c5205003bc16b43bfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Examples/test_script_env.sh b/Examples/test_script_env.sh | |
index 64899eb7..638443ae 100755 | |
--- a/Examples/test_script_env.sh | |
+++ b/Examples/test_script_env.sh | |
@@ -1,5 +1,9 @@ | |
#!/usr/bin/env bash | |
- | |
+if [ -z "${ROFI_OUTSIDE}" ] | |
+then | |
+ echo "run this script in rofi". | |
+ exit | |
+fi | |
echo -en "\x00no-custom\x1ftrue\n" | |
echo "${ROFI_RETV}" | |
diff --git a/source/dialogs/script.c b/source/dialogs/script.c | |
index c7cc6d70..d008996e 100644 | |
--- a/source/dialogs/script.c | |
+++ b/source/dialogs/script.c | |
@@ -157,6 +157,10 @@ static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *l | |
env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE); | |
g_free ( str_value ); | |
+ str_value = g_strdup_printf("%d", (int) getpid()); | |
+ env = g_environ_setenv ( env, "ROFI_OUTSIDE", str_value, TRUE); | |
+ g_free ( str_value ); | |
+ | |
if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) { | |
argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); | |
diff --git a/source/rofi.c b/source/rofi.c | |
index 88002324..0b47a9c7 100644 | |
--- a/source/rofi.c | |
+++ b/source/rofi.c | |
@@ -788,6 +788,17 @@ int main ( int argc, char *argv[] ) | |
return EXIT_SUCCESS; | |
} | |
+ { | |
+ const char *ro_pid = g_getenv("ROFI_OUTSIDE"); | |
+ if ( ro_pid != NULL ) { | |
+ int ro_pidi = g_ascii_strtoll ( ro_pid, NULL, 0 ); | |
+ if ( kill ( ro_pidi, 0 ) == 0 ) { | |
+ printf ( "Do not launch rofi from inside rofi.\r\n" ); | |
+ return EXIT_FAILURE; | |
+ } | |
+ } | |
+ } | |
+ | |
// Detect if we are in dmenu mode. | |
// This has two possible causes. | |
// 1 the user specifies it on the command-line. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment