Skip to content

Instantly share code, notes, and snippets.

@Raboo
Created April 11, 2013 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raboo/5361942 to your computer and use it in GitHub Desktop.
Save Raboo/5361942 to your computer and use it in GitHub Desktop.
gttab.sh - a script to run gnome-terminal in new tabs.
#!/usr/bin/env bash
#DEBUG_INFO= &>> debug.log
TERM_APP=gnome-terminal
DESKTOP=`xdotool get_desktop`
echo Desktop: $DESKTOP $DEBUG_INFO
SEARCH_CMD="xdotool search --onlyvisible --desktop $DESKTOP --limit 1 --class $TERM_APP"
#SEARCH_CMD="xdotool search --onlyvisible --desktop $DESKTOP --limit 0 --class $TERM_APP"
echo Search command: $SEARCH_CMD $DEBUG_INFO
TERM_WINDOW="$($SEARCH_CMD)"
echo Terminal window: $TERM_WINDOW $DEBUG_INFO
if [ -n "$TERM_WINDOW" ]; then
# A terminal window exists, open a new tab:
xdotool windowfocus --sync $TERM_WINDOW $DEBUG_INFO
xdotool key ctrl+shift+t $DEBUG_INFO
sleep 0.5
if [ -n "$*" ]; then
# Input the command to execute
xdotool type "$*" $DEBUG_INFO
# Press Enter
xdotool key Return $DEBUG_INFO
fi
else
# No terminal window exists on the desktop; create one:
if [ -n "$*" ]; then
$TERM_APP -e "$*"
else
$TERM_APP
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment