-
Notifications
You must be signed in to change notification settings - Fork 0
/
change-theme.pl
executable file
·68 lines (57 loc) · 1.53 KB
/
change-theme.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env perl
use File::Find;
my $dir = $ENV{HOME} . "/.config/rofi/";
my $colors_dir = $ENV{HOME} . "/.config/rofi/colors";
my $theme;
my @all_config_files;
sub wanted {
my $name = $File::Find::name;
my $file = (split "/", $name)[-1];
if ($file =~ /^\./) { return } # ignore hidden files/dirs
if (-f && $_ =~ /config.rasi$/) {
push(@all_config_files, $name);
}
}
sub update_file {
my ($config) = @_;
my $config_content = "";
# read config file
open(FH, '<' . $config) or die "Unable to open\n";
while(<FH>) {
if ($_ =~ /import.*colors/) {
$config_content .= qq{\@import\t "colors/$theme.rasi"\n};
next;
}
$config_content .= $_;
}
close(FH);
# write config file
open(FH, '>' . $config) or die "Unable to open\n";
print FH $config_content;
close(FH);
}
sub main {
if (scalar @ARGV > 0) {
my @all_themes = split "\n", `ls $colors_dir`;
@all_themes = sort { length($a) <=> length($b) } @all_themes;
($theme) = grep /$ARGV[0]/, @all_themes;
unless ($theme) {
print "No theme found for \'$ARGV[0]\'\n";
}
}
unless($theme) {
$theme = `ls $colors_dir | fzf`;
chomp $theme;
}
if ($theme) {
print "\'$theme\' rofi theme selected\n";
$theme =~ s/.rasi//g;
find( \&wanted, $dir);
foreach my $f (@all_config_files) {
update_file($f)
}
} else {
print "No theme selected\n";
}
}
main()