Skip to content

Instantly share code, notes, and snippets.

@RodrigoHahn
Created July 23, 2018 14:59
Show Gist options
  • Select an option

  • Save RodrigoHahn/daaf40becefde86af52ebd4ab4a29b36 to your computer and use it in GitHub Desktop.

Select an option

Save RodrigoHahn/daaf40becefde86af52ebd4ab4a29b36 to your computer and use it in GitHub Desktop.
LXTerminal as drop-down (aka guake)
#!/usr/bin/env bash
declare win_id
declare d="$HOME/.ramdisk/lxterminal"
if [[ -d "$d/working" ]] ; then
# wait two second
declare -i waits=0
while [[ $waits -lt 20 ]] ; do
[[ ! -d "$d/working" ]] && break
sleep 0.1s
let "waits++"
done
[[ $waits -ge 20 ]] && exit 1
fi
mkdir "$d/working"
if ! pgrep -x lxterminal &>/dev/null ; then
declare -i loops=0
mkdir -p "$d"
cd "$d"
nohup lxterminal -t LXTerminal --working-directory="$HOME" &>/dev/null 2>&1&
while [[ $loops -le 1000 ]] ; do
let "loops++"
if pgrep -x lxterminal &>/dev/null && wmctrl -l | grep -qP ' LXTerminal$' ; then
break
fi
sleep 0.1s
done
if [[ $loops -ge 1000 ]] ; then
rmdir "$d/working"
exit 1
fi
win_id="$(wmctrl -l | grep -P ' LXTerminal$' | cut -d ' ' -f1 | head -n1)"
echo "$win_id" > "$d/win_id"
wmctrl -i -r "$win_id" -b add,sticky
wmctrl -i -r "$win_id" -b add,maximized_vert,maximized_horz
wmctrl -i -r "$win_id" -b add,fullscreen
wmctrl -i -r "$win_id" -b add,skip_pager,skip_taskbar
wmctrl -i -r "$win_id" -b add,above
wmctrl -i -a "$win_id"
mkdir "$d/open"
elif [[ -f "$d/win_id" ]] ; then
win_id="$(cat "$d/win_id")"
if [[ -d "$d/open" ]] ; then
# xdotool windowminimize $(xdotool getactivewindow)
wmctrl -i -r "$win_id" -b remove,above
wmctrl -i -r "$win_id" -b add,below
for xdotool_win_id in $(xdotool search --class LXTerminal) ; do
xdotool windowminimize "$xdotool_win_id"
done
rmdir "$d/open"
else
mkdir "$d/open"
wmctrl -i -r "$win_id" -b remove,below
wmctrl -i -r "$win_id" -b add,above
wmctrl -i -a "$win_id"
fi
fi
rmdir "$d/working"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment