Created
April 11, 2013 09:19
-
-
Save Raboo/5361942 to your computer and use it in GitHub Desktop.
gttab.sh - a script to run gnome-terminal in new tabs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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