Skip to content

Instantly share code, notes, and snippets.

@73
Created February 18, 2020 15:04
Show Gist options
  • Save 73/40b1863dcac0770351ccbe799d8bcd04 to your computer and use it in GitHub Desktop.
Save 73/40b1863dcac0770351ccbe799d8bcd04 to your computer and use it in GitHub Desktop.
Workspace-aware on-demand terminal window (x11 only)
#!/bin/bash
_cmd="gnome-terminal"
_terminal="usr/libexec/gnome-terminal"
_current_workspace=$(wmctrl -d | grep -Po "^[\d]+(?= \*)")
_windows=$(wmctrl -lp | awk '{ if ($2 == cws) print $1,$3 }' cws="${_current_workspace}" )
_active_win=$(xprop -root _NET_ACTIVE_WINDOW | sed 's/.* //')
echo "${_windows}" | while read _window
do
# echo "${_window}"
_desc=($_window)
# echo "${_desc[0]}"
if readlink -f "/proc/${_desc[1]}/exe" | grep -q "$_terminal"
then
if [ $(printf "%d" ${_active_win}) -eq $(printf "%d" ${_desc[0]}) ]
then
if [ $(echo "${_windows}" | wc -l) != 1 ]
then
xdotool getactivewindow windowminimize
else
xdotool getactivewindow windowkill
fi
else
wmctrl -ia "${_desc[0]}"
fi
exit 73
fi
done
if [ $? != 73 ]
then
eval "$_cmd"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment