I know that its possible to set profile for new tab, but what if i need to switch profile for current tab?
2 Answers
From Changing Konsole colors in KDE using the shell the solution is quite simple but cover color
konsoleprofile colors=WhiteOnBlack
# or
konsoleprofile colors=GreenOnBlack
Where the value come from menu Settings > Edit Current Profile… > select Appearance tab.
Tmux
You need to wrap the command in the passthrough escape sequence inside tmux session, otherwise it won't do anything:
printf '\033Ptmux;\033\033]50;konsoleprofile colors=GreenOnBlack\007\033\\'
Here is are tiny helpers I put in my ~/.zshrc:
# Konsole color changing
theme-night() {
switch-term-color "colors=TomorrowNightBlue"
}
theme-light() {
switch-term-color "colors=Tomorrow"
}
switch-term-color() {
arg="${1:-colors=Tomorrow}"
if [[ -z "$TMUX" ]]
then
konsoleprofile "$arg"
else
printf '\033Ptmux;\033\033]50;%s\007\033\\' "$arg"
fi
}
Credits
- Thanks to
nicmon#tmuxchannel. - my gist on Github: https://gist.github.com/edouard-lopez/9973056
- 4,424
As noted by Luis Bocanegra in his answer this can be done by calling setProfile method of org.kde.konsole.Session Konsole's dbus interface.
Example using qdbus-qt6:
qdbus-qt6 $KONSOLE_DBUS_SERVICE $KONSOLE_DBUS_SESSION org.kde.konsole.Session.setProfile 'Profile 1'
Example using dbus-send:
dbus-send --dest=$KONSOLE_DBUS_SERVICE $KONSOLE_DBUS_SESSION --type=method_call org.kde.konsole.Session.setProfile string:'Profile 1'
For example to change Konsole's profile based on current directory in ZSH define the following function in either ~/.zprofile or ~/.zshrc:
chpwd () {
case "$PWD/" in
$HOME/some/directory/*)
konsole_profile='Profile 1'
;;
$HOME/another/directory*)
konsole_profile='Profile 2'
;;
$HOME/*)
konsole_profile='home'
;;
*)
konsole_profile='default'
;;
esac
dbus-send --dest=$KONSOLE_DBUS_SERVICE $KONSOLE_DBUS_SESSION --type=method_call org.kde.konsole.Session.setProfile string:$konsole_profile
}
Related:
Chapter 4. Scripting Konsole
How to check if $PWD is a subdirectory of a given path
Dennis Williamson's answer to the question How to change colors programmatically in Konsole based on current directory?
- 145
- 8