keymap revision 249746
1#!/bin/sh 2#- 3# Copyright (c) 2012-2013 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 249746 2013-04-22 05:02:34Z dteske $ 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." "$0" 34f_include $BSDCFG_SHARE/dialog.subr 35f_include $BSDCFG_SHARE/mustberoot.subr 36f_include $BSDCFG_SHARE/sysrc.subr 37 38BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console" 39f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 40 41ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 42[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 43 44############################################################ CONFIGURATION 45 46# 47# List of keymap names 48# 49KEYMAP_NAMES=" 50 belgian brazil_cp850 brazil_iso 51 brazil_iso_accent bulgarian_bds bulgarian_phonetic 52 central_european_iso croatian_iso czech_iso_accent 53 danish_cp865 danish_iso estonian_cp850 54 estonian_iso estonian_iso_15 finnish_cp850 55 finnish_iso french_iso french_iso_accent 56 french_iso_macbook german_cp850 german_iso 57 greek_101 greek_104 greek_elot 58 hungarian_101 hungarian_102 icelandic 59 icelandic_accent italian japanese_106 60 latin_american latin_american_accent norway_iso 61 polish_iso portuguese portuguese_accent 62 russia_koi8_r slovak slovenian 63 spanish spanish_accent swedish_cp850 64 swedish_iso swiss_french_cp850 swiss_french_iso 65 swiss_french_iso_accent swiss_german_cp850 swiss_german_iso 66 swiss_german_iso_accent uk_cp850 uk_iso 67 ukrainian_koi8_u ukrainian_koi8_u_koi8_r usa_capslock_ctrl 68 usa_dvorak usa_dvorak_left usa_dvorak_right 69 usa_emacs usa_iso usa_unix 70" # END-QUOTE 71 72############################################################ FUNCTIONS 73 74# dialog_menu_main 75# 76# Display the dialog(1)-based application main menu. 77# 78dialog_menu_main() 79{ 80 local menu_list size 81 local hline="$hline_choose_a_keyboard_map" 82 local prompt="$msg_keymap_menu_text" 83 84 # 85 # Export variables for awk(1) ENVIRON visibility 86 # 87 local name 88 for name in $KEYMAP_NAMES; do 89 export msg_$name msg_${name}_desc 90 done 91 92 # 93 # Generate a sorted list of keymaps. If the first letter of the keymap 94 # name is unique (case-insensitive) then it is used as the tag to allow 95 # the user to jump to that entry. 96 # 97 menu_list=$( 98 for name in $KEYMAP_NAMES; do 99 eval echo \"\$msg_$name\" msg_$name 100 done | sort | awk 'BEGIN { prefix = "" } 101 { 102 cur_prefix = tolower(substr(ENVIRON[$NF], 1, 1)) 103 printf "'\''" 104 if ( prefix != cur_prefix ) 105 prefix = cur_prefix 106 else 107 printf " " 108 printf "%s'\'' '\''%s'\''\n", 109 ENVIRON[$NF], ENVIRON[$NF"_desc"] 110 }' 111 ) 112 113 size=$( eval f_dialog_menu_size \ 114 \"\$DIALOG_TITLE\" \ 115 \"\$DIALOG_BACKTITLE\" \ 116 \"\$prompt\" \ 117 \"\$hline\" \ 118 $menu_list ) 119 120 local dialog_menu 121 dialog_menu=$( eval $DIALOG \ 122 --clear --title \"\$DIALOG_TITLE\" \ 123 --backtitle \"\$DIALOG_BACKTITLE\" \ 124 --hline \"\$hline\" \ 125 --ok-label \"\$msg_ok\" \ 126 --cancel-label \"\$msg_cancel\" \ 127 --menu \"\$prompt\" $size \ 128 $menu_list \ 129 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 130 ) 131 local retval=$? 132 setvar DIALOG_MENU_$$ "$dialog_menu" 133 return $retval 134} 135 136############################################################ MAIN 137 138# Incorporate rc-file if it exists 139[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 140 141# 142# Process command-line arguments 143# 144while getopts dD:hSX flag; do 145 case "$flag" in 146 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 147 esac 148done 149shift $(( $OPTIND - 1 )) 150 151# 152# Initialize 153# 154f_dialog_title "$msg_system_console_keymap" 155f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 156f_mustberoot_init 157 158# 159# Launch application main menu 160# 161while :; do 162 dialog_menu_main 163 retval=$? 164 mtag=$( f_dialog_menutag ) 165 166 [ $retval -eq 0 ] || f_die 167 168 # 169 # Reverse the users choice into the variable name 170 # 171 keymap_name= 172 mtag="${mtag# }" # remove single leading-space if-present 173 for name in $KEYMAP_NAMES; do 174 if [ "$( eval echo \"\$msg_$name\" )" = "$mtag" ]; then 175 keymap_name="$name" 176 break 177 fi 178 done 179 180 [ "$keymap_name" ] || continue 181 182 case "$keymap_name" in 183 belgian) 184 f_sysrc_set keymap "be.iso" || f_die 185 break ;; 186 brazil_cp850) 187 f_sysrc_set keymap "br275.cp850" || f_die 188 break ;; 189 brazil_iso) 190 f_sysrc_set keymap "br275.iso" || f_die 191 break ;; 192 brazil_iso_accent) 193 f_sysrc_set keymap "br275.iso.acc" || f_die 194 break ;; 195 bulgarian_bds) 196 f_sysrc_set keymap "bg.bds.ctrlcaps" || f_die 197 break ;; 198 bulgarian_phonetic) 199 f_sysrc_set keymap "bg.phonetic.ctrlcaps" || f_die 200 break ;; 201 central_european_iso) 202 f_sysrc_set keymap "ce.iso2" || f_die 203 break ;; 204 croatian_iso) 205 f_sysrc_set keymap "hr.iso" || f_die 206 break ;; 207 czech_iso_accent) 208 f_sysrc_set keymap "cs.latin2.qwertz" || f_die 209 break ;; 210 danish_cp865) 211 f_sysrc_set keymap "danish.cp865" || f_die 212 break ;; 213 danish_iso) 214 f_sysrc_set keymap "danish.iso" || f_die 215 break ;; 216 estonian_cp850) 217 f_sysrc_set keymap "estonian.cp850" || f_die 218 break ;; 219 estonian_iso) 220 f_sysrc_set keymap "estonian.iso" || f_die 221 break ;; 222 estonian_iso_15) 223 f_sysrc_set keymap "estonian.iso15" || f_die 224 break ;; 225 finnish_cp850) 226 f_sysrc_set keymap "finnish.cp850" || f_die 227 break ;; 228 finnish_iso) 229 f_sysrc_set keymap "finnish.iso" || f_die 230 break ;; 231 french_iso) 232 f_sysrc_set keymap "fr.iso" || f_die 233 break ;; 234 french_iso_accent) 235 f_sysrc_set keymap "fr.iso.acc" || f_die 236 break ;; 237 french_iso_macbook) 238 f_sysrc_set keymap "fr.macbook.acc" || f_die 239 break ;; 240 german_cp850) 241 f_sysrc_set keymap "german.cp850" || f_die 242 break ;; 243 german_iso) 244 f_sysrc_set keymap "german.iso" || f_die 245 break ;; 246 greek_101) 247 f_sysrc_set keymap "gr.us101.acc" || f_die 248 break ;; 249 greek_104) 250 f_sysrc_set keymap "el.iso07" || f_die 251 break ;; 252 greek_elot) 253 f_sysrc_set keymap "gr.elot.acc" || f_die 254 break ;; 255 hungarian_101) 256 f_sysrc_set keymap "hu.iso2.101keys" || f_die 257 break ;; 258 hungarian_102) 259 f_sysrc_set keymap "hu.iso2.102keys" || f_die 260 break ;; 261 icelandic) 262 f_sysrc_set keymap "icelandic.iso" || f_die 263 break ;; 264 icelandic_accent) 265 f_sysrc_set keymap "icelandic.iso.acc" || f_die 266 break ;; 267 italian) 268 f_sysrc_set keymap "it.iso" || f_die 269 break ;; 270 japanese_106) 271 f_sysrc_set keymap "jp.106" || f_die 272 break ;; 273 latin_american) 274 f_sysrc_set keymap "latinamerican" || f_die 275 break ;; 276 latin_american_accent) 277 f_sysrc_set keymap "latinamerican.iso.acc" || f_die 278 break ;; 279 norway_iso) 280 f_sysrc_set keymap "norwegian.iso" || f_die 281 break ;; 282 polish_iso) 283 f_sysrc_set keymap "pl_PL.ISO8859-2" || f_die 284 break ;; 285 portuguese) 286 f_sysrc_set keymap "pt.iso" || f_die 287 break ;; 288 portuguese_accent) 289 f_sysrc_set keymap "pt.iso.acc" || f_die 290 break ;; 291 russia_koi8_r) 292 f_sysrc_set keymap "ru.koi8-r" || f_die 293 break ;; 294 slovak) 295 f_sysrc_set keymap "sk.iso2" || f_die 296 break ;; 297 slovenian) 298 f_sysrc_set keymap "si.iso" || f_die 299 break ;; 300 spanish) 301 f_sysrc_set keymap "spanish.iso" || f_die 302 break ;; 303 spanish_accent) 304 f_sysrc_set keymap "spanish.iso.acc" || f_die 305 break ;; 306 swedish_cp850) 307 f_sysrc_set keymap "swedish.cp850" || f_die 308 break ;; 309 swedish_iso) 310 f_sysrc_set keymap "swedish.iso" || f_die 311 break ;; 312 swiss_french_cp850) 313 f_sysrc_set keymap "swissfrench.cp850" || f_die 314 break ;; 315 swiss_french_iso) 316 f_sysrc_set keymap "swissfrench.iso" || f_die 317 break ;; 318 swiss_french_iso_accent) 319 f_sysrc_set keymap "swissfrench.iso.acc" || f_die 320 break ;; 321 swiss_german_cp850) 322 f_sysrc_set keymap "swissgerman.cp850" || f_die 323 break ;; 324 swiss_german_iso) 325 f_sysrc_set keymap "swissgerman.iso" || f_die 326 break ;; 327 swiss_german_iso_accent) 328 f_sysrc_set keymap "swissgerman.iso.acc" || f_die 329 break ;; 330 uk_cp850) 331 f_sysrc_set keymap "uk.cp850" || f_die 332 break ;; 333 uk_iso) 334 f_sysrc_set keymap "uk.iso" || f_die 335 break ;; 336 ukrainian_koi8_u) 337 f_sysrc_set keymap "ua.koi8-u" || f_die 338 break ;; 339 ukrainian_koi8_u_koi8_r) 340 f_sysrc_set keymap "ua.koi8-u.shift.alt" || f_die 341 break ;; 342 usa_capslock_ctrl) 343 f_sysrc_set keymap "us.pc-ctrl" || f_die 344 break ;; 345 usa_dvorak) 346 f_sysrc_set keymap "us.dvorak" || f_die 347 break ;; 348 usa_dvorak_left) 349 f_sysrc_set keymap "us.dvorakl" || f_die 350 break ;; 351 usa_dvorak_right) 352 f_sysrc_set keymap "us.dvorakr" || f_die 353 break ;; 354 usa_emacs) 355 f_sysrc_set keymap "us.emacs" || f_die 356 break ;; 357 usa_iso) 358 f_sysrc_set keymap "us.iso" || f_die 359 break ;; 360 usa_unix) 361 f_sysrc_set keymap "us.unix" || f_die 362 break ;; 363 esac 364done 365 366exit $SUCCESS 367 368################################################################################ 369# END 370################################################################################ 371