File: update-ispell-dictionary

package info (click to toggle)
ispell 3.1.20-0.4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,684 kB
  • ctags: 1,065
  • sloc: ansic: 8,367; makefile: 1,916; yacc: 1,712; lisp: 1,613; sh: 1,124; objc: 385; csh: 215
file content (140 lines) | stat: -rw-r--r-- 3,534 bytes parent folder | download | duplicates (2)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh
#
# Bash script to select a new ispell default dictionary.
# Included as part of the Debian/GNU Linux ispell package.
#
# Kenneth MacDonald <K.MacDonald@ed.ac.uk> September 1995
#
# This script makes extensive use of 'update-alternatives' from the
# dpkg suite of programs.  Priority information for each of the
# alternatives is stored, read and acted upon by 'update-alternatives'.
# IMPORTANT: All ispell dictionary packages should install themselves
# with priority 10.  This script will then assign priority 999 to the
# chosen default, and re-run update-alternatives.

set -e

# Find the current dictionaries on the system, and format into a menu.

get_dictionaries() {
 dictionaries=`/usr/sbin/update-alternatives --display ispell-dictionary.hash \
	| grep priority \
	| sort -r -n -k 4 \
	| sed 's+/usr/lib/ispell/++' \
	| sed 's/\.hash//' \
	| awk '{printf ("\\\t[%d] %s\\\n", NR, $1)}'`

 if [ ! -z "$dictionaries" ]
 then 
  num_dictionaries=`echo -e $dictionaries | grep -c '\[.*\]'`
 else
  num_dictionaries='None'
 fi

}
# ----------------------------------------------------------------------

# Find the current default dictionary, set to None if none found.

get_default () {
 current_default=`/usr/sbin/update-alternatives \
	--display ispell-dictionary.hash \
	| grep 999 \
	| sed 's+/usr/lib/ispell/++' \
	| sed 's/\.hash//' \
	| awk '{print $1}'`

 if [ -z $current_default ]
 then
  current_default='None'
 fi
}

# ----------------------------------------------------------------------

# Keep prompting for default until valid choice made.

choose_default ()
{
 echo -e "\n$dictionaries"

 echo -n "Select the number of the default dictionary [1] "
 read num
 selected_num=${num:-1}

 selected=`echo -e $dictionaries | grep "\[$selected_num\]" | awk '{print $2}'`

 if [ -z $selected ]
 then
   echo -e "\nInvalid choice - try again!\n"
   choose_default
 fi
}

# ----------------------------------------------------------------------

# Promote the selected dictionary to be the default.

make_default ()
{
 echo -n "Making $selected the default ispell dictionary..."

 update-alternatives --quiet --install /usr/lib/ispell/default.hash \
	ispell-dictionary.hash /usr/lib/ispell/$selected.hash 999 \
	--slave /usr/lib/ispell/default.aff ispell-dictionary.aff \
	/usr/lib/ispell/$selected.aff > /dev/null

 echo "done."
}

# ----------------------------------------------------------------------

# Demote the old default dictionary.

demote_default ()
{
 echo -n "Demoting $current_default (old default)..."

 update-alternatives --quiet --install /usr/lib/ispell/default.hash \
	ispell-dictionary.hash /usr/lib/ispell/$current_default.hash 10 \
	--slave /usr/lib/ispell/default.aff ispell-dictionary.aff \
	/usr/lib/ispell/$current_default.aff > /dev/null

 echo "done."
}

# ----------------------------------------------------------------------

echo -e "Please wait while I search for ispell dictionaries..."
get_dictionaries

if [ $num_dictionaries != "None" ]
then

 get_default

 if [ $num_dictionaries != "1" ]
 then
  choose_default
 else
   selected=`echo -e $dictionaries | grep '\[.*\]' | awk '{print $2}'`
   echo There is only one installed dictionary - $selected.
 fi

 if ([ $current_default != 'None' ] && [ $current_default != $selected ])
 then
  demote_default
 fi

 if [ $selected != $current_default ]
 then
  make_default
 else
  echo No change - $selected is already the default.
 fi

else
 echo "WARNING: No ispell dictionaries found - recommended to install one."
 exit
fi