keymap revision 249746
1238438Sdteske#!/bin/sh 2238438Sdteske#- 3249746Sdteske# Copyright (c) 2012-2013 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 249746 2013-04-22 05:02:34Z dteske $ 28238438Sdteske# 29238438Sdteske############################################################ INCLUDES 30238438Sdteske 31240684SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 32240684Sdteske. $BSDCFG_SHARE/common.subr || exit 1 33244675Sdteskef_dprintf "%s: loading includes..." "$0" 34240684Sdteskef_include $BSDCFG_SHARE/dialog.subr 35240684Sdteskef_include $BSDCFG_SHARE/mustberoot.subr 36240684Sdteskef_include $BSDCFG_SHARE/sysrc.subr 37238438Sdteske 38240684SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console" 39238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 40238438Sdteske 41243112Sdteskeipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 42238438Sdteske[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 43238438Sdteske 44238438Sdteske############################################################ CONFIGURATION 45238438Sdteske 46238438Sdteske# 47238438Sdteske# List of keymap names 48238438Sdteske# 49238438SdteskeKEYMAP_NAMES=" 50238438Sdteske belgian brazil_cp850 brazil_iso 51238438Sdteske brazil_iso_accent bulgarian_bds bulgarian_phonetic 52238438Sdteske central_european_iso croatian_iso czech_iso_accent 53238438Sdteske danish_cp865 danish_iso estonian_cp850 54238438Sdteske estonian_iso estonian_iso_15 finnish_cp850 55238438Sdteske finnish_iso french_iso french_iso_accent 56238438Sdteske french_iso_macbook german_cp850 german_iso 57238438Sdteske greek_101 greek_104 greek_elot 58238438Sdteske hungarian_101 hungarian_102 icelandic 59238438Sdteske icelandic_accent italian japanese_106 60238438Sdteske latin_american latin_american_accent norway_iso 61238438Sdteske polish_iso portuguese portuguese_accent 62238438Sdteske russia_koi8_r slovak slovenian 63238438Sdteske spanish spanish_accent swedish_cp850 64238438Sdteske swedish_iso swiss_french_cp850 swiss_french_iso 65238438Sdteske swiss_french_iso_accent swiss_german_cp850 swiss_german_iso 66238438Sdteske swiss_german_iso_accent uk_cp850 uk_iso 67238438Sdteske ukrainian_koi8_u ukrainian_koi8_u_koi8_r usa_capslock_ctrl 68238438Sdteske usa_dvorak usa_dvorak_left usa_dvorak_right 69238438Sdteske usa_emacs usa_iso usa_unix 70238438Sdteske" # END-QUOTE 71238438Sdteske 72238438Sdteske############################################################ FUNCTIONS 73238438Sdteske 74238438Sdteske# dialog_menu_main 75238438Sdteske# 76238438Sdteske# Display the dialog(1)-based application main menu. 77238438Sdteske# 78238438Sdteskedialog_menu_main() 79238438Sdteske{ 80238438Sdteske local menu_list size 81238438Sdteske local hline="$hline_choose_a_keyboard_map" 82238438Sdteske local prompt="$msg_keymap_menu_text" 83238438Sdteske 84238438Sdteske # 85238438Sdteske # Export variables for awk(1) ENVIRON visibility 86238438Sdteske # 87238438Sdteske local name 88238438Sdteske for name in $KEYMAP_NAMES; do 89238438Sdteske export msg_$name msg_${name}_desc 90238438Sdteske done 91238438Sdteske 92238438Sdteske # 93238438Sdteske # Generate a sorted list of keymaps. If the first letter of the keymap 94238438Sdteske # name is unique (case-insensitive) then it is used as the tag to allow 95238438Sdteske # the user to jump to that entry. 96238438Sdteske # 97238438Sdteske menu_list=$( 98238438Sdteske for name in $KEYMAP_NAMES; do 99238438Sdteske eval echo \"\$msg_$name\" msg_$name 100238438Sdteske done | sort | awk 'BEGIN { prefix = "" } 101238438Sdteske { 102238438Sdteske cur_prefix = tolower(substr(ENVIRON[$NF], 1, 1)) 103238438Sdteske printf "'\''" 104238438Sdteske if ( prefix != cur_prefix ) 105238438Sdteske prefix = cur_prefix 106238438Sdteske else 107238438Sdteske printf " " 108238438Sdteske printf "%s'\'' '\''%s'\''\n", 109238438Sdteske ENVIRON[$NF], ENVIRON[$NF"_desc"] 110238438Sdteske }' 111238438Sdteske ) 112238438Sdteske 113238438Sdteske size=$( eval f_dialog_menu_size \ 114238438Sdteske \"\$DIALOG_TITLE\" \ 115238438Sdteske \"\$DIALOG_BACKTITLE\" \ 116238438Sdteske \"\$prompt\" \ 117238438Sdteske \"\$hline\" \ 118238438Sdteske $menu_list ) 119238438Sdteske 120240768Sdteske local dialog_menu 121240768Sdteske dialog_menu=$( eval $DIALOG \ 122238438Sdteske --clear --title \"\$DIALOG_TITLE\" \ 123238438Sdteske --backtitle \"\$DIALOG_BACKTITLE\" \ 124238438Sdteske --hline \"\$hline\" \ 125238438Sdteske --ok-label \"\$msg_ok\" \ 126238438Sdteske --cancel-label \"\$msg_cancel\" \ 127238438Sdteske --menu \"\$prompt\" $size \ 128238438Sdteske $menu_list \ 129240768Sdteske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 130240768Sdteske ) 131240768Sdteske local retval=$? 132240768Sdteske setvar DIALOG_MENU_$$ "$dialog_menu" 133240768Sdteske return $retval 134238438Sdteske} 135238438Sdteske 136238438Sdteske############################################################ MAIN 137238438Sdteske 138238438Sdteske# Incorporate rc-file if it exists 139238438Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 140238438Sdteske 141238438Sdteske# 142238438Sdteske# Process command-line arguments 143238438Sdteske# 144249746Sdteskewhile getopts dD:hSX flag; do 145238438Sdteske case "$flag" in 146238438Sdteske h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 147238438Sdteske esac 148238438Sdteskedone 149238438Sdteskeshift $(( $OPTIND - 1 )) 150238438Sdteske 151238438Sdteske# 152238438Sdteske# Initialize 153238438Sdteske# 154238438Sdteskef_dialog_title "$msg_system_console_keymap" 155238438Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 156238438Sdteskef_mustberoot_init 157238438Sdteske 158238438Sdteske# 159238438Sdteske# Launch application main menu 160238438Sdteske# 161238438Sdteskewhile :; do 162238438Sdteske dialog_menu_main 163238438Sdteske retval=$? 164238438Sdteske mtag=$( f_dialog_menutag ) 165238438Sdteske 166238438Sdteske [ $retval -eq 0 ] || f_die 167238438Sdteske 168238438Sdteske # 169238438Sdteske # Reverse the users choice into the variable name 170238438Sdteske # 171238438Sdteske keymap_name= 172238438Sdteske mtag="${mtag# }" # remove single leading-space if-present 173238438Sdteske for name in $KEYMAP_NAMES; do 174238438Sdteske if [ "$( eval echo \"\$msg_$name\" )" = "$mtag" ]; then 175238438Sdteske keymap_name="$name" 176238438Sdteske break 177238438Sdteske fi 178238438Sdteske done 179238438Sdteske 180238438Sdteske [ "$keymap_name" ] || continue 181238438Sdteske 182238438Sdteske case "$keymap_name" in 183238438Sdteske belgian) 184238438Sdteske f_sysrc_set keymap "be.iso" || f_die 185238438Sdteske break ;; 186238438Sdteske brazil_cp850) 187238438Sdteske f_sysrc_set keymap "br275.cp850" || f_die 188238438Sdteske break ;; 189238438Sdteske brazil_iso) 190238438Sdteske f_sysrc_set keymap "br275.iso" || f_die 191238438Sdteske break ;; 192238438Sdteske brazil_iso_accent) 193238438Sdteske f_sysrc_set keymap "br275.iso.acc" || f_die 194238438Sdteske break ;; 195238438Sdteske bulgarian_bds) 196238438Sdteske f_sysrc_set keymap "bg.bds.ctrlcaps" || f_die 197238438Sdteske break ;; 198238438Sdteske bulgarian_phonetic) 199238438Sdteske f_sysrc_set keymap "bg.phonetic.ctrlcaps" || f_die 200238438Sdteske break ;; 201238438Sdteske central_european_iso) 202238438Sdteske f_sysrc_set keymap "ce.iso2" || f_die 203238438Sdteske break ;; 204238438Sdteske croatian_iso) 205238438Sdteske f_sysrc_set keymap "hr.iso" || f_die 206238438Sdteske break ;; 207238438Sdteske czech_iso_accent) 208238438Sdteske f_sysrc_set keymap "cs.latin2.qwertz" || f_die 209238438Sdteske break ;; 210238438Sdteske danish_cp865) 211238438Sdteske f_sysrc_set keymap "danish.cp865" || f_die 212238438Sdteske break ;; 213238438Sdteske danish_iso) 214238438Sdteske f_sysrc_set keymap "danish.iso" || f_die 215238438Sdteske break ;; 216238438Sdteske estonian_cp850) 217238438Sdteske f_sysrc_set keymap "estonian.cp850" || f_die 218238438Sdteske break ;; 219238438Sdteske estonian_iso) 220238438Sdteske f_sysrc_set keymap "estonian.iso" || f_die 221238438Sdteske break ;; 222238438Sdteske estonian_iso_15) 223238438Sdteske f_sysrc_set keymap "estonian.iso15" || f_die 224238438Sdteske break ;; 225238438Sdteske finnish_cp850) 226238438Sdteske f_sysrc_set keymap "finnish.cp850" || f_die 227238438Sdteske break ;; 228238438Sdteske finnish_iso) 229238438Sdteske f_sysrc_set keymap "finnish.iso" || f_die 230238438Sdteske break ;; 231238438Sdteske french_iso) 232238438Sdteske f_sysrc_set keymap "fr.iso" || f_die 233238438Sdteske break ;; 234238438Sdteske french_iso_accent) 235238438Sdteske f_sysrc_set keymap "fr.iso.acc" || f_die 236238438Sdteske break ;; 237238438Sdteske french_iso_macbook) 238238438Sdteske f_sysrc_set keymap "fr.macbook.acc" || f_die 239238438Sdteske break ;; 240238438Sdteske german_cp850) 241238438Sdteske f_sysrc_set keymap "german.cp850" || f_die 242238438Sdteske break ;; 243238438Sdteske german_iso) 244238438Sdteske f_sysrc_set keymap "german.iso" || f_die 245238438Sdteske break ;; 246238438Sdteske greek_101) 247238438Sdteske f_sysrc_set keymap "gr.us101.acc" || f_die 248238438Sdteske break ;; 249238438Sdteske greek_104) 250238438Sdteske f_sysrc_set keymap "el.iso07" || f_die 251238438Sdteske break ;; 252238438Sdteske greek_elot) 253238438Sdteske f_sysrc_set keymap "gr.elot.acc" || f_die 254238438Sdteske break ;; 255238438Sdteske hungarian_101) 256238438Sdteske f_sysrc_set keymap "hu.iso2.101keys" || f_die 257238438Sdteske break ;; 258238438Sdteske hungarian_102) 259238438Sdteske f_sysrc_set keymap "hu.iso2.102keys" || f_die 260238438Sdteske break ;; 261238438Sdteske icelandic) 262238438Sdteske f_sysrc_set keymap "icelandic.iso" || f_die 263238438Sdteske break ;; 264238438Sdteske icelandic_accent) 265238438Sdteske f_sysrc_set keymap "icelandic.iso.acc" || f_die 266238438Sdteske break ;; 267238438Sdteske italian) 268238438Sdteske f_sysrc_set keymap "it.iso" || f_die 269238438Sdteske break ;; 270238438Sdteske japanese_106) 271238438Sdteske f_sysrc_set keymap "jp.106" || f_die 272238438Sdteske break ;; 273238438Sdteske latin_american) 274238438Sdteske f_sysrc_set keymap "latinamerican" || f_die 275238438Sdteske break ;; 276238438Sdteske latin_american_accent) 277238438Sdteske f_sysrc_set keymap "latinamerican.iso.acc" || f_die 278238438Sdteske break ;; 279238438Sdteske norway_iso) 280238438Sdteske f_sysrc_set keymap "norwegian.iso" || f_die 281238438Sdteske break ;; 282238438Sdteske polish_iso) 283238438Sdteske f_sysrc_set keymap "pl_PL.ISO8859-2" || f_die 284238438Sdteske break ;; 285238438Sdteske portuguese) 286238438Sdteske f_sysrc_set keymap "pt.iso" || f_die 287238438Sdteske break ;; 288238438Sdteske portuguese_accent) 289238438Sdteske f_sysrc_set keymap "pt.iso.acc" || f_die 290238438Sdteske break ;; 291238438Sdteske russia_koi8_r) 292238438Sdteske f_sysrc_set keymap "ru.koi8-r" || f_die 293238438Sdteske break ;; 294238438Sdteske slovak) 295238438Sdteske f_sysrc_set keymap "sk.iso2" || f_die 296238438Sdteske break ;; 297238438Sdteske slovenian) 298238438Sdteske f_sysrc_set keymap "si.iso" || f_die 299238438Sdteske break ;; 300238438Sdteske spanish) 301238438Sdteske f_sysrc_set keymap "spanish.iso" || f_die 302238438Sdteske break ;; 303238438Sdteske spanish_accent) 304238438Sdteske f_sysrc_set keymap "spanish.iso.acc" || f_die 305238438Sdteske break ;; 306238438Sdteske swedish_cp850) 307238438Sdteske f_sysrc_set keymap "swedish.cp850" || f_die 308238438Sdteske break ;; 309238438Sdteske swedish_iso) 310238438Sdteske f_sysrc_set keymap "swedish.iso" || f_die 311238438Sdteske break ;; 312238438Sdteske swiss_french_cp850) 313238438Sdteske f_sysrc_set keymap "swissfrench.cp850" || f_die 314238438Sdteske break ;; 315238438Sdteske swiss_french_iso) 316238438Sdteske f_sysrc_set keymap "swissfrench.iso" || f_die 317238438Sdteske break ;; 318238438Sdteske swiss_french_iso_accent) 319238438Sdteske f_sysrc_set keymap "swissfrench.iso.acc" || f_die 320238438Sdteske break ;; 321238438Sdteske swiss_german_cp850) 322238438Sdteske f_sysrc_set keymap "swissgerman.cp850" || f_die 323238438Sdteske break ;; 324238438Sdteske swiss_german_iso) 325238438Sdteske f_sysrc_set keymap "swissgerman.iso" || f_die 326238438Sdteske break ;; 327238438Sdteske swiss_german_iso_accent) 328238438Sdteske f_sysrc_set keymap "swissgerman.iso.acc" || f_die 329238438Sdteske break ;; 330238438Sdteske uk_cp850) 331238438Sdteske f_sysrc_set keymap "uk.cp850" || f_die 332238438Sdteske break ;; 333238438Sdteske uk_iso) 334238438Sdteske f_sysrc_set keymap "uk.iso" || f_die 335238438Sdteske break ;; 336238438Sdteske ukrainian_koi8_u) 337238438Sdteske f_sysrc_set keymap "ua.koi8-u" || f_die 338238438Sdteske break ;; 339238438Sdteske ukrainian_koi8_u_koi8_r) 340238438Sdteske f_sysrc_set keymap "ua.koi8-u.shift.alt" || f_die 341238438Sdteske break ;; 342238438Sdteske usa_capslock_ctrl) 343238438Sdteske f_sysrc_set keymap "us.pc-ctrl" || f_die 344238438Sdteske break ;; 345238438Sdteske usa_dvorak) 346238438Sdteske f_sysrc_set keymap "us.dvorak" || f_die 347238438Sdteske break ;; 348238438Sdteske usa_dvorak_left) 349238438Sdteske f_sysrc_set keymap "us.dvorakl" || f_die 350238438Sdteske break ;; 351238438Sdteske usa_dvorak_right) 352238438Sdteske f_sysrc_set keymap "us.dvorakr" || f_die 353238438Sdteske break ;; 354238438Sdteske usa_emacs) 355238438Sdteske f_sysrc_set keymap "us.emacs" || f_die 356238438Sdteske break ;; 357238438Sdteske usa_iso) 358238438Sdteske f_sysrc_set keymap "us.iso" || f_die 359238438Sdteske break ;; 360238438Sdteske usa_unix) 361238438Sdteske f_sysrc_set keymap "us.unix" || f_die 362238438Sdteske break ;; 363238438Sdteske esac 364238438Sdteskedone 365238438Sdteske 366238438Sdteskeexit $SUCCESS 367238438Sdteske 368238438Sdteske################################################################################ 369238438Sdteske# END 370238438Sdteske################################################################################ 371