diff options
| author | srdusr <trevorgray@srdusr.com> | 2025-09-24 05:45:26 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2025-09-24 05:45:26 +0200 |
| commit | d96a422496fe3a6b80659a720e63c6abc41b7de9 (patch) | |
| tree | 20f90abb5ce91875a40027333efbb52877902132 /common/scripts/utils/run_with_display.sh | |
| parent | 521215add7da7fef6722c7b5adec839b84d72db0 (diff) | |
| parent | a1627ac743289e768b138f1a60753a62e0869cc4 (diff) | |
| download | dotfiles-d96a422496fe3a6b80659a720e63c6abc41b7de9.tar.gz dotfiles-d96a422496fe3a6b80659a720e63c6abc41b7de9.zip | |
Add 'common/scripts/' from commit 'a1627ac743289e768b138f1a60753a62e0869cc4'
git-subtree-dir: common/scripts
git-subtree-mainline: 521215add7da7fef6722c7b5adec839b84d72db0
git-subtree-split: a1627ac743289e768b138f1a60753a62e0869cc4
Diffstat (limited to 'common/scripts/utils/run_with_display.sh')
| -rwxr-xr-x | common/scripts/utils/run_with_display.sh | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/common/scripts/utils/run_with_display.sh b/common/scripts/utils/run_with_display.sh new file mode 100755 index 0000000..5f1f3a0 --- /dev/null +++ b/common/scripts/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" "$@" + |
