From 8c31b4976fe10fa683b14f8e57dbcf20022c6476 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 2 Oct 2018 20:12:15 -0400 Subject: [PATCH 1/1] zshrc: Improve keymap setup. Move the keymap setup to a shell function and add a wrapper around reset which reconfigures the keymap after resetting the terminal. --- COPYING.WTFPL2 | 13 +++++++ zshrc | 92 ++++++++++++++++++++++++++------------------------ 2 files changed, 60 insertions(+), 45 deletions(-) create mode 100644 COPYING.WTFPL2 diff --git a/COPYING.WTFPL2 b/COPYING.WTFPL2 new file mode 100644 index 0000000..d23841b --- /dev/null +++ b/COPYING.WTFPL2 @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + 22 rue de Plaisance, 75014 Paris, France + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/zshrc b/zshrc index 10edaa9..af977aa 100644 --- a/zshrc +++ b/zshrc @@ -1,11 +1,10 @@ -# Configuration for interactive shells. +# Copyright © 2009-2011, 2017-2018 Nick Bowler # -# Copyright (C) 2009 Nick Bowler +# Default configuration for interactive zsh. # -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. # Default shell options setopt EXTENDED_GLOB @@ -16,46 +15,49 @@ if [[ -n $HOME ]]; then fi HISTSIZE=10000 -bindkey -e - -case $TERM in -rxvt*) - if [[ $TERM =~ '^rxvt-unicode' ]]; then - [[ -z $COLORTERM ]] && export COLORTERM='rxvt-xpm' - [[ -z $COLORFGBG ]] && export COLORFGBG='15;default;0' - fi - - bindkey '\e[3~' delete-char - bindkey '\e[8~' end-of-line - bindkey '\e[7~' beginning-of-line -;; -screen*|linux|cygwin) - bindkey '\e[3~' delete-char - bindkey '\e[4~' end-of-line - bindkey '\e[1~' beginning-of-line - bindkey '\eOM' accept-line -;; -xterm*) - bindkey '\e[3~' delete-char - bindkey '\e[F' end-of-line - bindkey '\e[H' beginning-of-line - bindkey '\eOH' beginning-of-line - bindkey '\eOF' end-of-line -;; -cons25) - bindkey '^?' delete-char - bindkey '\e[F' end-of-line - bindkey '\e[H' beginning-of-line -;; -esac +reset_keymap() { + local k del home end + + case $# in + 0) : ;; + *) export KEYMAP=$1 ;; + esac + + case $TERM in + rxvt*) + del=('\e[3~') home=('\e[7~') end=('\e[8~') ;; + screen*|linux|cygwin) + del=('\e[3~') home=('\e[1~') end=('\e[4~') ;; + cons25) + del=('^?') home=('\e[H') end=('\e[F') ;; + xterm*) + del=('\e[3~') + home=('\e[1~' '\e[H' '\e[OH') + end=('\e[4~' '\e[F' '\e[OF') + ;; + esac + + bindkey -e + for k in "${del[@]}"; do bindkey "$k" delete-char; done + for k in "${home[@]}"; do bindkey "$k" beginning-of-line; done + for k in "${end[@]}"; do bindkey "$k" end-of-line; done + + stty stop '' + case $KEYMAP in + colemak) + bindkey '^R' history-incremental-search-forward + bindkey '^P' history-incremental-search-backward + stty eof '^S' ;; + *) + stty eof '^D' ;; + esac +} +reset_keymap -# Keymap-specific bindings -case $KEYMAP in -colemak) - bindkey '^R' history-incremental-search-forward - bindkey '^P' history-incremental-search-backward - ;; -esac +reset() { + command reset + reset_keymap +} # Set the xterm title case $TERM in -- 2.43.2