move environment stuff from /etc/zsh/zshenv; added function minimal-shell; added...
[grml-etc-core.git] / etc / minimal-shellrc
1 # vim:ft=sh:fdm=marker
2 #
3 # configuration used for an absolute minimal ksh shell.
4 # Reason: reference no files in /usr/, so that FS can be umounted.
5
6 # skip this setup for non-interactive shells
7 [[ -o interactive && -t 0 ]] || return
8
9 export PATH="/bin:/sbin/:/usr/bin/:/usr/sbin:/usr/local/bin:/usr/local/sbin:${HOME}/bin:/opt/bin"
10 export EDITOR='ed'
11
12 if [[ -x $(which vim) ]] ; then
13     export VISUAL='vim'
14 else
15     export VISUAL='vi'
16 fi
17 if [[ -x $(which less) ]] ; then
18     export PAGER='less'
19 else
20     export PAGER='more'
21 fi
22
23 FPATH=/usr/share/ksh/functions
24 HISTSIZE=500
25 HISTEDIT="$EDITOR"
26
27 # some options.
28 set -o emacs -o trackall -o globstar
29
30 # aliases for various command shortcuts
31 alias ls='ls --color=auto'  # we're on grml, so we do have GNU ls.
32 alias ll='ls -lFb'
33 alias la='ls -LaFb'
34 alias pu='ps -fu $USER'
35
36 # Use keyboard trap to map keys to other keys
37 # note that escape sequences vary for different terminals so these
38 # may not work for you
39 trap '.sh.edchar=${keymap[${.sh.edchar}]:-${.sh.edchar}}' KEYBD
40
41 if [[ -x $(which infocmp) ]] && [[ -x $(which sed) ]] ; then
42     # reading some special keys from terminfo database.
43     # should work everywhere. hopefully.
44     typeset -A keymap
45     infocmp -L | sed '1,2d;s/\t//;s/, /\n/g;s/,$//' | \
46         while read -r line ; do
47             key="${line%=*}"
48             seq="${line#*=}"
49             case "$key" in
50                 key_left)       keymap+=( [$(print "$seq")]=$'\cb' ) ;;
51                 key_right)      keymap+=( [$(print "$seq")]=$'\cf' ) ;;
52                 key_up)         keymap+=( [$(print "$seq")]=$'\cp' ) ;;
53                 key_down)       keymap+=( [$(print "$seq")]=$'\cn' ) ;;
54                 key_home)       keymap+=( [$(print "$seq")]=$'\ca' ) ;;
55                 key_end)        keymap+=( [$(print "$seq")]=$'\ce' ) ;;
56                 key_backspace)  keymap+=( [$(print "$seq")]=$'\ch' ) ;;
57                 key_dc)         keymap+=( [$(print "$seq")]=$'\cd' ) ;;
58             esac
59         done
60 else
61     # fallback, does not work in all terminals.
62     keymap=(
63         [$'\eOD']=$'\eb'   # Ctrl-Left  -> move word left
64         [$'\eOC']=$'\ef'   # Ctrl-Right -> move word right
65         [$'\e[3~']=$'\cd'  # Delete     -> delete to right
66         [$'\e[1~']=$'\ca'  # Home       -> move to beginning of line
67         [$'\e[4~']=$'\ce'  # End        -> move to end of line
68     )
69 fi
70
71 # put the current directory and history number in the prompt.
72 # use a wrapper for 'cd' to get '~' instead of /home/foo/.
73 function _cd {
74     "cd" "$@"
75     [[ $PWD = $HOME* && $HOME != / ]] && _pwd=\~"${PWD#$HOME}" && return
76     _pwd="$PWD"
77 }
78 alias cd=_cd
79 _cd .
80 PS1='(!)-$_pwd\$ '