Accepting request 247868 from home:jnweiger:branches:Base:System
- added /usr/bin/kbd, a simple userfriedly keymap switcher. From https://github.com/jnweiger/kbd-wrapper OBS-URL: https://build.opensuse.org/request/show/247868 OBS-URL: https://build.opensuse.org/package/show/Base:System/kbd?expand=0&rev=60
This commit is contained in:
parent
90a984f5cb
commit
753d17b0cd
@ -1,3 +1,9 @@
|
||||
-------------------------------------------------------------------
|
||||
Thu Sep 4 17:51:54 UTC 2014 - jw@owncloud.com
|
||||
|
||||
- added /usr/bin/kbd, a simple userfriedly keymap switcher.
|
||||
From https://github.com/jnweiger/kbd-wrapper
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Aug 22 09:50:15 UTC 2014 - pgajdos@suse.com
|
||||
|
||||
|
148
kbd.pl
Normal file
148
kbd.pl
Normal file
@ -0,0 +1,148 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# simple script to switch the keyboard language
|
||||
# (c) 2014 jw@owncloud.om
|
||||
|
||||
my $sysconffile = '/etc/sysconfig/keyboard';
|
||||
my $mapdir = '/usr/share/kbd/keymaps/i386';
|
||||
|
||||
my $version = '1.0';
|
||||
|
||||
my $what = shift || '-h';
|
||||
|
||||
|
||||
my $v = slurp_sysconf($sysconffile);
|
||||
my $m = find_maps();
|
||||
|
||||
my $l = {
|
||||
'english' => 'us.map',
|
||||
'german' => 'de-latin1-nodeadkeys.map',
|
||||
'french' => 'fr-latin1.map',
|
||||
'spanish' => 'es.map',
|
||||
'italian' => 'it.map',
|
||||
'dutch' => 'nl.map',
|
||||
};
|
||||
|
||||
for my $k (keys %$l)
|
||||
{
|
||||
# zap non-installed languages from our pretty printed list.
|
||||
delete $l->{$k} unless $m->{$l->{$k}} or $m->{"$l->{$k}.gz"};
|
||||
}
|
||||
|
||||
if ($what eq '-h')
|
||||
{
|
||||
print qq{kbd Version $version
|
||||
|
||||
Usage: $0 [option] [mapping]
|
||||
|
||||
Available options are:
|
||||
-l list typical language mappings.
|
||||
-a list all maps
|
||||
-h print this usage
|
||||
|
||||
Specify as a mapping either a language name (seen with -l)
|
||||
or a mapping name (seen with -a). For a mapping name, add a .map suffix.
|
||||
|
||||
Current keymap: $v->{KEYTABLE}
|
||||
};
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($what eq '-l')
|
||||
{
|
||||
for my $k (sort keys %$l)
|
||||
{
|
||||
printf "%-10s %s\n", $k, $l->{$k};
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($what eq '-a' || $what eq '-m')
|
||||
{
|
||||
my @k = map { $1 if /(.*).map(.gz)?$/ } sort keys %$m;
|
||||
print "current keymap: $v->{KEYTABLE}\n";
|
||||
print "available keymaps: @k\n";
|
||||
print "\n\nuse '$0 MAPNAME' to change.\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
$what = $l->{$what} if $l->{$what};
|
||||
|
||||
$what = "$what.gz" if $m->{"$what.gz"};
|
||||
$what = "$what.map" if $m->{"$what.map"};
|
||||
$what = "$what.map.gz" if $m->{"$what.map.gz"};
|
||||
|
||||
die "$what: keymap not found.\n Try $0 -h\n" unless $m->{$what};
|
||||
|
||||
write_sysconf($sysconffile, { 'KEYTABLE' => $what } );
|
||||
# system("kbd_mode -u"); # switch to unicode. Should be the default anyway.
|
||||
system("loadkeys $what"); # now set the keymap.
|
||||
|
||||
# FIXME: is that all?
|
||||
# mayb also do: systemctl restart kbd.service
|
||||
|
||||
exit 0;
|
||||
###################################################################
|
||||
|
||||
sub find_maps
|
||||
{
|
||||
my $maps;
|
||||
|
||||
opendir DIR, $mapdir or die "$0: cannot readdir $mapdir: !$\n";
|
||||
my @d = grep { -d "$mapdir/$_" && !/^\./ } readdir DIR;
|
||||
closedir DIR;
|
||||
for my $d (@d)
|
||||
{
|
||||
opendir DIR, "$mapdir/$d" or die "$0: cannot readdir $mapdir/$d: !$\n";
|
||||
my @f = grep { /\.map(.gz)?$/ } readdir DIR;
|
||||
closedir DIR;
|
||||
for my $f (@f)
|
||||
{
|
||||
$maps->{$f} = "$d/$f";
|
||||
}
|
||||
}
|
||||
return $maps;
|
||||
}
|
||||
|
||||
sub slurp_sysconf
|
||||
{
|
||||
my ($file) = @_;
|
||||
|
||||
my $vals;
|
||||
open my $fd, "<", $file or die "$0: cannot read config file $file: $!\n";
|
||||
while (defined(my $line = <$fd>))
|
||||
{
|
||||
chomp $line;
|
||||
$vals->{$1} = $2 if $line =~ m{^([A-Z_]+)\s*=\s*"(.*)"};
|
||||
}
|
||||
close $fd;
|
||||
return $vals;
|
||||
}
|
||||
|
||||
sub write_sysconf
|
||||
{
|
||||
my ($file, $vals) = @_;
|
||||
|
||||
my @sysconf = ();
|
||||
open my $fd, "<", $file or die "$0: cannot read config file $file: $!\n";
|
||||
while (defined(my $line = <$fd>))
|
||||
{
|
||||
chomp $line;
|
||||
push @sysconf, $line;
|
||||
}
|
||||
close $fd;
|
||||
open $fd, ">", $file or die "$0: cannot write config file $file: $!\n";
|
||||
for my $line (@sysconf)
|
||||
{
|
||||
if ($line =~ m{^([A-Z_]+)\s*=\s*"(.*)"})
|
||||
{
|
||||
my ($keyword,$value) = ($1,$2);
|
||||
if (defined $vals->{$keyword})
|
||||
{
|
||||
$line =~ s{\Q$value\E}{$vals->{$keyword}};
|
||||
}
|
||||
}
|
||||
print $fd "$line\n";
|
||||
}
|
||||
close $fd or die "$0: could not write config file $file: $!\n";
|
||||
}
|
5
kbd.spec
5
kbd.spec
@ -39,6 +39,7 @@ Source9: sysconfig.keyboard
|
||||
Source11: fbtest.c
|
||||
Source12: fbtest.8
|
||||
Source13: guess_encoding.pl
|
||||
Source14: kbd.pl
|
||||
Source42: convert-kbd-mac.sed
|
||||
Source43: repack_kbd.sh
|
||||
Patch0: kbd-1.15.2-prtscr_no_sigquit.patch
|
||||
@ -230,6 +231,7 @@ rm -f %{buildroot}/%{_mandir}/man8/setkeycodes.8*
|
||||
install -m 755 fbtest %{buildroot}/%{_sbindir}
|
||||
install -m 644 %{SOURCE12} %{buildroot}/%{_mandir}/man8/
|
||||
install -m 755 %{SOURCE13} %{buildroot}/%{_bindir}/guess_encoding
|
||||
install -m 755 %{SOURCE14} %{buildroot}/%{_bindir}/kbd
|
||||
#UsrMerge
|
||||
mkdir -p %{buildroot}/bin
|
||||
mkdir -p %{buildroot}/sbin
|
||||
@ -240,6 +242,7 @@ ln -s %{_bindir}/dumpkeys %{buildroot}/bin
|
||||
ln -s %{_bindir}/fgconsole %{buildroot}/bin
|
||||
ln -s %{_bindir}/getunimap %{buildroot}/bin
|
||||
ln -s %{_bindir}/guess_encoding %{buildroot}/bin
|
||||
ln -s %{_bindir}/kbd %{buildroot}/bin
|
||||
ln -s %{_bindir}/kbd_mode %{buildroot}/bin
|
||||
ln -s %{_bindir}/kbdinfo %{buildroot}/bin
|
||||
ln -s %{_bindir}/kbdrate %{buildroot}/bin
|
||||
@ -331,6 +334,7 @@ ln -s %{_bindir}/resizecons %{buildroot}/bin
|
||||
/bin/unicode_stop
|
||||
/bin/kbdrate
|
||||
/bin/guess_encoding
|
||||
/bin/kbd
|
||||
/bin/clrunimap
|
||||
/bin/getunimap
|
||||
/bin/outpsfheader
|
||||
@ -376,6 +380,7 @@ ln -s %{_bindir}/resizecons %{buildroot}/bin
|
||||
%{_bindir}/unicode_stop
|
||||
%{_bindir}/kbdrate
|
||||
%{_bindir}/guess_encoding
|
||||
%{_bindir}/kbd
|
||||
%{_bindir}/clrunimap
|
||||
%{_bindir}/getunimap
|
||||
%{_bindir}/outpsfheader
|
||||
|
Loading…
x
Reference in New Issue
Block a user