keymap revision 238438
1238438Sdteske#!/bin/sh 2238438Sdteske#- 3238438Sdteske# Copyright (c) 2012 Devin Teske 4238438Sdteske# All Rights Reserved. 5238438Sdteske# 6238438Sdteske# Redistribution and use in source and binary forms, with or without 7238438Sdteske# modification, are permitted provided that the following conditions 8238438Sdteske# are met: 9238438Sdteske# 1. Redistributions of source code must retain the above copyright 10238438Sdteske# notice, this list of conditions and the following disclaimer. 11238438Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12238438Sdteske# notice, this list of conditions and the following disclaimer in the 13238438Sdteske# documentation and/or other materials provided with the distribution. 14238438Sdteske# 15238438Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16238438Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 17238438Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18238438Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19238438Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20238438Sdteske# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21238438Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22238438Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23238438Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24238438Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25238438Sdteske# SUCH DAMAGE. 26238438Sdteske# 27238438Sdteske# $FreeBSD: head/usr.sbin/bsdconfig/console/keymap 238438 2012-07-14 03:16:57Z dteske $ 28238438Sdteske# 29238438Sdteske############################################################ INCLUDES 30238438Sdteske 31238438SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" 32238438Sdteske. $BSDCFG_LIBE/include/common.subr || exit 1 33238438Sdteskef_include $BSDCFG_LIBE/include/dialog.subr 34238438Sdteskef_include $BSDCFG_LIBE/include/mustberoot.subr 35238438Sdteskef_include $BSDCFG_LIBE/include/sysrc.subr 36238438Sdteske 37238438SdteskeAPP_DIR="080.console" 38238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 39238438Sdteske 40238438Sdteskeipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 41238438Sdteske[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 42238438Sdteske 43238438Sdteske############################################################ CONFIGURATION 44238438Sdteske 45238438Sdteske# 46238438Sdteske# List of keymap names 47238438Sdteske# 48238438SdteskeKEYMAP_NAMES=" 49238438Sdteske belgian brazil_cp850 brazil_iso 50238438Sdteske brazil_iso_accent bulgarian_bds bulgarian_phonetic 51238438Sdteske central_european_iso croatian_iso czech_iso_accent 52238438Sdteske danish_cp865 danish_iso estonian_cp850 53238438Sdteske estonian_iso estonian_iso_15 finnish_cp850 54238438Sdteske finnish_iso french_iso french_iso_accent 55238438Sdteske french_iso_macbook german_cp850 german_iso 56238438Sdteske greek_101 greek_104 greek_elot 57238438Sdteske hungarian_101 hungarian_102 icelandic 58238438Sdteske icelandic_accent italian japanese_106 59238438Sdteske latin_american latin_american_accent norway_iso 60238438Sdteske polish_iso portuguese portuguese_accent 61238438Sdteske russia_koi8_r slovak slovenian 62238438Sdteske spanish spanish_accent swedish_cp850 63238438Sdteske swedish_iso swiss_french_cp850 swiss_french_iso 64238438Sdteske swiss_french_iso_accent swiss_german_cp850 swiss_german_iso 65238438Sdteske swiss_german_iso_accent uk_cp850 uk_iso 66238438Sdteske ukrainian_koi8_u ukrainian_koi8_u_koi8_r usa_capslock_ctrl 67238438Sdteske usa_dvorak usa_dvorak_left usa_dvorak_right 68238438Sdteske usa_emacs usa_iso usa_unix 69238438Sdteske" # END-QUOTE 70238438Sdteske 71238438Sdteske############################################################ FUNCTIONS 72238438Sdteske 73238438Sdteske# dialog_menu_main 74238438Sdteske# 75238438Sdteske# Display the dialog(1)-based application main menu. 76238438Sdteske# 77238438Sdteskedialog_menu_main() 78238438Sdteske{ 79238438Sdteske local menu_list size 80238438Sdteske local hline="$hline_choose_a_keyboard_map" 81238438Sdteske local prompt="$msg_keymap_menu_text" 82238438Sdteske 83238438Sdteske # 84238438Sdteske # Export variables for awk(1) ENVIRON visibility 85238438Sdteske # 86238438Sdteske local name 87238438Sdteske for name in $KEYMAP_NAMES; do 88238438Sdteske export msg_$name msg_${name}_desc 89238438Sdteske done 90238438Sdteske 91238438Sdteske # 92238438Sdteske # Generate a sorted list of keymaps. If the first letter of the keymap 93238438Sdteske # name is unique (case-insensitive) then it is used as the tag to allow 94238438Sdteske # the user to jump to that entry. 95238438Sdteske # 96238438Sdteske menu_list=$( 97238438Sdteske for name in $KEYMAP_NAMES; do 98238438Sdteske eval echo \"\$msg_$name\" msg_$name 99238438Sdteske done | sort | awk 'BEGIN { prefix = "" } 100238438Sdteske { 101238438Sdteske cur_prefix = tolower(substr(ENVIRON[$NF], 1, 1)) 102238438Sdteske printf "'\''" 103238438Sdteske if ( prefix != cur_prefix ) 104238438Sdteske prefix = cur_prefix 105238438Sdteske else 106238438Sdteske printf " " 107238438Sdteske printf "%s'\'' '\''%s'\''\n", 108238438Sdteske ENVIRON[$NF], ENVIRON[$NF"_desc"] 109238438Sdteske }' 110238438Sdteske ) 111238438Sdteske 112238438Sdteske size=$( eval f_dialog_menu_size \ 113238438Sdteske \"\$DIALOG_TITLE\" \ 114238438Sdteske \"\$DIALOG_BACKTITLE\" \ 115238438Sdteske \"\$prompt\" \ 116238438Sdteske \"\$hline\" \ 117238438Sdteske $menu_list ) 118238438Sdteske 119238438Sdteske eval $DIALOG \ 120238438Sdteske --clear --title \"\$DIALOG_TITLE\" \ 121238438Sdteske --backtitle \"\$DIALOG_BACKTITLE\" \ 122238438Sdteske --hline \"\$hline\" \ 123238438Sdteske --ok-label \"\$msg_ok\" \ 124238438Sdteske --cancel-label \"\$msg_cancel\" \ 125238438Sdteske --menu \"\$prompt\" $size \ 126238438Sdteske $menu_list \ 127238438Sdteske 2> "$DIALOG_TMPDIR/dialog.menu.$$" 128238438Sdteske} 129238438Sdteske 130238438Sdteske############################################################ MAIN 131238438Sdteske 132238438Sdteske# Incorporate rc-file if it exists 133238438Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 134238438Sdteske 135238438Sdteske# 136238438Sdteske# Process command-line arguments 137238438Sdteske# 138238438Sdteskewhile getopts hSX flag; do 139238438Sdteske case "$flag" in 140238438Sdteske h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 141238438Sdteske esac 142238438Sdteskedone 143238438Sdteskeshift $(( $OPTIND - 1 )) 144238438Sdteske 145238438Sdteske# 146238438Sdteske# Initialize 147238438Sdteske# 148238438Sdteskef_dialog_init 149238438Sdteskef_dialog_title "$msg_system_console_keymap" 150238438Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 151238438Sdteskef_mustberoot_init 152238438Sdteske 153238438Sdteske# 154238438Sdteske# Launch application main menu 155238438Sdteske# 156238438Sdteskewhile :; do 157238438Sdteske dialog_menu_main 158238438Sdteske retval=$? 159238438Sdteske mtag=$( f_dialog_menutag ) 160238438Sdteske 161238438Sdteske [ $retval -eq 0 ] || f_die 162238438Sdteske 163238438Sdteske # 164238438Sdteske # Reverse the users choice into the variable name 165238438Sdteske # 166238438Sdteske keymap_name= 167238438Sdteske mtag="${mtag# }" # remove single leading-space if-present 168238438Sdteske for name in $KEYMAP_NAMES; do 169238438Sdteske if [ "$( eval echo \"\$msg_$name\" )" = "$mtag" ]; then 170238438Sdteske keymap_name="$name" 171238438Sdteske break 172238438Sdteske fi 173238438Sdteske done 174238438Sdteske 175238438Sdteske [ "$keymap_name" ] || continue 176238438Sdteske 177238438Sdteske case "$keymap_name" in 178238438Sdteske belgian) 179238438Sdteske f_sysrc_set keymap "be.iso" || f_die 180238438Sdteske break ;; 181238438Sdteske brazil_cp850) 182238438Sdteske f_sysrc_set keymap "br275.cp850" || f_die 183238438Sdteske break ;; 184238438Sdteske brazil_iso) 185238438Sdteske f_sysrc_set keymap "br275.iso" || f_die 186238438Sdteske break ;; 187238438Sdteske brazil_iso_accent) 188238438Sdteske f_sysrc_set keymap "br275.iso.acc" || f_die 189238438Sdteske break ;; 190238438Sdteske bulgarian_bds) 191238438Sdteske f_sysrc_set keymap "bg.bds.ctrlcaps" || f_die 192238438Sdteske break ;; 193238438Sdteske bulgarian_phonetic) 194238438Sdteske f_sysrc_set keymap "bg.phonetic.ctrlcaps" || f_die 195238438Sdteske break ;; 196238438Sdteske central_european_iso) 197238438Sdteske f_sysrc_set keymap "ce.iso2" || f_die 198238438Sdteske break ;; 199238438Sdteske croatian_iso) 200238438Sdteske f_sysrc_set keymap "hr.iso" || f_die 201238438Sdteske break ;; 202238438Sdteske czech_iso_accent) 203238438Sdteske f_sysrc_set keymap "cs.latin2.qwertz" || f_die 204238438Sdteske break ;; 205238438Sdteske danish_cp865) 206238438Sdteske f_sysrc_set keymap "danish.cp865" || f_die 207238438Sdteske break ;; 208238438Sdteske danish_iso) 209238438Sdteske f_sysrc_set keymap "danish.iso" || f_die 210238438Sdteske break ;; 211238438Sdteske estonian_cp850) 212238438Sdteske f_sysrc_set keymap "estonian.cp850" || f_die 213238438Sdteske break ;; 214238438Sdteske estonian_iso) 215238438Sdteske f_sysrc_set keymap "estonian.iso" || f_die 216238438Sdteske break ;; 217238438Sdteske estonian_iso_15) 218238438Sdteske f_sysrc_set keymap "estonian.iso15" || f_die 219238438Sdteske break ;; 220238438Sdteske finnish_cp850) 221238438Sdteske f_sysrc_set keymap "finnish.cp850" || f_die 222238438Sdteske break ;; 223238438Sdteske finnish_iso) 224238438Sdteske f_sysrc_set keymap "finnish.iso" || f_die 225238438Sdteske break ;; 226238438Sdteske french_iso) 227238438Sdteske f_sysrc_set keymap "fr.iso" || f_die 228238438Sdteske break ;; 229238438Sdteske french_iso_accent) 230238438Sdteske f_sysrc_set keymap "fr.iso.acc" || f_die 231238438Sdteske break ;; 232238438Sdteske french_iso_macbook) 233238438Sdteske f_sysrc_set keymap "fr.macbook.acc" || f_die 234238438Sdteske break ;; 235238438Sdteske german_cp850) 236238438Sdteske f_sysrc_set keymap "german.cp850" || f_die 237238438Sdteske break ;; 238238438Sdteske german_iso) 239238438Sdteske f_sysrc_set keymap "german.iso" || f_die 240238438Sdteske break ;; 241238438Sdteske greek_101) 242238438Sdteske f_sysrc_set keymap "gr.us101.acc" || f_die 243238438Sdteske break ;; 244238438Sdteske greek_104) 245238438Sdteske f_sysrc_set keymap "el.iso07" || f_die 246238438Sdteske break ;; 247238438Sdteske greek_elot) 248238438Sdteske f_sysrc_set keymap "gr.elot.acc" || f_die 249238438Sdteske break ;; 250238438Sdteske hungarian_101) 251238438Sdteske f_sysrc_set keymap "hu.iso2.101keys" || f_die 252238438Sdteske break ;; 253238438Sdteske hungarian_102) 254238438Sdteske f_sysrc_set keymap "hu.iso2.102keys" || f_die 255238438Sdteske break ;; 256238438Sdteske icelandic) 257238438Sdteske f_sysrc_set keymap "icelandic.iso" || f_die 258238438Sdteske break ;; 259238438Sdteske icelandic_accent) 260238438Sdteske f_sysrc_set keymap "icelandic.iso.acc" || f_die 261238438Sdteske break ;; 262238438Sdteske italian) 263238438Sdteske f_sysrc_set keymap "it.iso" || f_die 264238438Sdteske break ;; 265238438Sdteske japanese_106) 266238438Sdteske f_sysrc_set keymap "jp.106" || f_die 267238438Sdteske break ;; 268238438Sdteske latin_american) 269238438Sdteske f_sysrc_set keymap "latinamerican" || f_die 270238438Sdteske break ;; 271238438Sdteske latin_american_accent) 272238438Sdteske f_sysrc_set keymap "latinamerican.iso.acc" || f_die 273238438Sdteske break ;; 274238438Sdteske norway_iso) 275238438Sdteske f_sysrc_set keymap "norwegian.iso" || f_die 276238438Sdteske break ;; 277238438Sdteske polish_iso) 278238438Sdteske f_sysrc_set keymap "pl_PL.ISO8859-2" || f_die 279238438Sdteske break ;; 280238438Sdteske portuguese) 281238438Sdteske f_sysrc_set keymap "pt.iso" || f_die 282238438Sdteske break ;; 283238438Sdteske portuguese_accent) 284238438Sdteske f_sysrc_set keymap "pt.iso.acc" || f_die 285238438Sdteske break ;; 286238438Sdteske russia_koi8_r) 287238438Sdteske f_sysrc_set keymap "ru.koi8-r" || f_die 288238438Sdteske break ;; 289238438Sdteske slovak) 290238438Sdteske f_sysrc_set keymap "sk.iso2" || f_die 291238438Sdteske break ;; 292238438Sdteske slovenian) 293238438Sdteske f_sysrc_set keymap "si.iso" || f_die 294238438Sdteske break ;; 295238438Sdteske spanish) 296238438Sdteske f_sysrc_set keymap "spanish.iso" || f_die 297238438Sdteske break ;; 298238438Sdteske spanish_accent) 299238438Sdteske f_sysrc_set keymap "spanish.iso.acc" || f_die 300238438Sdteske break ;; 301238438Sdteske swedish_cp850) 302238438Sdteske f_sysrc_set keymap "swedish.cp850" || f_die 303238438Sdteske break ;; 304238438Sdteske swedish_iso) 305238438Sdteske f_sysrc_set keymap "swedish.iso" || f_die 306238438Sdteske break ;; 307238438Sdteske swiss_french_cp850) 308238438Sdteske f_sysrc_set keymap "swissfrench.cp850" || f_die 309238438Sdteske break ;; 310238438Sdteske swiss_french_iso) 311238438Sdteske f_sysrc_set keymap "swissfrench.iso" || f_die 312238438Sdteske break ;; 313238438Sdteske swiss_french_iso_accent) 314238438Sdteske f_sysrc_set keymap "swissfrench.iso.acc" || f_die 315238438Sdteske break ;; 316238438Sdteske swiss_german_cp850) 317238438Sdteske f_sysrc_set keymap "swissgerman.cp850" || f_die 318238438Sdteske break ;; 319238438Sdteske swiss_german_iso) 320238438Sdteske f_sysrc_set keymap "swissgerman.iso" || f_die 321238438Sdteske break ;; 322238438Sdteske swiss_german_iso_accent) 323238438Sdteske f_sysrc_set keymap "swissgerman.iso.acc" || f_die 324238438Sdteske break ;; 325238438Sdteske uk_cp850) 326238438Sdteske f_sysrc_set keymap "uk.cp850" || f_die 327238438Sdteske break ;; 328238438Sdteske uk_iso) 329238438Sdteske f_sysrc_set keymap "uk.iso" || f_die 330238438Sdteske break ;; 331238438Sdteske ukrainian_koi8_u) 332238438Sdteske f_sysrc_set keymap "ua.koi8-u" || f_die 333238438Sdteske break ;; 334238438Sdteske ukrainian_koi8_u_koi8_r) 335238438Sdteske f_sysrc_set keymap "ua.koi8-u.shift.alt" || f_die 336238438Sdteske break ;; 337238438Sdteske usa_capslock_ctrl) 338238438Sdteske f_sysrc_set keymap "us.pc-ctrl" || f_die 339238438Sdteske break ;; 340238438Sdteske usa_dvorak) 341238438Sdteske f_sysrc_set keymap "us.dvorak" || f_die 342238438Sdteske break ;; 343238438Sdteske usa_dvorak_left) 344238438Sdteske f_sysrc_set keymap "us.dvorakl" || f_die 345238438Sdteske break ;; 346238438Sdteske usa_dvorak_right) 347238438Sdteske f_sysrc_set keymap "us.dvorakr" || f_die 348238438Sdteske break ;; 349238438Sdteske usa_emacs) 350238438Sdteske f_sysrc_set keymap "us.emacs" || f_die 351238438Sdteske break ;; 352238438Sdteske usa_iso) 353238438Sdteske f_sysrc_set keymap "us.iso" || f_die 354238438Sdteske break ;; 355238438Sdteske usa_unix) 356238438Sdteske f_sysrc_set keymap "us.unix" || f_die 357238438Sdteske break ;; 358238438Sdteske esac 359238438Sdteskedone 360238438Sdteske 361238438Sdteskeexit $SUCCESS 362238438Sdteske 363238438Sdteske################################################################################ 364238438Sdteske# END 365238438Sdteske################################################################################ 366