How to start a terminal with certain text already input on the command-line?
You can do this with expect (install). Create and make executable ~/bin/myprompt
:
#!/usr/bin/expect -f
# Get a Bash shell
spawn -noecho bash
# Wait for a prompt
expect "$ "
# Type something
send "my text to be posted"
# Hand over control to the user
interact
exit
and run Gnome Terminal with:
gnome-terminal -e ~/bin/myprompt
ændrük's suggestion is very good and worked for me, however the command is hardcoded within the script, and if you resize the terminal window it doesn't work well. Using his code as the base, I've added the ability to send the myprompt script the command as an argument, and this script correctly handles resizing the terminal window.
#!/usr/bin/expect
#trap sigwinch and pass it to the child we spawned
#this allows the gnome-terminal window to be resized
trap {
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
set arg1 [lindex $argv 0]
# Get a Bash shell
spawn -noecho bash
# Wait for a prompt
expect "$ "
# Type something
send $arg1
# Hand over control to the user
interact
exit
and run Gnome Terminal with:
gnome-terminal -e "~/bin/myprompt \"my text to be posted\""