summaryrefslogtreecommitdiffstats
path: root/ximkeys
blob: 6a0a5d87edcf4eaf5bf3f1eef0b4977e42a6a7f1 (plain)
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
#!/bin/bash

# List the X compose sequences available to generate the specified character.
# I.E. the keyboard key sequence to enter after the compose (multi) key or
# a dead key is pressed.
#
# This version has been heavily modified by me (David the H.).  It is now
# bash-specific, reduces the need for external tools (only grep is needed),
# and can handle multiple inputs.
#
# Original script info follows.  For the original version, go here:
# http://www.pixelbeat.org/docs/xkeyboard/
#
# Author:
#    P@draigBrady.com
# Notes:
#    GTK+ apps use a different but broadly similar input method
#    to X by default. Personally I tell GTK+ to use the X one by
#    adding `export GTK_IM_MODULE=xim` to /etc/profile
# Changes:
#    V0.1, 09 Sep 2005, Initial release
#    V0.2, 04 May 2007, Added support for ubuntu
#

if [[ -z $* ]]; then
	echo "Usage: ${0##*/} 'character(s)'" >&2
	echo "Multiple characters are supported." >&2
	echo "They don't need to be space-separated." >&2
	exit 1
fi

if [[ $LANG =~ (.*)[.]UTF.*8 ]]; then

	lang="${BASH_REMATCH[1]}"
	codeset=UTF-8

else

	echo "Sorry, only UTF-8 is supported at present" >&2
	exit 1
	#could try and normalise codeset, and get char with printf %q
	#but would not be general enough I think.

fi

dir=/usr/share/X11/locale #ubuntu

if [[ ! -d "$dir" ]]; then

	dir=/usr/X11R6/lib/X11/locale #redhat/debian

fi

if [[ ! -f "$dir/locale.dir" ]]; then

	echo "Sorry, couldn't find your X windows locale data" >&2
	exit 1

fi

page="$( grep -m1 "${lang}.${codeset}$" <$dir/locale.dir )"
page=${page%%/*}

file="$dir/$page/Compose"

while read -n 1 character; do

	[[ -z $character ]] && continue
	echo "combinations found for [$character]"
	grep -F "\"$character\"" "$file"
	echo

done <<<"$@"

exit 0