How could I reroute every "Konsole" opening intent to open a tab instead?

Dolpin, Kate, Kwrite, GIMP, Okular, XNViewMP, Firefox, …

These are apps that all open a new tab when the app is already running and you open a new file / location.

But Konsole, where tabs are just as well integrated, always opens windows.

This is pretty annoying, as it can create a pretty mess.

Do you know how I could reroute every “open in Konsole” intent to open a new tab instead?

I suppose some dbus stuff, but I am a totally noob here.

Interesting: konsole --new-tab opens a window instead of a tab!

I guess you could set it to run in a single process (settings>general) and then change the executable for konsole to konsole --new-tab and make sure the tab bar is always visible.
Futhermore, you can also start konsole with a couple of predefined tabs.
You’d need to create such a file in ~/.konsole ( if needed, create the folder) and it should look something like, for example:
workdir: /home/john;; title: Htop;; command:htop
workdir: /home/john;; title: Ranger;; command:ranger
workdir: /home/john;; title: Cava;; command:cava
You start it with “konsole --tabs-from-file /path/to/the/file”. It’ll always have a default tab, regardless how many predefined tabs you create in that file)

In that same folder you can also create a konsole.css in case you should like some fancy like highlighting the current tab and what not. You can enable that css in konsole ( settings>tabbar/splitters).

Something like ( starting konsole with a bunch of preloads and css):

1 Like

Please file a bug about this :slight_smile:

About launching new tabs instead of new windows, there is a open feature request for that 473907 – "Always open new tabs instead of new windows" feature

I tried to hack together a service menu in combination with a script that lets you choose the window you want to open the new tab in using qdbus (requires kdialog).

Only thing I couldn’t figure out was how to focus/raise the window where the tab is created.

Save in ~/.local/share/kio/servicemenus/openInKonsoleTab.desktop

[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin
MimeType=inode/directory;
Actions=openKonsoleHere;openKonsoleTabHere;
X-KDE-AuthorizeAction=shell_access
X-KDE-Priority=TopLevel

[Desktop Action openKonsoleTabHere]
TryExec=konsole
Exec=konsole-new-tab Default %f
Icon=utilities-terminal
Name=Open Konsole Tab Here
Comment=Opens a new Konsole tab at the current directory

[Desktop Action openKonsoleHere]
TryExec=konsole
Exec=konsole --workdir %f
Icon=utilities-terminal
Name=Open Konsole Here
Comment=Opens a Konsole window at the current directory

Save in ~/.local/bin/konsole-new-tab

#!/usr/bin/env bash

# Default to "Default" profile and home dir (/home/USER/)
PROFILE="${1:Default}"
DIRECTORY="${2:-HOME}"

mapfile -t konsole_windows < <(qdbus "org.kde.konsole*")

echo "windows:" "$(printf "'%s' " "${konsole_windows[@]}")"

formatted_options=()

# Convert options to the desired format
for i in "${!konsole_windows[@]}"; do
    # window_name=$(qdbus "${konsole_windows[$i]}" /MainApplication org.qtproject.Qt.QGuiApplication.applicationDisplayName)
    window_title=$(qdbus "${konsole_windows[$i]}" /konsole/MainWindow_1 org.qtproject.Qt.QWidget.windowTitle)
    window_sessions_count=$(qdbus "${konsole_windows[$i]}" /Windows/1 org.kde.konsole.Window.sessionCount)
    formatted_options+=("$i" "Title: $window_title ($window_sessions_count open tabs)")
    ((i + 1))
done

# Show dialog to pick a window
selected_window=$(kdialog --title "New Konsole Tab" --menu "Select window to open $DIRECTORY in new tab:" "${formatted_options[@]}")

if [ $? -eq 0 ]; then
    # user clicked OK, open new tab in selected window
    qdbus "${konsole_windows[$selected_window]}" /Windows/1 org.kde.konsole.Window.newSession "$PROFILE" "$DIRECTORY"
fi

Not exactly sure why this needs to be filed as a bug. New tab does what is needs to do. It opens a new tab next to an existing one.

Oh, my bad. I was testing plasma 6 before, reverted to kf5/qt5 and is working now. :man_facepalming: I didn’t build Konsole from source so probably that was the reason --new-tab wasn’t working for me.

konsole --new-tab opens a new window on KDE 5.27.8 so I think this is a bug, right?

No it’s not. It only opens a new window if the setting “run in a single window” ( process) isn’t ticked ( as mentioned). The orange one is the new tab in the same window.

1 Like

thanks that is true. Does this mean it actually uses the same process, or just the same window? Does using the same process have any drawbacks?

doing this solved it:

cp /usr/share/applications/org.kde.konsole.desktop ~/.local/share/applications/
sed -i 's/Exec=konsole/Exec=konsole --new-tab/g' ~/.local/share/applictions/org.kde.konsole.desktop &&\
echo "done"

Now Dolphin opens a new konsole tab too!

Programs launching with “Terminal=true” like fish or htop launch in a new window though. Will try to fix that somehow