]> git.draconx.ca Git - zshconf.git/blob - zshrc
zshrc: Improve keymap setup.
[zshconf.git] / zshrc
1 # Copyright © 2009-2011, 2017-2018 Nick Bowler
2 #
3 # Default configuration for interactive zsh.
4 #
5 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
6 # This is free software: you are free to do what the fuck you want to.
7 # There is NO WARRANTY, to the extent permitted by law.
8
9 # Default shell options
10 setopt EXTENDED_GLOB
11
12 if [[ -n $HOME ]]; then
13         HISTFILE=$HOME/.zsh_history
14         SAVEHIST=10000
15 fi
16 HISTSIZE=10000
17
18 reset_keymap() {
19   local k del home end
20
21   case $# in
22   0) : ;;
23   *) export KEYMAP=$1 ;;
24   esac
25
26   case $TERM in
27   rxvt*)
28     del=('\e[3~') home=('\e[7~') end=('\e[8~') ;;
29   screen*|linux|cygwin)
30     del=('\e[3~') home=('\e[1~') end=('\e[4~') ;;
31   cons25)
32     del=('^?') home=('\e[H') end=('\e[F') ;;
33   xterm*)
34     del=('\e[3~')
35     home=('\e[1~' '\e[H' '\e[OH')
36     end=('\e[4~' '\e[F' '\e[OF')
37     ;;
38   esac
39
40   bindkey -e
41   for k in "${del[@]}"; do bindkey "$k" delete-char; done
42   for k in "${home[@]}"; do bindkey "$k" beginning-of-line; done
43   for k in "${end[@]}"; do bindkey "$k" end-of-line; done
44
45   stty stop ''
46   case $KEYMAP in
47   colemak)
48     bindkey '^R' history-incremental-search-forward
49     bindkey '^P' history-incremental-search-backward
50     stty eof '^S' ;;
51   *)
52     stty eof '^D' ;;
53   esac
54 }
55 reset_keymap
56
57 reset() {
58   command reset
59   reset_keymap
60 }
61
62 # Set the xterm title
63 case $TERM in
64         xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
65                 settitle() { print -Pn $'\e]0;%n@%m %33<...<%~%<<\a' }
66                 ;;
67         screen)
68                 settitle() { print -Pn $'\e_%n@%m %33<...<%~%<<\e\\' }
69                 ;;
70         *)
71                 settitle() { }
72                 ;;
73 esac
74
75 # Show the return code of failed commands, but don't be noisy about it.
76 precmd() {
77         settitle
78
79         if [[ -n $__NEWRUN ]]; then
80                 RPS1='%(0?,,%B%F{red}RC=%?%f%b)'
81                 unset __NEWRUN
82         else
83                 unset RPS1
84         fi
85 }
86
87 preexec() {
88         __NEWRUN=yes
89 }
90
91 # A gentoo-like prompt.
92 PS1='%B%(!,%F{red},%F{green}%n@)%m %F{blue}%33<...<%~%<< %#%f%b '
93
94 if [ -n $COLORTERM ]; then
95         # Assorted colour-related options
96         export MINICOM="-c on"
97 fi
98
99 if [[ -n $SSH_CONNECTION ]]; then
100         PS1=${PS1/green/yellow}
101 fi
102
103 # Locale
104 export LANG=en_CA.UTF-8
105 export LC_COLLATE=ja_JP.UTF-8
106
107 # Default options for various utilities.
108 alias ls='ls -N --time-style=long-iso --color=auto'
109 alias grep='grep --color=auto'
110
111 # I hate mistakes
112 alias mv='mv -i'
113 alias rm='rm -i'
114 alias cp='cp -i'
115
116 # Common aliases
117 alias vv='$EDITOR ~/.zshrc && source ~/.zshrc'
118 alias ll='ls -l'
119 alias lr='ls -rtl'