keymap revision 244674
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 244674 2012-12-25 09:30:25Z dteske $ 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_include $BSDCFG_SHARE/dialog.subr 34f_include $BSDCFG_SHARE/mustberoot.subr 35f_include $BSDCFG_SHARE/sysrc.subr 36 37BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console" 38f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 39 40ipgm=$( f_index_menusel_keyword $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 local dialog_menu 120 dialog_menu=$( eval $DIALOG \ 121 --clear --title \"\$DIALOG_TITLE\" \ 122 --backtitle \"\$DIALOG_BACKTITLE\" \ 123 --hline \"\$hline\" \ 124 --ok-label \"\$msg_ok\" \ 125 --cancel-label \"\$msg_cancel\" \ 126 --menu \"\$prompt\" $size \ 127 $menu_list \ 128 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 129 ) 130 local retval=$? 131 setvar DIALOG_MENU_$$ "$dialog_menu" 132 return $retval 133} 134 135############################################################ MAIN 136 137# Incorporate rc-file if it exists 138[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 139 140# 141# Process command-line arguments 142# 143while getopts hSX flag; do 144 case "$flag" in 145 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 146 esac 147done 148shift $(( $OPTIND - 1 )) 149 150# 151# Initialize 152# 153f_dialog_title "$msg_system_console_keymap" 154f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 155f_mustberoot_init 156 157# 158# Launch application main menu 159# 160while :; do 161 dialog_menu_main 162 retval=$? 163 mtag=$( f_dialog_menutag ) 164 165 [ $retval -eq 0 ] || f_die 166 167 # 168 # Reverse the users choice into the variable name 169 # 170 keymap_name= 171 mtag="${mtag# }" # remove single leading-space if-present 172 for name in $KEYMAP_NAMES; do 173 if [ "$( eval echo \"\$msg_$name\" )" = "$mtag" ]; then 174 keymap_name="$name" 175 break 176 fi 177 done 178 179 [ "$keymap_name" ] || continue 180 181 case "$keymap_name" in 182 belgian) 183 f_sysrc_set keymap "be.iso" || f_die 184 break ;; 185 brazil_cp850) 186 f_sysrc_set keymap "br275.cp850" || f_die 187 break ;; 188 brazil_iso) 189 f_sysrc_set keymap "br275.iso" || f_die 190 break ;; 191 brazil_iso_accent) 192 f_sysrc_set keymap "br275.iso.acc" || f_die 193 break ;; 194 bulgarian_bds) 195 f_sysrc_set keymap "bg.bds.ctrlcaps" || f_die 196 break ;; 197 bulgarian_phonetic) 198 f_sysrc_set keymap "bg.phonetic.ctrlcaps" || f_die 199 break ;; 200 central_european_iso) 201 f_sysrc_set keymap "ce.iso2" || f_die 202 break ;; 203 croatian_iso) 204 f_sysrc_set keymap "hr.iso" || f_die 205 break ;; 206 czech_iso_accent) 207 f_sysrc_set keymap "cs.latin2.qwertz" || f_die 208 break ;; 209 danish_cp865) 210 f_sysrc_set keymap "danish.cp865" || f_die 211 break ;; 212 danish_iso) 213 f_sysrc_set keymap "danish.iso" || f_die 214 break ;; 215 estonian_cp850) 216 f_sysrc_set keymap "estonian.cp850" || f_die 217 break ;; 218 estonian_iso) 219 f_sysrc_set keymap "estonian.iso" || f_die 220 break ;; 221 estonian_iso_15) 222 f_sysrc_set keymap "estonian.iso15" || f_die 223 break ;; 224 finnish_cp850) 225 f_sysrc_set keymap "finnish.cp850" || f_die 226 break ;; 227 finnish_iso) 228 f_sysrc_set keymap "finnish.iso" || f_die 229 break ;; 230 french_iso) 231 f_sysrc_set keymap "fr.iso" || f_die 232 break ;; 233 french_iso_accent) 234 f_sysrc_set keymap "fr.iso.acc" || f_die 235 break ;; 236 french_iso_macbook) 237 f_sysrc_set keymap "fr.macbook.acc" || f_die 238 break ;; 239 german_cp850) 240 f_sysrc_set keymap "german.cp850" || f_die 241 break ;; 242 german_iso) 243 f_sysrc_set keymap "german.iso" || f_die 244 break ;; 245 greek_101) 246 f_sysrc_set keymap "gr.us101.acc" || f_die 247 break ;; 248 greek_104) 249 f_sysrc_set keymap "el.iso07" || f_die 250 break ;; 251 greek_elot) 252 f_sysrc_set keymap "gr.elot.acc" || f_die 253 break ;; 254 hungarian_101) 255 f_sysrc_set keymap "hu.iso2.101keys" || f_die 256 break ;; 257 hungarian_102) 258 f_sysrc_set keymap "hu.iso2.102keys" || f_die 259 break ;; 260 icelandic) 261 f_sysrc_set keymap "icelandic.iso" || f_die 262 break ;; 263 icelandic_accent) 264 f_sysrc_set keymap "icelandic.iso.acc" || f_die 265 break ;; 266 italian) 267 f_sysrc_set keymap "it.iso" || f_die 268 break ;; 269 japanese_106) 270 f_sysrc_set keymap "jp.106" || f_die 271 break ;; 272 latin_american) 273 f_sysrc_set keymap "latinamerican" || f_die 274 break ;; 275 latin_american_accent) 276 f_sysrc_set keymap "latinamerican.iso.acc" || f_die 277 break ;; 278 norway_iso) 279 f_sysrc_set keymap "norwegian.iso" || f_die 280 break ;; 281 polish_iso) 282 f_sysrc_set keymap "pl_PL.ISO8859-2" || f_die 283 break ;; 284 portuguese) 285 f_sysrc_set keymap "pt.iso" || f_die 286 break ;; 287 portuguese_accent) 288 f_sysrc_set keymap "pt.iso.acc" || f_die 289 break ;; 290 russia_koi8_r) 291 f_sysrc_set keymap "ru.koi8-r" || f_die 292 break ;; 293 slovak) 294 f_sysrc_set keymap "sk.iso2" || f_die 295 break ;; 296 slovenian) 297 f_sysrc_set keymap "si.iso" || f_die 298 break ;; 299 spanish) 300 f_sysrc_set keymap "spanish.iso" || f_die 301 break ;; 302 spanish_accent) 303 f_sysrc_set keymap "spanish.iso.acc" || f_die 304 break ;; 305 swedish_cp850) 306 f_sysrc_set keymap "swedish.cp850" || f_die 307 break ;; 308 swedish_iso) 309 f_sysrc_set keymap "swedish.iso" || f_die 310 break ;; 311 swiss_french_cp850) 312 f_sysrc_set keymap "swissfrench.cp850" || f_die 313 break ;; 314 swiss_french_iso) 315 f_sysrc_set keymap "swissfrench.iso" || f_die 316 break ;; 317 swiss_french_iso_accent) 318 f_sysrc_set keymap "swissfrench.iso.acc" || f_die 319 break ;; 320 swiss_german_cp850) 321 f_sysrc_set keymap "swissgerman.cp850" || f_die 322 break ;; 323 swiss_german_iso) 324 f_sysrc_set keymap "swissgerman.iso" || f_die 325 break ;; 326 swiss_german_iso_accent) 327 f_sysrc_set keymap "swissgerman.iso.acc" || f_die 328 break ;; 329 uk_cp850) 330 f_sysrc_set keymap "uk.cp850" || f_die 331 break ;; 332 uk_iso) 333 f_sysrc_set keymap "uk.iso" || f_die 334 break ;; 335 ukrainian_koi8_u) 336 f_sysrc_set keymap "ua.koi8-u" || f_die 337 break ;; 338 ukrainian_koi8_u_koi8_r) 339 f_sysrc_set keymap "ua.koi8-u.shift.alt" || f_die 340 break ;; 341 usa_capslock_ctrl) 342 f_sysrc_set keymap "us.pc-ctrl" || f_die 343 break ;; 344 usa_dvorak) 345 f_sysrc_set keymap "us.dvorak" || f_die 346 break ;; 347 usa_dvorak_left) 348 f_sysrc_set keymap "us.dvorakl" || f_die 349 break ;; 350 usa_dvorak_right) 351 f_sysrc_set keymap "us.dvorakr" || f_die 352 break ;; 353 usa_emacs) 354 f_sysrc_set keymap "us.emacs" || f_die 355 break ;; 356 usa_iso) 357 f_sysrc_set keymap "us.iso" || f_die 358 break ;; 359 usa_unix) 360 f_sysrc_set keymap "us.unix" || f_die 361 break ;; 362 esac 363done 364 365exit $SUCCESS 366 367################################################################################ 368# END 369################################################################################ 370