Skip to content

Instantly share code, notes, and snippets.

@chetanmeh
Last active February 28, 2020 09:48
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save chetanmeh/5676141 to your computer and use it in GitHub Desktop.
Save chetanmeh/5676141 to your computer and use it in GitHub Desktop.
Script to launch a KDE Konsole window with multiple tabs. It is based on script provided in [Linux Journal](http://www.linuxjournal.com/content/start-and-control-konsole-dbus). It helps to bootstrap development env by launching multiple tabs with preconfigured directory and titles.
source ~/path/to/tabs.sh
load-dev(){
#Create sessi data format '<Tab Name/Title> <Profile Name> <Working Directory>'
local sessions=(
oak Shell 'clear; cd ~/git/apache/oak'
sling Shell 'clear; cd ~/git/apache/sling'
felix Shell 'clear; cd ~/git/apache/felix'
)
start_sessions sessions[@]
}
#!/bin/bash
#
# Based on http://www.linuxjournal.com/content/start-and-control-konsole-dbus
#####################################################################
# Start sessions in konsole.
function start_sessions()
{
#The passed argument is an array so capture it in a variable
declare -a sessions=("${!1}")
local nsessions=0
local session_count=${#sessions[*]}
local i=0
while [[ $i -lt $session_count ]]
do
local name=${sessions[$i]}
let i++
local profile=${sessions[$i]}
let i++
local command=${sessions[$i]}
let i++
echo "Creating $name: $command"
# Starting with a specific profile appears to be broken.
#local session_num=$(qdbus org.kde.konsole /Konsole newSession $profile $HOME)
local session_num=$(qdbus org.kde.konsole /Konsole newSession)
sleep 0.1
qdbus org.kde.konsole /Sessions/$session_num setTitle 0 $name
sleep 0.1
qdbus org.kde.konsole /Sessions/$session_num setTitle 1 $name
sleep 0.1
qdbus org.kde.konsole /Sessions/$session_num sendText "$command"
sleep 0.1
qdbus org.kde.konsole /Sessions/$session_num sendText $'\n'
sleep 0.1
let nsessions++
done
# Activate first session.
while [[ $nsessions -gt 1 ]]
do
qdbus org.kde.konsole /Konsole prevSession
let nsessions--
done
}
@bentzys
Copy link

bentzys commented Aug 29, 2013

You wrote:

Starting with a specific profile appears to be broken.

local session_num=$(qdbus org.kde.konsole /Konsole newSession $profile $HOME)

Good news: It works perfectly for me ;-) (Kubuntu 13.04)

I run at console
load-dev;exit
And my setup is done.

Thanks!

Copy link

ghost commented Feb 28, 2017

Works fine for me as well, thanks!

@codemedic
Copy link

Thanks @chetanmeh
This is brilliant! Saved me a ton of work to figure out those clever combinations!

I have forked and added a few more bells and whistles!
https://gist.github.com/codemedic/18589cbe2adef370c9638b463688af67/

@websers
Copy link

websers commented Mar 11, 2019

can you please create a script that can merge all terminal windows into one window & tabs ?
Thanks for pointing for any hints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment