From 6259704782b2a4d38624b1709c253c0e8117a0f6 Mon Sep 17 00:00:00 2001 From: Anthony Accioly Date: Mon, 28 Feb 2022 02:40:11 +0000 Subject: [PATCH] Launch a new terminal when none is running Launch a new terminal when none is running The user no longer needs to manually launch a terminal emulator before using this script. It works with manual configuration as well as auto detected terminal emulators. When the script is configured to auto detect terminal (option 2), it launches the leftmost valid terminal emulator. --- any_term_dropdown.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/any_term_dropdown.sh b/any_term_dropdown.sh index 8db6365..3986028 100755 --- a/any_term_dropdown.sh +++ b/any_term_dropdown.sh @@ -29,6 +29,20 @@ my_term="xterm" # get terminal emulator and matching name pid ex: 44040485 pid=$(comm -12 <(xdotool search --name "$my_term" | sort) <(xdotool search --class "$my_term" | sort)) +# start a new terminal if none is currently running +if [[ -z "$pid" ]]; then + while IFS='|' read -ra TERMS; do + for candidate_term in "${TERMS[@]}"; do + if command -v "$candidate_term" &>/dev/null; then + ${candidate_term} &>/dev/null & + disown + pid=$! + break + fi + done + done <<<"$my_term" +fi + # get windows id from pid ex: 0x2a00125% wid=$(printf 0x%x "$pid")