aboutsummaryrefslogtreecommitdiff
path: root/unix/utils/run_with_display.sh
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2025-09-24 05:01:20 +0200
committersrdusr <trevorgray@srdusr.com>2025-09-24 05:01:20 +0200
commit553cb2204b0bf27afe13c6332f5679bbd47172a0 (patch)
tree75c86ff018122a682e0afd7a0e2a0228a63e44bd /unix/utils/run_with_display.sh
parentb20e4e004be74884cc72c57a3128e36fd5177d7a (diff)
downloaddotfiles-553cb2204b0bf27afe13c6332f5679bbd47172a0.tar.gz
dotfiles-553cb2204b0bf27afe13c6332f5679bbd47172a0.zip
Update/Overhaul
Diffstat (limited to 'unix/utils/run_with_display.sh')
-rwxr-xr-xunix/utils/run_with_display.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/unix/utils/run_with_display.sh b/unix/utils/run_with_display.sh
new file mode 100755
index 0000000..5f1f3a0
--- /dev/null
+++ b/unix/utils/run_with_display.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+run_with_display() {
+ output=$("$@" 2>&1)
+ exit_status=$?
+
+ if [[ $exit_status -ne 0 && ("$output" =~ "cannot open display" || "$output" =~ "DISPLAY environment variable is missing") ]]; then
+ DISPLAY=:0 "$@"
+ else
+ echo "$output"
+ return $exit_status
+ fi
+}
+
+# Call this script with any command you want to run
+command=$1
+shift
+run_with_display "$command" "$@"
+