-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole_setup
executable file
·46 lines (36 loc) · 924 Bytes
/
console_setup
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
#!/usr/bin/env perl
use warnings;
use strict;
my $file = $ARGV[0] || '/etc/default/keyboard'; # For testing
die "No keyboard configuration found\n" unless -r $file;
my @lines;
my $found;
{
open my $fh, "<", $file or die;
while (<$fh>) {
if( /^XKBOPTIONS="(.*)"/ ) {
++$found;
my %keys;
my @options;
foreach my $opt (split ',', $1) {
push @options, $opt;
if( $opt =~ /^(.*?)(?::(.*))?$/ ) {
$keys{$1} = $2;
}
}
push @options, "ctrl:swapcaps" unless exists $keys{ctrl};
push @options, "compose:menu" unless exists $keys{compose};
my $options = join ',', @options;
$_ = qq{XKBOPTIONS="$options"\n};
}
push @lines, $_;
}
}
die "No XKBOPTIONS found in $file\n" unless $found;
{
open my $fh, '>', $file or die "Can't write config file\n";
print {$fh} @lines;
my $command = "setupcon -k";
print "Running \`$command\` to reconfigure console\n";
system $command;
}