TLDR
- Disable
"Run all Konsole windows in a single process"
in konsole settings
- install
xdotool
- Create a global shortcut with the follwing command, replacing
[profile_name]
with your profile's name:
qdbus org.kde.konsole-$(xdotool getwindowpid $(xdotool search --class "konsole" | tail -1)) /Windows/1 newSession "[profile_name]"; xdotool windowactivate $(xdotool search --class "konsole" | tail -1)
There doesn't seem to be a dedicated shortcut for this, and as this post suggests, the default behaviour seems to have changed in recent versions.
However, there is a workaround. As explained here, you can open a new session (=tab) by sending a qdbus
command. The problem with this is that you need to run that command in a shell inside the konsole window, otherwise the environment variables will not be set. Now you could bind the following command to a keyboard shortcut in bash using bind
:
qdbus $KONSOLE_DBUS_SERVICE $KONSOLE_DBUS_WINDOW newSession "[profile_name]"
...but using bind
is not really user friendly and especially not shell independent. Alternatively, you can specify an alias if that is acceptable.
If you want to have a keyboard shortcut that is independent from the shell you are currently using, you'll need to use a global shortcut and inevitably lose the environment variables.
Using a global keyboard shortcut
The process depends on the "Run all Konsole windows in a single process"
setting in "Settings -> Configure Konsole"
.
All windows in one process
If that is enabled, there will be one qdbus service called org.kde.konsole
and each window will be an object Windows/1
, Windows/2
etc. So if you only use one konsole window, the following command would be sufficient for a global keyboard shortcut:
qdbus org.kde.konsole Windows/1 newSession "[profile_name]"
One process for each window
If konsole is configured to spawn a new process for each window, you'll have some additional options. In that case, there will be one qdbus service for each window called org.kde.konsole-[process_id]
, each with only one object Windows/1
.
To retrieve the id of the process owning the konsole window, we can use xdotool
. In each of the following examples, replace [profile_name]
with your profile's name:
open new tab in active konsole window
qdbus org.kde.konsole-$(xdotool getactivewindow getwindowpid) /Windows/1 newSession "[profile_name]"
open new tab in most recently used (or active) konsole window
qdbus org.kde.konsole-$(xdotool getwindowpid $(xdotool search --class "konsole" | tail -1)) /Windows/1 newSession "[profile_name]"
open new tab in most recently used (or active) konsole window and bring it to front
qdbus org.kde.konsole-$(xdotool getwindowpid $(xdotool search --class "konsole" | tail -1)) /Windows/1 newSession "[profile_name]"; xdotool windowactivate $(xdotool search --class "konsole" | tail -1)
qdbus $KONSOLE_DBUS_SERVICE $KONSOLE_DBUS_WINDOW newSession
in konsole and tell me if that opens a new tab. – danzel Mar 07 '20 at 14:14