Release new version 0.19.7
[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='command ls --color=auto'  # we're on grml, so we do have GNU ls.
33 alias ll='command ls -l --color=auto'
34 alias la='command ls -la --color=auto'
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 -r -- "${line#*=}" | sed -e 's,\\\([1-7][0-7]*\),\\0\1,g')"
47             seq="$(print "${seq}")"
48             case "$key" in
49                 key_left)      bind "${seq}"='backward-char'        ;;
50                 key_right)     bind "${seq}"='forward-char'         ;;
51                 key_up)        bind "${seq}"='up-history'           ;;
52                 key_down)      bind "${seq}"='down-history'         ;;
53                 key_ppage)     bind "${seq}"='search-history-up'    ;;
54                 key_npage)     bind "${seq}"='search-history-down'  ;;
55                 key_home)      bind "${seq}"='beginning-of-line'    ;;
56                 key_end)       bind "${seq}"='end-of-line'          ;;
57                 key_backspace) bind "${seq}"='delete-char-backward' ;;
58                 key_dc)        bind "${seq}"='delete-char-forward'  ;;
59             esac
60         done
61 fi
62
63 function _lrv {
64     local rv="$?"
65     if [[ "${rv}" != 0 ]]; then
66         print -- "[${rv}]-"
67     fi
68     return 0
69 }
70 # put the current directory and history number in the prompt.
71 # use a wrapper for 'cd' to get '~' instead of /home/foo/.
72 function _cd {
73     "cd" "$@"
74     [[ $PWD = $HOME* && $HOME != / ]] && _pwd=\~"${PWD#$HOME}" && return
75     _pwd="$PWD"
76 }
77 alias cd=_cd
78 _cd .
79 PS1='$(_lrv)(!)-$_pwd'
80 if (( USER_ID )); then
81     PS1="$PS1"'\$ '
82 else
83     PS1="$PS1"'# '
84 fi
85
86 HISTSIZE=500
87 HISTEDIT="$EDITOR"
88 # This is the default in mksh, but we make sure in case people tempered
89 # with it in their environment.
90 unset HISTFILE
91 true