microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.25k stars 8.27k forks source link

Terminal "badge" like function similar to iTerm2 #14088

Open ConercaoAlpha opened 2 years ago

ConercaoAlpha commented 2 years ago

Description of the new feature/enhancement

Something akin to the "badge" functionality in iTerm2. This creates a configurable "badge" in the background of a terminal that can be used to denote whatever is wished. I personally use this feature when working with multiple cloud environments to differentiate between the different terminals

Proposed technical implementation details (optional)

As for how to implement this, I am unsure but perhaps they could be added as a function to Terminal's improving theming? At present this feature is called from a function within my .zshrc file(below)

set_badge () {
printf "\033]1337:SetBadgeFormat=%s\007" $(echo $1 | base64)

This can then be set by using

set_badge $VAR

or

set_badge "something with whitespace"

Example

Screenshot 2022-09-27 at 14 55 26
ConercaoAlpha commented 1 year ago

I've managed to get a workaround for this working using a couple of zsh functions that replace the background image file path in the json.settings.

init_background () {

cd /mnt/c/Users/$(whoami)/AppData/Local/Packages/Microsoft.WindowsTerminal_xxxxxxxxxxxx/LocalState/
jpg=$(grep .jpg settings.json | cut -d "\\" -f 9 | awk '{sub(/..$/,"")}1')

if [ "$jpg" != "blank.jpg" ];
then
  sed -i "s|$jpg|blank.jpg|" settings.json
fi

cd $OLDPWD
}

#Run init_background on login to clear terminal
init_background

set_background () {

cd /mnt/c/Users/$(whoami)/AppData/Local/Packages/Microsoft.WindowsTerminal_xxxxxxxxxxxx/LocalState/
jpg=$(grep .jpg settings.json | cut -d "\\" -f 9 | awk '{sub(/..$/,"")}1')

case ${jpg} in
  blank.jpg)
    sed -i "s|blank.jpg|$ENV_PROFILE.jpg|" settings.json
    ;;
  environment1.jpg)
    sed -i "s|environment1.jpg|$ENV_PROFILE.jpg|" settings.json
    ;;
  environment2.jpg)
    sed -i "s|environment2.jpg|$ENV_PROFILE.jpg|" settings.json
    ;;
  environment3.jpg)
    sed -i "s|environment3.jpg|$ENV_PROFILE.jpg|" settings.json
    ;;
  environment4.jpg)
    sed -i "s|environment24.jpg|$ENV_PROFILE.jpg|" settings.json
    ;;
  environment5.jpg)
    sed -i "s|environment5.jpg|$ENV_PROFILE.jpg|" settings.json
esac

cd $OLDPWD
}

The init_background function sets the background to blank (assuming that the background has been set before). This could probably go into z.logout to clear the profile on close. The second function, set-background allows for chopping and changing between environments. This is doing the same function as setting the badge variable in iTerm2.

Both functions require that you have created a "blank" background image and then one for each of your environments, LIVE, STAGING. DEV/TEST etc etc