Skip to content

Instantly share code, notes, and snippets.

@zidizei
Created May 23, 2019 20:58
Show Gist options
  • Save zidizei/a4128de7c11846132ad63ce0732f031b to your computer and use it in GitHub Desktop.
Save zidizei/a4128de7c11846132ad63ce0732f031b to your computer and use it in GitHub Desktop.
Toggle your GNOME Terminal window with a keyboard shortcut under Linux.
#!/bin/bash
function toggle_terminal () {
Terminal_Window_ID=`xdotool search --all --onlyvisible --classname gnome-terminal`
# echo $Terminal_Window_ID
if [[ -z "$Terminal_Window_ID" ]]
then
gnome-terminal --working-directory="/home/$USER"
else
Active_Window_ID=`xdotool getactivewindow`
if [[ "$Terminal_Window_ID" == "$Active_Window_ID" ]]
then
xdotool windowminimize ${Terminal_Window_ID}
else
# Uncomment the following two lines
# if the Terminal is not set to be visible on all Workspaces
#
# Active_Desktop_ID=`xdotool get_desktop`
# xdotool set_desktop_for_window ${Terminal_Window_ID} ${Active_Desktop_ID}
#
xdotool windowraise ${Terminal_Window_ID}
xdotool windowfocus ${Terminal_Window_ID}
fi
fi
}
toggle_terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment