2021-02-15 21:12:50 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry)
|
|
|
|
# https://www.youtube.com/user/gotbletu
|
|
|
|
# DESC: turn any terminal into a dropdown terminal
|
|
|
|
# DEMO: https://www.youtube.com/watch?v=mVw2gD9iiOg
|
|
|
|
# DEPEND: coreutils xdotool wmutils (https://github.com/wmutils/core | https://aur.archlinux.org/packages/wmutils-git/)
|
2022-03-25 18:43:40 +00:00
|
|
|
# CLOG: 2022-03-05 else statement to allow terminal to jump to current virtual desktop if is visible on another desktop
|
2022-03-05 11:07:02 +00:00
|
|
|
# 2022-02-28 added auto launch terminal if none running by https://github.com/aaccioly
|
|
|
|
# 2021-02-10 use comm to match window name and class, this avoids terminal windows with different names
|
2021-02-15 21:12:50 +00:00
|
|
|
# 2015-02-15 0.1
|
|
|
|
|
|
|
|
# get screen resolution width and height
|
|
|
|
ROOT=$(lsw -r)
|
|
|
|
width=$(wattr w "$ROOT")
|
|
|
|
height=$(wattr h "$ROOT")
|
|
|
|
|
|
|
|
# option 1: set terminal emulator manually
|
|
|
|
# my_term=urxvt
|
|
|
|
# my_term=sakura
|
|
|
|
my_term="xterm"
|
|
|
|
# my_term="alacritty"
|
|
|
|
# my_term=terminator
|
|
|
|
# my_term=gnome-terminal
|
2022-03-25 18:43:40 +00:00
|
|
|
# my_term=kitty # for kitty to work uncomment line 30 and comment line 33
|
2021-02-15 21:12:50 +00:00
|
|
|
|
|
|
|
# option 2: auto detect terminal emulator (note: make sure to only open one)
|
2022-01-30 21:14:02 +00:00
|
|
|
# my_term="urxvt|kitty|xterm|uxterm|termite|sakura|lxterminal|terminator|mate-terminal|pantheon-terminal|konsole|gnome-terminal|xfce4-terminal"
|
2021-02-15 21:12:50 +00:00
|
|
|
|
|
|
|
# get terminal emulator pid ex: 44040485
|
|
|
|
# pid=$(xdotool search --class "$my_term" | tail -n1)
|
|
|
|
|
2022-03-25 18:43:40 +00:00
|
|
|
# get terminal emulator and matching name pid ex: 44040485
|
2021-02-15 21:12:50 +00:00
|
|
|
pid=$(comm -12 <(xdotool search --name "$my_term" | sort) <(xdotool search --class "$my_term" | sort))
|
|
|
|
|
2022-02-28 02:40:11 +00:00
|
|
|
# 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"
|
2022-03-25 18:43:40 +00:00
|
|
|
else
|
2022-03-05 11:07:02 +00:00
|
|
|
# get windows id from pid ex: 0x2a00125%
|
|
|
|
wid=$(printf 0x%x "$pid")
|
2022-03-25 18:43:40 +00:00
|
|
|
|
2022-03-05 11:07:02 +00:00
|
|
|
# maximize terminal emulator
|
|
|
|
wrs "$width" "$height" "$wid"
|
2022-03-25 18:43:40 +00:00
|
|
|
|
2022-03-05 11:07:02 +00:00
|
|
|
# toggle show/hide terminal emulator
|
|
|
|
mapw -t "$wid"
|
2022-02-28 02:40:11 +00:00
|
|
|
fi
|