Skip to content

Instantly share code, notes, and snippets.

@byrney
Last active May 1, 2016 20:02
Show Gist options
  • Save byrney/f1b1bc5c80774e5f7a437f5b37f6afbf to your computer and use it in GitHub Desktop.
Save byrney/f1b1bc5c80774e5f7a437f5b37f6afbf to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# When terminal has "use option key as meta" then opt-3 (hash or pound)
# is not accessible because readline maps it to digit-argument
#
# bind -p | grep e3
# the see the mapping
#
# bind provides a way to remove a mapping `bind -r` but that just leaves us
# with the key doing nothing. So we have to explicitly map to the correct char,
# and that means we need to detect the layout.
#
# Because we can only detect the attatched keyboard we need to make some
# allowances for connections over ssh. If LC_KBD_LAYOUT environment variable is
# set already we don't detect again. LC_* env vars are usually allowed through
# an ssh connection (/etc/sshd_config) so when this shell is started via ssh
# we use the remote value
#
# this needs to be sourced in .bashrc at both ends of the ssh connection
#
# Set LC_KBD_LAYOUT if it has not already been set
#
if [[ -z ${LC_KBD_LAYOUT+x} ]] && which defaults > /dev/null ; then
LC_KBD_LAYOUT=$( defaults read com.apple.HIToolbox.plist AppleCurrentKeyboardLayoutInputSourceID )
export LC_KBD_LAYOUT
fi
#
# Mapping for US kbd
#
if [[ "${LC_KBD_LAYOUT:-unknown}" = 'com.apple.keylayout.US' ]] ; then
bind '"\e3":"£"'
fi
#
# mapping for british keyboard
#
if [[ "${LC_KBD_LAYOUT:-unknown}" = 'com.apple.keylayout.British' ]] ; then
bind '"\e3":"#"'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment