zshrc: Switch `minimal-shell()' from ksh93 to mksh
[grml-etc-core.git] / etc / minimal-shellrc
1 # vim:ft=sh:fdm=marker
2 # Configuration for the `minimal-shell' function of grml's zsh setup.
3 # That function spawns a `mksh' shell with this file as its configuration.
4
5 # skip this setup for non-interactive shells
6 [[ -o interactive && -t 0 ]] || return
7
8 export PATH="/bin:/sbin/:/usr/bin/:/usr/sbin:/usr/local/bin:/usr/local/sbin:${HOME}/bin:/opt/bin"
9 export EDITOR='ed'
10
11 if [[ -x $(which vim) ]] ; then
12     export VISUAL='vim'
13 else
14     export VISUAL='vi'
15 fi
16 if [[ -x $(which less) ]] ; then
17     export PAGER='less'
18 else
19     export PAGER='more'
20 fi
21
22 # some options.
23 set -o bgnice        \
24     -o braceexpand   \
25     -o emacs         \
26     -o markdirs      \
27     -o monitor       \
28     -o nohup         \
29     -o trackall
30
31 # aliases for various command shortcuts
32 alias ls='ls --color=auto'  # we're on grml, so we do have GNU ls.
33 alias ll='ls -lFb'
34 alias la='ls -LaFb'
35 alias pu='ps -fu $USER'
36
37 ## Keybindings
38 bind '^L=clear-screen'
39 if [[ -x $(which infocmp) ]] && [[ -x $(which sed) ]] ; then
40     # Reading some special keys from terminfo database. If `infocmp'
41     # cannot be found, we rely on mksh to do the right thing.
42     infocmp -x1L | sed '/^\t[^k]/d;/^[^\t]/d;s/\t//;s/,$//' | \
43         while read -r line ; do
44             key="${line%=*}"
45             [[ "${key}" != k* ]] && continue
46             seq="$(print "${line#*=}")"
47             case "$key" in
48                 key_left)      bind "${seq}"='backward-char'        ;;
49                 key_right)     bind "${seq}"='forward-char'         ;;
50                 key_up)        bind "${seq}"='up-history'           ;;
51                 key_down)      bind "${seq}"='down-history'         ;;
52                 key_ppage)     bind "${seq}"='search-history-up'    ;;
53                 key_npage)     bind "${seq}"='search-history-down'  ;;
54                 key_home)      bind "${seq}"='beginning-of-line'    ;;
55                 key_end)       bind "${seq}"='end-of-line'          ;;
56                 key_backspace) bind "${seq}"='delete-char-backward' ;;
57                 key_dc)        bind "${seq}"='delete-char-forward'  ;;
58             esac
59         done
60 fi
61
62 function _lrv {
63     local rv="$?"
64     if [[ "${rv}" != 0 ]]; then
65         print -- "[${rv}]-"
66     fi
67     return 0
68 }
69 # put the current directory and history number in the prompt.
70 # use a wrapper for 'cd' to get '~' instead of /home/foo/.
71 function _cd {
72     "cd" "$@"
73     [[ $PWD = $HOME* && $HOME != / ]] && _pwd=\~"${PWD#$HOME}" && return
74     _pwd="$PWD"
75 }
76 alias cd=_cd
77 _cd .
78 PS1='$(_lrv)(!)-$_pwd'
79 if (( USER_ID )); then
80     PS1="$PS1"'\$ '
81 else
82     PS1="$PS1"'# '
83 fi
84
85 HISTSIZE=500
86 HISTEDIT="$EDITOR"
87 # This is the default in mksh, but we make sure in case people tempered
88 # with it in their environment.
89 unset HISTFILE
90 true