blob: 5f1f3a0d3792bb5594d57d0f3490e42ba2d127f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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" "$@"
|