Skip to content

Instantly share code, notes, and snippets.

@2shortplanks
Last active February 19, 2020 19:55
Show Gist options
  • Save 2shortplanks/d1eaf5192ec0c076aab6a3c1e2c0dfb9 to your computer and use it in GitHub Desktop.
Save 2shortplanks/d1eaf5192ec0c076aab6a3c1e2c0dfb9 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# set the iterm background depending on what directory you're in.
# 1) put this file in you path.
# 2) put this in your .zshrc
# function chpwd() {
# change-terminal-background
# }
# 3) Create the directory ~/setup/whatever/bg
# 4) put JPG / PNG in there named after the directory names
# (e.g. put foo-bar.jpg in there if you want anything under
# the foo-bar/ directory to have that background
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use MIME::Base64 qw( encode_base64 );
# get a list of all possible terminal backgrounds
my @files = `ls -d ~/setup/*/bg/*`;
chomp for @files;
my %files = map { basename($_) =~ s/[.][^.]+//r => $_ } @files;
my $re = '\\b('.join('|',keys %files).')\b';
print "\x{1b}]1337;SetBackgroundImageFile=";
if ($ENV{PWD} =~ $re) {
print encode_base64( $files{$1} );
}
print "\a";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment