xsay: add support for sselp and xclip; output error message
[grml-scripts.git] / usr_bin / caps-ctrl
1 #!/bin/zsh
2 # Filename:      caps-ctrl
3 # Purpose:       switch caps to control key and vice versa for linux console and X
4 # Authors:       grml-team (grml.org),  (c) Matthias Kopfermann <maddi@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Don Nov 23 22:32:29 CET 2006 [mika]
8 ################################################################################
9
10 if . /etc/grml/script-functions ; then
11    check4progs xmodmap loadkeys dumpkeys || exit 1
12 fi
13 . /etc/grml/lsb-functions || ( alias einfo=echo ; alias eerror=echo; alias eend=echo )
14
15 emulate zsh
16 autoload -U colors ; colors
17
18 if [[ -z $DISPLAY  ]] ; then # test if X is not running when calling us
19          if [[ $UID != 0 ]] ; then # test if user root did invoke this command
20             eerror "As of Linux 2.6.15 you need root permissions for changing"
21             eerror "the keyboard on console using loadkeys for security reasons."
22             eerror "Run this program with root permissions. Exiting." ; eend 1
23             exit 1
24          fi
25          dumpkeys | grep -q '^keycode  58 = Caps_Lock' && \
26          ( einfo "caps-ctrl - switching caps lock and control key."
27
28            loadkeys <<- EOT
29            keycode 58 = `repeat 15 echo -n 'Control '`
30            keycode 29 = `repeat 7 echo -n 'Caps_Lock '`
31                 EOT
32            eend $?
33
34         ) || (
35           einfo "caps-ctrl - switching caps lock and control key."
36
37            loadkeys <<- EOT
38            keycode 58 = `repeat 15 echo -n 'Caps_Lock '`
39            keycode 29 = `repeat 7 echo -n 'Control '`
40                 EOT
41            eend $?
42          )
43
44 else     # running under X
45         (
46         einfo "caps-ctrl - switching caps lock and control key."
47         einfo "If you notice errors, please make sure the xmodmap you have is right"
48         einfo "or use e.g. \"setxkbmap us\" beforehand."
49         xmodmap -pke | grep 'Caps_Lock' > /dev/null || (
50         xmodmap - <<- EOT
51         keycode 66 = Caps_Lock
52                 EOT
53         )
54
55         xmodmap - <<- EOT
56         remove Lock = Caps_Lock
57         remove Control = Control_L
58         !remove Control = Control_R
59
60         keysym Control_L = Caps_Lock
61         keysym Caps_Lock = Control_L
62         !keysym Control_R = Caps_Lock
63         !keysym Caps_Lock = Control_R
64
65         add lock = Caps_Lock
66         add Control = Control_L
67         !add Control = Control_R
68                 EOT
69         eend $?
70         )
71 fi # end of test if X or console is used
72
73 ## END OF FILE #################################################################