Working With Yakuake

In the great Linuxification of 2018 I played around with a bunch of desktops. I eventually settled on KDE’s Plasma (don’t @ me), of which the new 5.13 release is very shiny.

Naturally, I also spent in an inordinate amount of time looking at terminals. I spend a lot of my life in one and on OS X I really only had time for iTerm2. I’m pretty picky about UI/UX and have some specific layouts I want like split windows and multi-tabs. As part of this process I tried out the Gnome terminals, even veritable XTerm, Terminator and Tilix amongst others.

As I’d never used a “quake”-style dropdown terminal, I also looked at Tilda. I liked the drop in/drop out feel of a “quake” terminal a lot. The idea of pulling up a terminal either in response to a key or a mouse gesture appeals a lot over clicking on a icon or shuffling through windows to find my terminal session. I wasn’t totally taken with Tilda but that did lead me to Yakuake. Yakuake is a KDE terminal built on KConsole, KDE’s default terminal, and modelled on Guake, a similar terminal for Gnome. It supports tabs, split views, and importantly it has a D-Bus integration allows it to be controlled via the command line and potentially launched with a custom terminal configuration.

Yakuake

In this post I am going to really quickly step through what I did to set Yakuake up

Install Yakuake 🔗︎

I’m running Ubuntu, so Yakuake comes available as a package that I installed via apt.

$ sudo apt install yakuake

Yakuake is available on most distributions and you should be able to install it via your package manager.

Automatically start Yakuake 🔗︎

Next, I wanted Yakuake to run automatically at login. There are a few different ways to do this but when running KDE the simplest is to symlink the Yakuake desktop file into your ~/.kde/Autostart directory. You can usually find the desktop file in /usr/share/applications/ or you can find it via the applications:// panel in Dolphin.

We symlink the file:

$ ln -s /usr/share/applications/org.kde.yakuake.desktop ~/.kde/Autostart/

When if you log out and in again Yakuake will automatically start. You can use the default F12 key to pull the terminal down to test it.

Control Yakuake with D-Bus 🔗︎

You can also configure how many sessions Yakuake launches and how those are configured. We can do this using Yakuake’s D-Bus API interface, either through a script or directly on the command line. We can configure what the sessions look like, their titles, and even execute commands in them, for example tail‘ing a log file in a session.

qdbus 🔗︎

We’re going to use the qdbus binary to configure Yakuake at launch (you could also use dbus-send if you don’t want all of Qt), via a script we’re going to autostart with Yakuake. But first let’s have a look at what we can do with qdbus.

First, let’s check qdbus is installed. On Ubuntu, the binary is provided by the qdbus package and you can check if the package or the binary is installed.

$ which qdbus
/usr/bin/qdbus

If you run qdbus with no options you’ll see a list of all the applications with exposed D-Bus buses that you can interact with. The Yakuake API is available at org.kde.yakuake.

$ qdbus org.kde.yakuake
/
/MainApplication
/Sessions
. . .

We pass command via the qdbus binary to org.kde.yakuake. Let’s try it now. Open Yakuake and run the following command:

$ qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.addSession

This will launch a new session. We pass in the D-Bus bus we want to work with, the specific endpoint we want to send a command to, in our case /yakuake/sessions, and then the command we want to run. Here the org.kde.yakuake.addSession command launches that new session.

If you want to see the full list of available commands for each bus you can use the very cool d-feet application (available via the d-feet package on Ubuntu), which is a D-Bus GUI.

d-feet

We could also configure the title of the session. First, we find the session’s ID.

$ qdbus org.kde.yakuake /yakuake/sessions activeSessionId
11

We can see the session ID is 11. IDs start at 0 and are incremented from there. A session is a tab open in Yakuake. Now we can change the session’s title like so:

$ qdbus org.kde.yakuake /yakuake/tabs org.kde.yakuake.setTabTitle 11 "yosession"

This will name your session: “yosession”.

We can also split the tab horizontally or vertically.

$ qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.splitSessionLeftRight 11

Here we’ve split session 11 vertically. We can use org.kde.yakuake.splitSessionTopBottom to split horizontally.

We can also toggle the Yakuake window open and closed (useful for setting the window state when you launch) like so:

$ qdbus org.kde.yakuake /yakuake/window org.kde.yakuake.toggleWindowState

Lastly, we can configure our sessions to do specific things, for example run commands. We can do this by sending the commands to the bus. We first need to identify the terminal ID. The terminal ID is usually 1:1 with the session ID but if you’ve split the session you’ll increment the terminal ID. Loosely, a session has a single session ID but, depending on how it’s split, many terminal IDs.

You can find the terminal IDs associated with a session like so:

$ qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.terminalIdsForSessionId 0
0,3

This tells us that session 0 has two terminal IDs, it’s likely been split into two, 0 and 3. Let’s say we want to run a command in that second terminal, 3, let’s do that now.

$ qdbus org.kde.yakuake /yakuake/sessions runCommandInTerminal 3 'tail -f /var/log/syslog'"

Here we’ve sent terminal 3 the command tail -f /var/log/syslog.

(You may see D-Bus throw a security warning when you use runCommandInTerminal (or RunCommand or KConsole’s sendText). There is a risk that with this bus open a malicious program could send a command to one of your shells… YMMV on risk here.)

Yakuake setup script 🔗︎

Now let’s write a script that makes use of these API instructions to configure Yakuake. We’ll create the script in the ~/.kde/Autostart directory.

$ touch ~/.kde/Autostart/setup_yakuake

And now we can populate that script.

#!/bin/bash

function makeitso {
cmd="qdbus org.kde.yakuake $1"
eval $cmd &> /dev/null
sleep 0.5
}

makeitso "/yakuake/sessions org.kde.yakuake.addSession"
makeitso "/yakuake/sessions org.kde.yakuake.addSession"
makeitso "/yakuake/sessions org.kde.yakuake.splitSessionLeftRight 0"
makeitso "/yakuake/sessions runCommandInTerminal 2 'tail -f /var/log/syslog'"
makeitso "/yakuake/tabs org.kde.yakuake.setTabTitle 2 'syslog'"

Our script contains a function, called makeitso, a wrapper around the qdbus command, to which we can pass API calls.

In our script we create two additional sessions and split the first session horizontally. We then tail the /var/log/syslog file in the last session we created. Finally, we rename that last session’s title to syslog.

We now mark this script as executable.

$ chmod +x ~/.kde/Autostart/setup_yakuake

You can then test the script by running it manually to see what happens.

Finally, set the script to be auto-started when you login from the System Settings -> Startup and Shutdown -> Autostart screen. Click Add Script… and add our setup_yakuake script.

Autostarting Yakuake script

Now you can launch a custom “quake” style terminal setup and configured how you’d like.

comments powered by Disqus