Switch profile in Konsole from command line?

I know that its possible to set profile for new tab, but what if i need to switch profile for current tab?


Solution 1:

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 nicm on #tmux channel.
  • my gist on Github: https://gist.github.com/edouard-lopez/9973056