From dda8485d57bc59bd4781ea43cf1dc200351afebe Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Thu, 12 Dec 2024 08:31:51 +0100 Subject: enable SSH host-specific terminal background colors --- nixos/parts/graphical.nix | 12 ++++++++++++ user/zsh/zshrc-graphical.sh | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/nixos/parts/graphical.nix b/nixos/parts/graphical.nix index 990cd9e..8c340fc 100644 --- a/nixos/parts/graphical.nix +++ b/nixos/parts/graphical.nix @@ -18,6 +18,18 @@ brightnessctl wl-clipboard # for wl-copy and wl-paste + # When I ssh into a server my terminal changes to a host-specific background color via + # a LocalCommand configured in ~/.ssh/config and a ZSH function to reset the color on exit. + (writeShellScriptBin "set-bg" '' + #!/usr/bin/env bash + rgb_with_slashes=$(echo "$1" | sed -r 's,(..)(..),\1/\2/,') + echo -en "\033]11;rgb:$rgb_with_slashes\007" + '') + (writeShellScriptBin "reset-bg" '' + #!/usr/bin/env bash + echo -en "\033]111\007" + '') + # graphical tools imv mpv diff --git a/user/zsh/zshrc-graphical.sh b/user/zsh/zshrc-graphical.sh index d60c15a..678448e 100644 --- a/user/zsh/zshrc-graphical.sh +++ b/user/zsh/zshrc-graphical.sh @@ -1,5 +1,16 @@ # This file is sourced by .zshrc if parts/graphical.nix was imported. +function ssh() { + # In my ~/.ssh/config I configure host-specific background colors, for example: + # + # Host forest + # LocalCommand set-bg 003300 + # + # Since SSH doesn't provide a way of running a command on exit, this shell + # function takes care of resetting the background color on exit. + command ssh "$@"; reset-bg +} + if [ $TERM = foot ]; then # Enable spawning of new terminal instances in the current working directory function osc7-pwd() { -- cgit v1.2.3