Symlink notifyd.py to osd_server.py for backward compatibility
[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 ################################################################################
8
9 if . /etc/grml/script-functions ; then
10    check4progs xmodmap loadkeys dumpkeys || exit 1
11 fi
12 . /etc/grml/lsb-functions || ( alias einfo=echo ; alias eerror=echo; alias eend=echo )
13
14 emulate zsh
15 autoload -U colors ; colors
16
17 if [[ -z $DISPLAY  ]] ; then # test if X is not running when calling us
18          if [[ $UID != 0 ]] ; then # test if user root did invoke this command
19             eerror "As of Linux 2.6.15 you need root permissions for changing"
20             eerror "the keyboard on console using loadkeys for security reasons."
21             eerror "Run this program with root permissions. Exiting." ; eend 1
22             exit 1
23          fi
24          dumpkeys | grep -q '^keycode  58 = Caps_Lock' && \
25          ( einfo "caps-ctrl - switching caps lock and control key."
26
27            loadkeys <<- EOT
28            keycode 58 = `repeat 15 echo -n 'Control '`
29            keycode 29 = `repeat 7 echo -n 'Caps_Lock '`
30                 EOT
31            eend $?
32
33         ) || (
34           einfo "caps-ctrl - switching caps lock and control key."
35
36            loadkeys <<- EOT
37            keycode 58 = `repeat 15 echo -n 'Caps_Lock '`
38            keycode 29 = `repeat 7 echo -n 'Control '`
39                 EOT
40            eend $?
41          )
42
43 else     # running under X
44         (
45         einfo "caps-ctrl - switching caps lock and control key."
46         einfo "If you notice errors, please make sure the xmodmap you have is right"
47         einfo "or use e.g. \"setxkbmap us\" beforehand."
48         xmodmap -pke | grep 'Caps_Lock' > /dev/null || (
49         xmodmap - <<- EOT
50         keycode 66 = Caps_Lock
51                 EOT
52         )
53
54         xmodmap - <<- EOT
55         remove Lock = Caps_Lock
56         remove Control = Control_L
57         !remove Control = Control_R
58
59         keysym Control_L = Caps_Lock
60         keysym Caps_Lock = Control_L
61         !keysym Control_R = Caps_Lock
62         !keysym Caps_Lock = Control_R
63
64         add lock = Caps_Lock
65         add Control = Control_L
66         !add Control = Control_R
67                 EOT
68         eend $?
69         )
70 fi # end of test if X or console is used
71
72 ## END OF FILE #################################################################