Skip to content

Instantly share code, notes, and snippets.

@shellheim
Last active March 7, 2024 12:20
Show Gist options
  • Save shellheim/4d0386f5af17bcca62a57789be8fd73f to your computer and use it in GitHub Desktop.
Save shellheim/4d0386f5af17bcca62a57789be8fd73f to your computer and use it in GitHub Desktop.
Change kitty terminal's background image with a shortcut
#!/usr/bin/bash
kitty_config="$HOME/.config/kitty/"
kitty_conf_file="$HOME/.config/kitty/kitty.conf"
# Change these as per your liking
dark_image="$HOME/Pictures/Saved Pictures/Wallpapers/dark_house.png"
light_image="$HOME/Pictures/Saved Pictures/Wallpapers/sunrise.png"
cd "$kitty_config" || exit 1
dark_mode=true
rg 'dark_house' &>/dev/null
status="$?"
if [[ $status -ne 0 ]]; then
dark_mode=false
fi
if [[ "$dark_mode" = true ]]; then
sed -i "s#background_image $dark_image#background_image $light_image# " "$kitty_conf_file"
else
sed -i "s#background_image $light_image#background_image $dark_image#" "$kitty_conf_file"
fi
# Press 'Ctrl + Shift + F5' to reload kitty.conf for the change to take effect. ydotool requires ydotoold to be running, you can use a user systemd service to always run ydotoold.
ydotool key 29:1 42:1 63:1 29:0 42:0 63:0
@shellheim
Copy link
Author

I use the fish-shell and have set up a shortcut to execute this script on Ctrl + K

bind \cK 'change_kitty_background'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment