I am trying to write a command that will launch a few terminal tabs, execute something in each tab, and have each tab stay open after the command in finished, so I can look at the output and type more commands in each tab

something like this:

gnome-terminal --tab -e "ls -a" --tab -e "ls"

but the problem with this is that the tabs close as soon as the "ls" commands finish. Does anyone know how to make the tabs stay open?

link|improve this question
feedback

migrated from stackoverflow.com Aug 21 '10 at 5:36

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 4 down vote accepted

Gnome-terminal can either execute a command or open a shell, but not both.

There is a workaround to do both by encapsulating the command and subsequent invocation of the shell into one command.

$ gnome-terminal -e "bash -c \"echo foo; echo bar; exec bash\""

Read this answer to another, similar, question for more alternatives.

link|improve this answer
feedback

If you have xdotool and wmctrl installed, then the following shell script might work:

#!/usr/bin/env bash

window="$(xdotool search --class gnome-terminal | head -1)"
xdotool windowfocus $window
xdotool key ctrl+shift+t
xdotool type "$*"
xdotool key Return

I use it like this:

$ run-in-new-tab 'ls -l'

I found this idea on Trustin Lee's blog.

link|improve this answer
Thanks. This works pretty well. I have to add a sleep 1 after the ctrl+shift+t to get it to work for me though. I'll accept this if nothing else comes up soon – Mark Aug 4 '10 at 5:07
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.