Open a bunch of tabs in konsole at startup

From raju

Objective

The idea here is to open a bunch of tabs in konsole at startup and cd into specific directories in each tab.

Solution

  1. Create a file with content similar to what is shown below
  2. rajulocal@hogwarts ~ % cat sessions/session.konsole     
    # The lines beginning with '#' are ignored
    # Tokens are separated by ;;
    # Each line should contain at least one of 'command' and 'profile'
    # Supported tokens are title, command and profile
    #
    title: work;; workdir: ~/work;; profile: Shell
    title: stuff;; workdir: ~/sessions;; profile: Shell
    title: fun;; workdir: ~/chess;; profile: Shell
    #
    # some other examples found in the source code of konsole
    #
    # title: This is the title;; command: ssh jupiter
    # title: Top this!;; command: top
    # command: ssh  earth
    # profile: Zsh
    
  3. Run konsole with the "--tabs-from-file" option
  4. rajulocal@hogwarts ~ % konsole --tabs-from-file sessions/session.konsole
    

Result

Multiple tabs in konsole.png

The above screen shot is generated by ksnapshot (0.8.2) and edited by kolourpaint (4.14.2).

System Information

Tested on a machine running Debian Jessie (testing), konsole 2.14.2, KDE 4.13.3, Qt 4.8.6

How I hacked this

First I tried to read the man page of konsole

rajulocal@hogwarts ~ % man konsole                                     
No manual entry for konsole
See 'man 7 undocumented' for help when manual pages are not available.

Ok. So there is no manpage for konsole. It seems someone already filed a bug for it [#648274]. So there is not much I can do on that front.

Next I checked the --help option

rajulocal@hogwarts ~ % konsole --help
Usage: konsole [Qt-options] [KDE-options] [options] [args] 
...
Options:
  --tabs-from-file <file>   Create tabs as specified in given tabs configuration file
...

Ok, so the --tabs-from-file option is interesting. But what about the contents of the <file>? Time to poke around the source code of konsole.

rajulocal@hogwarts ~/work/debian
 % mkdir expt_konsole

rajulocal@hogwarts ~/work/debian
 % cd expt_konsole 

rajulocal@hogwarts ~/work/debian/expt_konsole
 % apt-get source konsole
...
Get:1 http://ftp.us.debian.org/debian/ jessie/main konsole 4:4.14.2-1 (dsc) [2,223 B]
Get:2 http://ftp.us.debian.org/debian/ jessie/main konsole 4:4.14.2-1 (tar) [455 kB]
Get:3 http://ftp.us.debian.org/debian/ jessie/main konsole 4:4.14.2-1 (diff) [7,412 B]
...
dpkg-source: info: extracting konsole in konsole-4.14.2
...

rajulocal@hogwarts ~/work/debian/expt_konsole
 % cd konsole-4.14.2 

rajulocal@hogwarts ~/work/debian/expt_konsole/konsole-4.14.2
 % grep -sirn "tabs-from-file" .
./doc/manual/index.docbook:1085:<term><option>--tabs-from-file </option><parameter>file</parameter></term>
./.pc/debian-T-addition.diff/src/main.cpp:175:    options.add("tabs-from-file <file>",
./src/main.cpp:175:    options.add("tabs-from-file <file>",
./src/Application.cpp:116:        if (args->isSet("tabs-from-file")) {
./src/Application.cpp:184:    const QString tabsFileName(args->getOption("tabs-from-file"));

The Application.cpp in src directory seems to contain code related to this option. Let's check that out.

rajulocal@hogwarts ~/work/debian/expt_konsole/konsole-4.14.2
 % gvim +116 src/Application.cpp 

After some more digging, I found the golden mine

164 /* Documentation for tab file:
165  *
166  * ;; is the token separator
167  * # at the beginning of line results in line being ignored.
168  * supported tokens are title, command and profile.
169  *
170  * Note that the title is static and the tab will close when the
171  * command is complete (do not use --noclose).  You can start new tabs.
172  *
173  * Examples:
174 title: This is the title;; command: ssh jupiter
175 title: Top this!;; command: top
176 #this line is comment
177 command: ssh  earth
178 profile: Zsh
179 */