Skip to content

Instantly share code, notes, and snippets.

@andresmatasuarez
Last active August 29, 2015 14:26
Show Gist options
  • Save andresmatasuarez/f65629098fb58760f333 to your computer and use it in GitHub Desktop.
Save andresmatasuarez/f65629098fb58760f333 to your computer and use it in GitHub Desktop.
Bash | Auto-open terminals running custom commands

Auto-open terminal tabs in Gnome

Features

  • Custom titles
  • Default commands executed on them
  • No need to modify .bashrc
  • Tested in Ubuntu 14.04 and Ubuntu 15.04

Installation & usage

  • Copy the contents of autotty.sh to a file in your system
  • Give it execution rights: chmod +x autotty.sh
  • Edit it!
    • Some default tabs are already added to the script. You can use them, modify them, remove them or mimick them to specify new ones until you are satisfied.
  • Run it with Bash: bash autotty.sh
  • Voilá!
#!/bin/bash
join_arguments(){
for i in "$@"
do
echo -n $i" ; "
done
}
terminal_title(){
echo "echo -ne \"\033]0;"$1"\007\""
}
terminal_commands(){
local commands=$(join_arguments "$@")
echo "/bin/bash -c '$commands'"
}
TITLE_REDIS=$(terminal_title 'redis-server')
TITLE_MONGO=$(terminal_title 'mongod')
TITLE_WORKSPACE=$(terminal_title 'Workspace')
COMMAND_REDIS='redis-server'
COMMAND_MONGO="mongod --dbpath=${HOME}/.mongodbdata"
WD_WORKSPACE="${HOME}/workspace/"
TAB_INIT_REDIS="$(terminal_commands "$TITLE_REDIS" "$COMMAND_REDIS")"
TAB_INIT_MONGO="$(terminal_commands "$TITLE_MONGO" "$COMMAND_MONGO")"
TAB_INIT_PROJECT="$(terminal_commands "$TITLE_WORKSPACE" "exec /bin/bash -i")"
gnome-terminal \
--tab -e "${TAB_INIT_REDIS}" \
--tab -e "${TAB_INIT_MONGO}" \
--tab -e "${TAB_INIT_PROJECT}" --working-directory="${WD_WORKSPACE}" \
/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment