keymap revision 238438
1#!/bin/sh 2#- 3# Copyright (c) 2012 Devin Teske 4# All Rights Reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27# $FreeBSD: head/usr.sbin/bsdconfig/console/keymap 238438 2012-07-14 03:16:57Z dteske $ 28# 29############################################################ INCLUDES 30 31BSDCFG_LIBE="/usr/libexec/bsdconfig" 32. $BSDCFG_LIBE/include/common.subr || exit 1 33f_include $BSDCFG_LIBE/include/dialog.subr 34f_include $BSDCFG_LIBE/include/mustberoot.subr 35f_include $BSDCFG_LIBE/include/sysrc.subr 36 37APP_DIR="080.console" 38f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 39 40ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 41[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 42 43############################################################ CONFIGURATION 44 45# 46# List of keymap names 47# 48KEYMAP_NAMES=" 49 belgian brazil_cp850 brazil_iso 50 brazil_iso_accent bulgarian_bds bulgarian_phonetic 51 central_european_iso croatian_iso czech_iso_accent 52 danish_cp865 danish_iso estonian_cp850 53 estonian_iso estonian_iso_15 finnish_cp850 54 finnish_iso french_iso french_iso_accent 55 french_iso_macbook german_cp850 german_iso 56 greek_101 greek_104 greek_elot 57 hungarian_101 hungarian_102 icelandic 58 icelandic_accent italian japanese_106 59 latin_american latin_american_accent norway_iso 60 polish_iso portuguese portuguese_accent 61 russia_koi8_r slovak slovenian 62 spanish spanish_accent swedish_cp850 63 swedish_iso swiss_french_cp850 swiss_french_iso 64 swiss_french_iso_accent swiss_german_cp850 swiss_german_iso 65 swiss_german_iso_accent uk_cp850 uk_iso 66 ukrainian_koi8_u ukrainian_koi8_u_koi8_r usa_capslock_ctrl 67 usa_dvorak usa_dvorak_left usa_dvorak_right 68 usa_emacs usa_iso usa_unix 69" # END-QUOTE 70 71############################################################ FUNCTIONS 72 73# dialog_menu_main 74# 75# Display the dialog(1)-based application main menu. 76# 77dialog_menu_main() 78{ 79 local menu_list size 80 local hline="$hline_choose_a_keyboard_map" 81 local prompt="$msg_keymap_menu_text" 82 83 # 84 # Export variables for awk(1) ENVIRON visibility 85 # 86 local name 87 for name in $KEYMAP_NAMES; do 88 export msg_$name msg_${name}_desc 89 done 90 91 # 92 # Generate a sorted list of keymaps. If the first letter of the keymap 93 # name is unique (case-insensitive) then it is used as the tag to allow 94 # the user to jump to that entry. 95 # 96 menu_list=$( 97 for name in $KEYMAP_NAMES; do 98 eval echo \"\$msg_$name\" msg_$name 99 done | sort | awk 'BEGIN { prefix = "" } 100 { 101 cur_prefix = tolower(substr(ENVIRON[$NF], 1, 1)) 102 printf "'\''" 103 if ( prefix != cur_prefix ) 104 prefix = cur_prefix 105 else 106 printf " " 107 printf "%s'\'' '\''%s'\''\n", 108 ENVIRON[$NF], ENVIRON[$NF"_desc"] 109 }' 110 ) 111 112 size=$( eval f_dialog_menu_size \ 113 \"\$DIALOG_TITLE\" \ 114 \"\$DIALOG_BACKTITLE\" \ 115 \"\$prompt\" \ 116 \"\$hline\" \ 117 $menu_list ) 118 119 eval $DIALOG \ 120 --clear --title \"\$DIALOG_TITLE\" \ 121 --backtitle \"\$DIALOG_BACKTITLE\" \ 122 --hline \"\$hline\" \ 123 --ok-label \"\$msg_ok\" \ 124 --cancel-label \"\$msg_cancel\" \ 125 --menu \"\$prompt\" $size \ 126 $menu_list \ 127 2> "$DIALOG_TMPDIR/dialog.menu.$$" 128} 129 130############################################################ MAIN 131 132# Incorporate rc-file if it exists 133[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 134 135# 136# Process command-line arguments 137# 138while getopts hSX flag; do 139 case "$flag" in 140 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 141 esac 142done 143shift $(( $OPTIND - 1 )) 144 145# 146# Initialize 147# 148f_dialog_init 149f_dialog_title "$msg_system_console_keymap" 150f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 151f_mustberoot_init 152 153# 154# Launch application main menu 155# 156while :; do 157 dialog_menu_main 158 retval=$? 159 mtag=$( f_dialog_menutag ) 160 161 [ $retval -eq 0 ] || f_die 162 163 # 164 # Reverse the users choice into the variable name 165 # 166 keymap_name= 167 mtag="${mtag# }" # remove single leading-space if-present 168 for name in $KEYMAP_NAMES; do 169 if [ "$( eval echo \"\$msg_$name\" )" = "$mtag" ]; then 170 keymap_name="$name" 171 break 172 fi 173 done 174 175 [ "$keymap_name" ] || continue 176 177 case "$keymap_name" in 178 belgian) 179 f_sysrc_set keymap "be.iso" || f_die 180 break ;; 181 brazil_cp850) 182 f_sysrc_set keymap "br275.cp850" || f_die 183 break ;; 184 brazil_iso) 185 f_sysrc_set keymap "br275.iso" || f_die 186 break ;; 187 brazil_iso_accent) 188 f_sysrc_set keymap "br275.iso.acc" || f_die 189 break ;; 190 bulgarian_bds) 191 f_sysrc_set keymap "bg.bds.ctrlcaps" || f_die 192 break ;; 193 bulgarian_phonetic) 194 f_sysrc_set keymap "bg.phonetic.ctrlcaps" || f_die 195 break ;; 196 central_european_iso) 197 f_sysrc_set keymap "ce.iso2" || f_die 198 break ;; 199 croatian_iso) 200 f_sysrc_set keymap "hr.iso" || f_die 201 break ;; 202 czech_iso_accent) 203 f_sysrc_set keymap "cs.latin2.qwertz" || f_die 204 break ;; 205 danish_cp865) 206 f_sysrc_set keymap "danish.cp865" || f_die 207 break ;; 208 danish_iso) 209 f_sysrc_set keymap "danish.iso" || f_die 210 break ;; 211 estonian_cp850) 212 f_sysrc_set keymap "estonian.cp850" || f_die 213 break ;; 214 estonian_iso) 215 f_sysrc_set keymap "estonian.iso" || f_die 216 break ;; 217 estonian_iso_15) 218 f_sysrc_set keymap "estonian.iso15" || f_die 219 break ;; 220 finnish_cp850) 221 f_sysrc_set keymap "finnish.cp850" || f_die 222 break ;; 223 finnish_iso) 224 f_sysrc_set keymap "finnish.iso" || f_die 225 break ;; 226 french_iso) 227 f_sysrc_set keymap "fr.iso" || f_die 228 break ;; 229 french_iso_accent) 230 f_sysrc_set keymap "fr.iso.acc" || f_die 231 break ;; 232 french_iso_macbook) 233 f_sysrc_set keymap "fr.macbook.acc" || f_die 234 break ;; 235 german_cp850) 236 f_sysrc_set keymap "german.cp850" || f_die 237 break ;; 238 german_iso) 239 f_sysrc_set keymap "german.iso" || f_die 240 break ;; 241 greek_101) 242 f_sysrc_set keymap "gr.us101.acc" || f_die 243 break ;; 244 greek_104) 245 f_sysrc_set keymap "el.iso07" || f_die 246 break ;; 247 greek_elot) 248 f_sysrc_set keymap "gr.elot.acc" || f_die 249 break ;; 250 hungarian_101) 251 f_sysrc_set keymap "hu.iso2.101keys" || f_die 252 break ;; 253 hungarian_102) 254 f_sysrc_set keymap "hu.iso2.102keys" || f_die 255 break ;; 256 icelandic) 257 f_sysrc_set keymap "icelandic.iso" || f_die 258 break ;; 259 icelandic_accent) 260 f_sysrc_set keymap "icelandic.iso.acc" || f_die 261 break ;; 262 italian) 263 f_sysrc_set keymap "it.iso" || f_die 264 break ;; 265 japanese_106) 266 f_sysrc_set keymap "jp.106" || f_die 267 break ;; 268 latin_american) 269 f_sysrc_set keymap "latinamerican" || f_die 270 break ;; 271 latin_american_accent) 272 f_sysrc_set keymap "latinamerican.iso.acc" || f_die 273 break ;; 274 norway_iso) 275 f_sysrc_set keymap "norwegian.iso" || f_die 276 break ;; 277 polish_iso) 278 f_sysrc_set keymap "pl_PL.ISO8859-2" || f_die 279 break ;; 280 portuguese) 281 f_sysrc_set keymap "pt.iso" || f_die 282 break ;; 283 portuguese_accent) 284 f_sysrc_set keymap "pt.iso.acc" || f_die 285 break ;; 286 russia_koi8_r) 287 f_sysrc_set keymap "ru.koi8-r" || f_die 288 break ;; 289 slovak) 290 f_sysrc_set keymap "sk.iso2" || f_die 291 break ;; 292 slovenian) 293 f_sysrc_set keymap "si.iso" || f_die 294 break ;; 295 spanish) 296 f_sysrc_set keymap "spanish.iso" || f_die 297 break ;; 298 spanish_accent) 299 f_sysrc_set keymap "spanish.iso.acc" || f_die 300 break ;; 301 swedish_cp850) 302 f_sysrc_set keymap "swedish.cp850" || f_die 303 break ;; 304 swedish_iso) 305 f_sysrc_set keymap "swedish.iso" || f_die 306 break ;; 307 swiss_french_cp850) 308 f_sysrc_set keymap "swissfrench.cp850" || f_die 309 break ;; 310 swiss_french_iso) 311 f_sysrc_set keymap "swissfrench.iso" || f_die 312 break ;; 313 swiss_french_iso_accent) 314 f_sysrc_set keymap "swissfrench.iso.acc" || f_die 315 break ;; 316 swiss_german_cp850) 317 f_sysrc_set keymap "swissgerman.cp850" || f_die 318 break ;; 319 swiss_german_iso) 320 f_sysrc_set keymap "swissgerman.iso" || f_die 321 break ;; 322 swiss_german_iso_accent) 323 f_sysrc_set keymap "swissgerman.iso.acc" || f_die 324 break ;; 325 uk_cp850) 326 f_sysrc_set keymap "uk.cp850" || f_die 327 break ;; 328 uk_iso) 329 f_sysrc_set keymap "uk.iso" || f_die 330 break ;; 331 ukrainian_koi8_u) 332 f_sysrc_set keymap "ua.koi8-u" || f_die 333 break ;; 334 ukrainian_koi8_u_koi8_r) 335 f_sysrc_set keymap "ua.koi8-u.shift.alt" || f_die 336 break ;; 337 usa_capslock_ctrl) 338 f_sysrc_set keymap "us.pc-ctrl" || f_die 339 break ;; 340 usa_dvorak) 341 f_sysrc_set keymap "us.dvorak" || f_die 342 break ;; 343 usa_dvorak_left) 344 f_sysrc_set keymap "us.dvorakl" || f_die 345 break ;; 346 usa_dvorak_right) 347 f_sysrc_set keymap "us.dvorakr" || f_die 348 break ;; 349 usa_emacs) 350 f_sysrc_set keymap "us.emacs" || f_die 351 break ;; 352 usa_iso) 353 f_sysrc_set keymap "us.iso" || f_die 354 break ;; 355 usa_unix) 356 f_sysrc_set keymap "us.unix" || f_die 357 break ;; 358 esac 359done 360 361exit $SUCCESS 362 363################################################################################ 364# END 365################################################################################ 366