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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
|
#! /bin/sh
#############################################################################
# Invoke xterm in UTF-8 mode, using best Unicode fonts found.
# Make sure sufficient Unicode fonts are installed with your X server:
# http://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz
# http://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts-asian.tar.gz
# The script installfonts may help to install and configure them.
# For direct invocation of xterm (or the uxterm script which comes with
# xterm), configure fonts to be used with X resource entries
# (typically in $HOME/.Xdefaults), see Xdefaults.mined sample
# resource file, also in the mined runtime support library.
# NOTE: This script, however, tries its best to use fonts that provide
# a maximum of Unicode support - that's what this script is for.
# That means, it checks if you have the 10x20 Unicode font and a
# matching 20x20 double width font installed (see explanation below).
# If not, it checks if you have the 9x18 Unicode font and a
# matching 18x18 double width font installed and uses them.
# If both are not found, it tries to invoke rxvt with the GNU unifont.
# If either GNU unifont or rxvt are not installed, efont is tried.
# As a last resort, it tries to invoke xterm with 6x13 and 12x13 fonts.
# As a very last fallback, it invokes xterm with its configured default fonts.
#############################################################################
# Information about font usage
# Font selection is a matter of both taste and script coverage.
# This script uses fonts with a good coverage of Unicode script ranges,
# but its order of precedence may not suit your specific needs. In that
# case you should configure your exact desired font preference and
# invoke the desired terminal (xterm, rxvt) directly.
# Coverage of certain scripts would suggest certain font preferences:
# Korean Hangul: GNU unifont
# Devanagari: efont
# Georgian: efont, X fonts
# ...
# The safest way to start an xterm with a maximum of Unicode support is to
# use 18 pixel size and specify single and double width fonts as follows:
# -fn "-misc-fixed-medium-r-*--18-*-*-*-*-90-iso10646-1"
# -fw "-misc-fixed-medium-r-*-*-18-*-*-*-*-180-iso10646-1"
# The 20 pixel size fonts are much clearer in appearance.
# Unfortunately the X Unicode fonts distribution does not include
# matching double width fonts and xterm is not yet capable of combining
# 18 pixel single width with 20 pixel double width fonts.
# The bdf18to20 script, also in the mined runtime support library,
# helps with this issue and generates the missing fonts from the
# 18 pixel double width fonts by padding blank pixels.
# If you have installed those, you can start xterm with these
# font specifications:
# -fn "-misc-fixed-medium-r-*--20-*-*-*-*-100-iso10646-1"
# -fw "-misc-fixed-medium-r-*-*-20-*-*-*-*-200-iso10646-1"
# The following font combines single width and double width characters
# and works with rxvt but NOT with xterm; for use with rxvt, it should
# be specified twice, for bold display as well - otherwise rxvt may
# not display bold characters:
# -fn -gnu-unifont-medium-r-*--16-160-75-75-c-80-iso10646-1
# -fb -gnu-unifont-medium-r-*--16-160-75-75-c-80-iso10646-1
# If the standard Unicode X fonts are not installed, the efont is an
# alternative. Its 16 pixel size font seems to have the best (not
# the largest) coverage of Unicode scripts.
# Note: efont is said to be unsuitable for Polytonic Greek
# -fn "-efont-fixed-medium-r-normal--16-160-75-75-c-80-iso10646-1"
# -fw "-efont-fixed-medium-r-normal--16-160-75-75-c-160-iso10646-1"
# The Unicode VGA font by Dmitry Bolkhovityanov could be used together
# with the double-with 16 pixel efont. The bolkhov font has a better
# coverage of Arabic and some Cyrillic characters than the single-width
# efont but is missing Devanagari, Thai, Georgian, Runic and some Greek.
# -fn "-bolkhov-vga-medium-r-normal--16-160-75-75-c-80-iso10646-1"
# -fw "-efont-fixed-medium-r-normal--16-160-75-75-c-160-iso10646-1"
# The following is a rather tiny alternative for use with xterm:
# -fn "-misc-fixed-medium-r-*--13-*-*-*-*-60-iso10646-1"
# -fw "-misc-fixed-medium-r-*-*-13-*-*-*-*-120-iso10646-1"
#############################################################################
# Fix display reference
case " $*" in
*" -display "*) DISPLAY=`echo " $*" | sed -e 's,.* -display \([^ ]*\).*,\1,'`
export DISPLAY;;
esac
#############################################################################
# Make X tools accessible
PATH=$PATH:/usr/X11/bin
#############################################################################
# Check available fonts
retrievefontlist () {
#echo retrieving $fontlist
xlsfonts -fn "*10646*" > $fontlist &
xlsfonts=$!
sleep 0.5 2> /dev/null || sleep 1
(sleep 11; kill $xlsfonts 2> /dev/null) &
wait $xlsfonts
}
cachefontlist=true # speed up a little bit
if $cachefontlist
then fontlistdir=/tmp
fontlistname=xlsfonts.$DISPLAY
fontlist=$fontlistdir/$fontlistname
if [ -z "`find $fontlistdir -maxdepth 1 -name $fontlistname -mtime 0`" ]
then retrievefontlist
fi
else fontlist=/tmp/xlsfonts.$$
retrievefontlist
fi
#############################################################################
# Select suitable terminal
# check terminal preference command line option
case "$1" in
-rx|-rxvt)
TERM=rxvt
shift;;
-xt|-xterm)
TERM=xterm
shift;;
esac
# find rxvt-unicode
if type urxvt > /dev/null 2>&1
then rxvt=urxvt
elif type urxvt-unicode > /dev/null 2>&1
then rxvt=urxvt-unicode
elif type rxvt > /dev/null 2>&1
then if rxvt -help 2>&1 | sed -e 1q | grep rxvt-unicode > /dev/null
then rxvt=rxvt
else rxvt=
fi
fi
# check user preference
case "$TERM" in
rxvt*) if type "$rxvt" > /dev/null 2>&1
then term="$rxvt"
else term=xterm
fi;;
*) term=xterm;;
esac
#############################################################################
# Check typical Unicode fonts
# set font names
f20w="-misc-fixed-medium-r-[^-]*-[^-]*-20-[^-]*-[^-]*-[^-]*-[^-]*-200-iso10646-1"
f20="-misc-fixed-medium-r-[^-]*--20-[^-]*-[^-]*-[^-]*-[^-]*-100-iso10646-1"
f18w="-misc-fixed-medium-r-[^-]*-[^-]*-18-[^-]*-[^-]*-[^-]*-[^-]*-180-iso10646-1"
f18="-misc-fixed-medium-r-[^-]*--18-[^-]*-[^-]*-[^-]*-[^-]*-90-iso10646-1"
fgnu="-gnu-unifont-medium-r-[^-]*--16-160-75-75-c-80-iso10646-1"
e16w="-efont-fixed-medium-r-normal--16-160-75-75-c-160-iso10646-1"
e16="-efont-fixed-medium-r-normal--16-160-75-75-c-80-iso10646-1"
f13w="-misc-fixed-medium-r-[^-]*-[^-]*-13-[^-]*-[^-]*-[^-]*-[^-]*-120-iso10646-1"
f13="-misc-fixed-medium-r-[^-]*--13-[^-]*-[^-]*-[^-]*-[^-]*-60-iso10646-1"
# check font availability
if egrep -e "$f20w" $fontlist > /dev/null && egrep -e "$f20" $fontlist > /dev/null
then fn="-misc-fixed-medium-r-*--20-*-*-*-*-100-iso10646-1"
fw="-misc-fixed-medium-r-*-*-20-*-*-*-*-200-iso10646-1"
elif egrep -e "$f18w" $fontlist > /dev/null && egrep -e "$f18" $fontlist > /dev/null
then fn="-misc-fixed-medium-r-*--18-*-*-*-*-90-iso10646-1"
fw="-misc-fixed-medium-r-*-*-18-*-*-*-*-180-iso10646-1"
echo 20x20 font not found, using 9x18 with 18x18.
elif egrep -e "$fgnu" $fontlist > /dev/null && type "$rxvt" > /dev/null 2>&1
then term="$rxvt"
fn="-gnu-unifont-medium-r-*--16-160-75-75-c-80-iso10646-1"
echo Large misc-fixed Unicode fonts not found, using rxvt with GNU unifont.
elif egrep -e "$e16w" $fontlist > /dev/null && egrep -e "$e16" $fontlist > /dev/null
then fn="-efont-fixed-medium-r-normal--16-160-75-75-c-80-iso10646-1"
fw="-efont-fixed-medium-r-normal--16-160-75-75-c-160-iso10646-1"
echo Large misc-fixed Unicode fonts and GNU unifont fonts not found, using efont.
elif egrep -e "$f13w" $fontlist > /dev/null && egrep -e "$f13" $fontlist > /dev/null
then fn="-misc-fixed-medium-r-*--13-*-*-*-*-60-iso10646-1"
fw="-misc-fixed-medium-r-*-*-13-*-*-*-*-120-iso10646-1"
echo Large Unicode fonts, GNU unifont, efont not found, using smaller Unicode font.
else echo No Unicode fonts with suitable character repertoire found.
echo Starting xterm with configured default font.
term=xterm.def
fi
# clean up font list (unless kept for caching)
$cachefontlist || rm -f $fontlist
#############################################################################
# Modify locale environment to indicate UTF-8 mode:
# If the effective locale variable (defined and "non-null" environment
# variable in the order of precedence LC_ALL, LC_CTYPE, LANG)
# already indicates UTF-8, nothing needs to be modified.
# Otherwise all variables that affect the locale environment need
# to be manipulated to indicate a UTF-8 locale:
# For all of them, we first check if they already indicate UTF-8
# (using locale charmap; note that not all UTF-8 locales have the proper
# ".UTF-8" or ".utf8" suffix), otherwise:
# an appropriate suffix is appended, then we further check if the
# resulting locale exists, otherwise:
# we fall back to a default locale.
debug=false
defutf8=en_US.UTF-8 # UTF-8 locale most likely to be installed at least
setutf8 () {
case "${LC_ALL:-${LC_CTYPE:-$LANG}}" in
*.UTF-8 | *.utf8) return;;
esac
if type locale > /dev/null 2>&1
then # check if it's a UTF-8 locale without clear indication
if [ "`locale charmap 2> /dev/null`" = "UTF-8" ]
then return
fi
lcvars=`printenv | sed -e "s,^LANG=.*,LANG," -e "s,^\(LC_[A-Z]*\)=.*,\1," -e t -e d`
$debug && echo LC vars: $lcvars
for lcvar in ${lcvars:-LC_CTYPE}
do $debug && echo $lcvar :
lc=`eval echo '$'$lcvar`
$debug && echo lc=$lc
if [ "`LC_ALL=$lc locale charmap 2> /dev/null`" = "UTF-8" ]
then true
else lc=`echo $lc | sed -e "s,[.@].*,,"`.UTF-8
$debug && echo lc=$lc
if [ "`LC_ALL=$lc locale charmap 2> /dev/null`" = "UTF-8" ]
then true
else lc=$defutf8
$debug && echo lc=$lc
fi
eval $lcvar=$lc
eval export $lcvar
fi
done
else
lcvars=`printenv | sed -e "s,^LANG=.*,LANG," -e "s,^\(LC_[A-Z]*\)=.*,\1," -e t -e d`
$debug && echo LC vars: $lcvars
for lcvar in ${lcvars:-LC_CTYPE}
do $debug && echo $lcvar :
lc=`eval echo '$'$lcvar`
$debug && echo lc=$lc
case "$lc" in
*.UTF-8 | *.utf8) true;;
*) lc=`echo $lc | sed -e "s,[.@].*,,"`.UTF-8
$debug && echo lc=$lc
eval $lcvar=$lc
eval export $lcvar
;;
esac
done
fi
}
setutf8
$debug && echo LC_ALL=${LC_ALL-<undefined>}, LC_CTYPE=${LC_CTYPE-<undefined>}, LANG=${LANG-<undefined>}
$debug && exit
#############################################################################
# Further xterm configuration
case "$term" in
xterm*)
# Retrieve X font resource for class UXTerm and use it if available;
# this should actually be achieved with -class UXTerm instead,
# but due to an xterm bug, -e is ignored when -class is used,
# so uterm wouldn't work with any -e parameter.
# Fixed with xterm 162.
xtermversion=`xterm -version 2> /dev/null | sed -e 's,.*(\([0-9]*\)).*,\1,' -e t -e d`
if [ 0$xtermversion -ge 162 ]
then uresources="-class UXTerm"
else # work-around for buggy xterm that ignores -e when -class is present
# also for xterm that understands neither -version nor -class
# (e.g. SunOS /usr/openwin/bin/xterm)
uresources="`
xrdb -query |
sed -e ': start' -e '/\\$/ b cont' -e b -e ': cont' -e N -e 'b start' |
sed -e "/^UXTerm/ s,[ ],,g" -e "s,^UXTerm,-xrm XTerm," -e t -e d
`"
fi
# Enforce UTF-8 mode with xterm. Also make sure that environment settings
# do not override UTF-8 mode as given with -u8 (which used to happen
# with an older version of xterm, even involving luit and hanging the
# terminal in combination with the -e option in that case).
# This is achieved with the X resource UXTerm*locale:false.
uparams="-u8 -xrm UXTerm*locale:UTF-8"
# Add the -mk_width option if available. Only if invoked with -e option.
# Reasons:
# * This option tells xterm to use its own, compiled-in character
# width property tables, rather than using system locale information.
# The advantage is that this information is often newer (referring
# to a newer version of Unicode) than the installed system data.
# Thus the user is enabled to use up-to-date Unicode data by
# using a self-installed copy of xterm, rather than being stuck with
# the Unicode data that the system administrator cares to install.
# * This is especially useful if the application is known to be able to
# recognise that Unicode version, like mined. Thus this feature is
# enabled if the -e option is used, like in the "umined" script which
# calls uterm +sb -e mined.
# * If uterm is called for a general terminal session, other applications
# might be invoked that rely themselves on the system locale mechanism.
# Therefore, this feature is not enabled in that case.
if [ 0$xtermversion -ge 201 ]
then case "$*" in
*-e\ *) uparams="$uparams -mk_width";;
esac
fi
;;
esac
#############################################################################
# Add useful X resources for xterm
# resource preferences that are generally useful
uparams="$uparams \
-xrm *VT100*eightBitOutput:true \
-xrm *VT100*metaSendsEscape:true \
-xrm *VT100*eightBitInput:false \
-xrm *VT100*allowTitleOps:true \
-xrm *VT100*allowTcapOps:true \
"
# -xrm *VT100.Translations:#override\n<Key>Home:string([H)\n<Key>End:string([F) \
# additional resource preferences with application being invoked (esp mined)
case "$*" in
*-e\ *) uparams="$uparams \
-xrm *VT100*deleteIsDEL:true \
-xrm *utf8Title:true \
";;
esac
#############################################################################
# Start Unicode terminal
set -f
case $term in
xterm.def)
exec xterm $uparams $uresources "$@"
;;
xterm)
exec xterm $uparams $uresources -fn "$fn" -fw "$fw" "$@"
;;
"$rxvt")
exec "$rxvt" -fn "$fn" -fb "$fn" "$@"
;;
*)
echo Error: no terminal program selected.
;;
esac
#############################################################################
# End
|