-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage.pl
executable file
·284 lines (250 loc) · 8.41 KB
/
manage.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#! /usr/bin/perl
#
# File: manage.pl
# Time-stamp: <2022-08-22 11:10:57 ska>
#
# Copyright (C) 2016 by Stefan Kamphausen
#
# Author: Stefan Kamphausen
#
# Description:
# Use this file to manage the init files
use strict;
use warnings;
use Data::Dumper;
use IO::File;
use Carp;
use Getopt::Long;
use Pod::Usage;
use File::Compare;
use File::Copy;
use File::Basename qw/dirname/;
use File::Path qw/make_path/;
my $Version = "1.0";
######################################################################
## OPTIONS
######################################################################
GetOptions(
"install|i" => \my $install,
"collect|c" => \my $collect,
"kdeconfig|k" => \my $kde_config,
"dryrun|n" => \my $dryrun,
"force|f" => \my $force,
"help|h" => \my $help,
"longhelp" => \my $longhelp,
"version|v" => \my $version
) or pod2usage(
verbose => 0,
exitstatus => 1
);
if ($help) {
pod2usage(
verbose => 1,
exitstatus => 0
);
}
if ($longhelp) {
pod2usage(
verbose => 2,
exitstatus => 0
);
}
if ($version) {
print $Version;
exit 0;
}
######################################################################
## MAIN
######################################################################
# all values are relative to $HOME!
my %files =
("dot.emacs.d/init.el" => ".emacs.d/init.el",
"dot.emacs.d/lisp/chb-util.el" => ".emacs.d/lisp/chb-util.el",
"dot.emacs.d/lisp/active-menu.el" => ".emacs.d/lisp/active-menu.el",
"dot.emacs.d/lisp/linmag-mode.el" => ".emacs.d/lisp/linmag-mode.el",
"dot.emacs.d/lisp/mtorus.el" => ".emacs.d/lisp/mtorus.el",
"bash/dot.bash_ska" => ".bash_ska",
"bash/dot.bash_aliases" => ".bash_aliases",
"bash/dot.color-man" => ".color-man",
"dot.screenrc" => ".screenrc"
);
my %kde_settings =
("kwinrc" =>
{"Windows" => [
["AutoRaise", "false"],
["FocusPolicy", "FocusFollowsMouse"],
["RollOverDesktops", "false"],
["GeometryTip", "true"],
],
"Desktops" => [
["Name_1", "1.1"],
["Name_2", "1.2"],
["Name_3", "1.3"],
["Name_4", "2.1"],
["Name_5", "2.2"],
["Name_6", "2.3"],
["Name_7", "3.1"],
["Name_8", "3.2"],
["Name_9", "3.3"],
["Number", "9"],
["Rows", "3"],
],
"ElectricBorders" => [
["Bottom", "None"],
["BottomLeft", "None"],
["BottomRight", "None"],
["Left", "None"],
["Right", "None"],
["Top", "None"],
["TopLeft", "None"],
["TopRight", "None"],
],
"ModifierOnlyShortcuts" => [["Meta", ""]],
"MouseBindings" => [
["CommandActiveTitlebar1", "Raise"],
["CommandActiveTitlebar2", "Nothing"],
["CommandActiveTitlebar3", "Operations menu"],
["CommandAll1", "Move"],
["CommandAll2", "Resize"],
["CommandAll3", "Toggle raise and lower"],
["CommandAllKey", "Meta"],
["CommandAllWheel", "Nothing"],
["CommandInactiveTitlebar1", "Activate and raise"],
["CommandInactiveTitlebar2", "Nothing"],
["CommandInactiveTitlebar3", "Operations menu"],
["CommandTitlebarWheel", "Nothing"],
["CommandWindow1", "Activate, raise and pass click"],
["CommandWindow2", "Activate and pass click"],
["CommandWindow3", "Activate and pass click"],
["CommandWindowWheel", "Scroll"],
],
},
"plasmarc" =>
{
"Theme" => [["name", "breeze-dark"]],
"Wallpapers" => [["usersWallpapers", "/home/ska/etc/desktop/WS2.JPG"]]
},
);
my $home = $ENV{HOME};
unless (defined($home)) {
die "Can not find HOME env var.";
}
if ($collect) {
run_collect();
} elsif ($install) {
run_install();
} elsif ($kde_config) {
run_kde_config();
} else {
pod2usage(verbose => 0, message => "No operation mode.",
exitstatus => 11);
}
exit;
######################################################################
## SUBS
######################################################################
sub run_install {
for my $repo (keys %files) {
my $real = "$home/$files{$repo}";
if ( -f $real && $force) {
print "Updating: \"$repo\" --> \"$real\"\n";
} elsif (! -f $real) {
print "Installing: \"$repo\" --> \"$real\"\n";
} else {
print "Skipping \"$repo\"\n";
next;
}
my $dir = dirname($real);
if (! -d $dir) {
print "Creating directory and parents \"$dir\"\n";
make_path($dir) or die
"Can't create path: $!\n";
}
if ($dryrun) {
print "copy $repo -> $real\n";
} else {
copy($repo, $real) or die
"Could not copy \"$repo\" to \"$real\": $!";
}
}
}
sub run_kde_config {
install_kwin_extensions();
for my $file (keys %kde_settings) {
my %file_settings = %{ $kde_settings{$file} };
for my $group (keys %file_settings) {
my @grp_settings = @{ $file_settings{$group} };
for my $setting (@grp_settings) {
my @cmd =
("kwriteconfig5",
"--file", $file,
"--group", $group,
"--key", $setting->[0],
$setting->[1]);
if ($dryrun) {
print "call: " . join(" ", @cmd) . "\n";
} else {
system(@cmd) == 0 or die
"Error in kwriteconfig5" . $! . Dumper(\@cmd);
}
}
}
}
my $kwin_restart = "qdbus org.kde.KWin /KWin reconfigure";
if ($dryrun) {
print "call: $kwin_restart\n";
} else {
system($kwin_restart) == 0
or die "Can't reconfigure kwin: $!\n";
}
# ? qdbus org.kde.klauncher /KLauncher org.kde.KLauncher.reparseConfiguration
}
sub run_collect {
for my $repo (keys %files) {
my $real = "$home/$files{$repo}";
if (compare($real, $repo) != 0) {
print "Getting update: \"$real\" --> \"$repo\"\n";
if ($dryrun) {
print "copy $real -> $repo\n";
} else {
copy($real, $repo) or die
"Could not copy \"$real\" to \"$repo\": $!";
}
}
}
}
sub install_kwin_extensions {
my $pack = "plasmapkg2 --type kwindscript";
# installed already? If so, update
# else install
}
__END__
######################################################################
## Now Docs...
######################################################################
=head1 NAME
manage.pl - Manage init files in this repository
=head1 SYNOPSIS
manage.pl [-h] [-v] [-f] [-c] [-i]
=head1 OPTIONS
=over
=item B<-i, --install>
Install files from this repo into your home directory. Will not
overwrite already existing files unless forced with --force.
=item B<-c, --collect>
Collect files from your home back into the repo so that you can
compare and possibly update the repo.
=item B<-k, --kdeconfig>
Run KDE configuration using kwriteconfig5.
=item B<-n, --dryrun>
Don't perform any actions, just print what would happen.
=item B<-f, --force>
Force overwriting already existing files during install (aka update).
=item B<-h, --help>
Print help message and exit successfully.
=item B<--longhelp>
Print program documentation.
=item B<-v, --version>
Print version information and exit successfully.
=back
=cut