1 sub on_osc_seq {
 2     my ($self, $seq, $value) = @_;
 3     # only handle icon setting
 4     return unless $seq == 1;
 5 
 6     # find a suitable full path
 7     my $icon = find_icon_path $self, $value;
 8 
 9     # command to set the icon
10     my @cmd = (
11         'set-icon.py',
12         $icon, # full path to icon
13         sprintf "0x%x", $self->{term}->parent # window ID
14     );
15 
16     # set up PATH, mainly
17     %ENV = %{$self->env};
18 
19     # system's return code is the opposite of what we want
20     !system { $cmd[0] } @cmd;
21 }
22 
23 sub find_icon_path {
24     # do something to determine a nice icon filename
25     my ($self, $search) = @_;
26 
27     # return the value if it looks like it might be a full path
28     return $search if $search =~ m{/};
29 
30     # try an icon dir
31     my $fn = "/usr/share/icons/gnome/32x32/apps/$search.png";
32     return $fn if -e $fn;
33 
34     # fallback to a fixed default
35     "/usr/share/icons/gnome/32x32/apps/gnome-terminal.png";
36 }
37 # vim:set ft=perl: