This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Konsole: profile for new tabs

Tags: None
(comma "," separated)
tomzastrow
Registered Member
Posts
2
Karma
0

Konsole: profile for new tabs

Wed Jan 18, 2023 12:13 pm
Hi,

I'm used to create several profiles in my terminal application, especially to change the color of the background for different tasks / servers I'm logged in.

In Konsole, I can create profiles and give every profile its own color - thats perfect :-)

But when I have a Konsole window and open up a new tab, it always uses the standard profile for a newly opened session. Manual work is necessary to change that new tab also to another profile.

It would be very nice if Konsole would use the profile of the already active session when creating a new one, and not fall back to the default theme ;-)

Cheers,

Tom
dzon
Registered Member
Posts
493
Karma
3

Re: Konsole: profile for new tabs

Wed Jan 18, 2023 2:21 pm
IPersonally I don't use tabs but yeah, some sort of save tabs (session, profile, name , color) could be handy. Anywho, if the profile is your only concern, you could do this:
The command to start a new tab in a running konsole session is the following:qdbus org.kde.konsole-$(xdotool getwindowpid $(xdotool search --class "konsole" | tail -1)) /Windows/1 newSession "[profile_name]"
Obviously, you need xdotool for that and the profile name is the one you want.
Now, you can make a desktop application for that or, you can add this to the right-click menu of the konsole appliction. Now, like I said, I don't use tabs but something similar ( script) should definetely exist for restoring anything from a konsole tab, I just don't know. Anywho..here's to show what I mean: https://imgur.com/a/tI5edCk
So, if you create a bunch of entries (green, red, black profiles....just saying) your workflow will already increase ( albeit just for the profiles of course). Click the konsole icon and rightclick it to instantly add new tabs in different profile colors.
Something similar probably can be done for saving the tabs (name and color), but as far as I know, saved tabs don't save the color profile. Fairly sure someone figured out some script. I know for a fact that someone actually did but plasma changed a few settings and it doesn't work anymore.
#!/bin/bash

# ~/.konsole/watcher.sh

# Watches the konsole qdbus messages and saves session state changes so they can be restored easily
# https://docs.kde.org/trunk5/en/applicat ... tions.html

# Configuration
COMMAND=''
WATCH_INTERVAL_SECONDS=15
SAVEFILE_TERMINAL="${HOME}/.konsole/current-tabs"

# Restore if asked to
if [ "$1" = "restore" ] ; then
echo "Restoring..."
konsole --tabs-from-file ${SAVEFILE_TERMINAL} -e 'bash -c exit'&
fi

# Function to get the current sessions and write them to a file
function getSessions {
pid=$(pgrep konsole -u $USER)
local SESSIONS=$(qdbus org.kde.konsole-$pid | grep /Sessions/)
if [[ ${SESSIONS} ]] ; then
echo "# Most recent session list " $(date) > ${SAVEFILE_TERMINAL}
for i in ${SESSIONS}; do
local FORMAT=$(qdbus org.kde.konsole-$pid $i tabTitleFormat 0)
local PROCESSID=$(qdbus org.kde.konsole-$pid $i processId)
local CWD=$(pwdx ${PROCESSID} | sed -e "s/^[0-9]*: //")
if [[ $(pgrep --parent ${PROCESSID}) ]] ; then
CHILDPID=$(pgrep --parent ${PROCESSID})
COMMAND=$(ps -p ${CHILDPID} -o args=)
fi
echo "workdir: ${CWD};; title: ${FORMAT};; command:${COMMAND}" >> ${SAVEFILE_TERMINAL}
COMMAND=''
done
fi
}

#Update the Konsole sessions every WATCH_INTERVAL_SECONDS seconds
while true; do sleep ${WATCH_INTERVAL_SECONDS}; getSessions; done &


This realm's name is Maya. And she speaks Hertz. But Ahamkara makes a fuzz about it.
tomzastrow
Registered Member
Posts
2
Karma
0

Re: Konsole: profile for new tabs

Wed Jan 18, 2023 3:17 pm
Ah, that looks great, I will try to get this up and running, thanks a lot!

:D
dzon
Registered Member
Posts
493
Karma
3

Re: Konsole: profile for new tabs

Wed Jan 18, 2023 3:45 pm
Waaaaiiiiitt!!!!Found "better"
Here's how it works. Create a text file like this ( my example, you get the point):

title: Inxi ;; command: ~/Scripts/inxi.sh ;;profile:SolusDark
title: Shabbam ;; command: ~/Scripts/shabbam.sh ;;profile: Carl
title: Bash ;; command: /bin/bash ;;profile: Cake

Save it somewhere.

Next, create a desktop file like:

[Desktop Entry]
Comment=
Exec=konsole --tabs-from-file /path/to/that file
Icon=utilities-terminal-symbolic
Name=Tabs
NoDisplay=false
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

Save that one in ~/.local/share/applications. You can now add that to a panel or menu. I tried to add it to the konsole right click (like the previous solution) but somehow it didn't work. This does. Does tabs, with or without command and with a given profile. Done! https://imgur.com/a/ZAE83Yb One "downside". It adds an empty tab with the default profile ;D

EDIT: got the right click entry in konsole working. Only changed the directory. Not sure what happened but hey..

Last edited by dzon on Wed Jan 18, 2023 5:39 pm, edited 1 time in total.


This realm's name is Maya. And she speaks Hertz. But Ahamkara makes a fuzz about it.
dzon
Registered Member
Posts
493
Karma
3

Re: Konsole: profile for new tabs

Wed Jan 18, 2023 3:53 pm
From the docs site:
--tabs-from-file file
Create tabs as specified in the given tabs configuration file.

Note
The file has one tab per line in the following format:

Each line specifies a tab to open using up to 4 fields specifying how it is to open. Fields are delimited with ;; and a field name must have a : appended. Empty lines or lines with # at the beginning are ignored, so you can use line beginning with # to add comments.

title: a name for this tab, tab default if blank or not specified
workdir: working directory, ~ if blank or not specified
profile: a Konsole profile to use, the default if blank or not specified
command: a command to run
Each line should contain at least one of command or profile field.

Example: title: %n;; command: /usr/bin/top ;; profile: Shell


This realm's name is Maya. And she speaks Hertz. But Ahamkara makes a fuzz about it.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]