As announced in:
<http://ml.grml.org/pipermail/grml-devel/2010-February/000011.html>
The minimal-shell() function now checks if the shell in question (mksh)
is available and if so, executes it with an empty environment, with only
TERM and HOME set. The mksh setup used sets a number of other
environment variables (such as $VISUAL, $EDITOR and $PAGER).
One added feature is that the mksh prompt shows non-zero return values
from programs you ran:
[snip]
(3)-~$ false
[1]-(4)-~$ true
(5)-~$
[snap]
The prompt does *not* feature any eye-candy such as standout or colour
sequences. It should therefore run in pretty much every terminal.
Special keys are set up via terminfo if `infocmp' is available.
Otherwise mksh's rather sane defaults are used.
+grml-etc-core (0.3.80) UNRELEASED; urgency=low
+
+ * zshrc: Switched `minimal-shell' from ksh93 to mksh.
+
+ -- Frank Terbeck <ft@grml.org> Mon, 01 Mar 2010 17:48:01 +0100
+
grml-etc-core (0.3.79) unstable; urgency=low
[ Ulrich Dangel ]
grml-etc-core (0.3.79) unstable; urgency=low
[ Ulrich Dangel ]
-#
-# configuration used for an absolute minimal ksh shell.
-# Reason: reference no files in /usr/, so that FS can be umounted.
+# Configuration for the `minimal-shell' function of grml's zsh setup.
+# That function spawns a `mksh' shell with this file as its configuration.
# skip this setup for non-interactive shells
[[ -o interactive && -t 0 ]] || return
# skip this setup for non-interactive shells
[[ -o interactive && -t 0 ]] || return
-FPATH=/usr/share/ksh/functions
-HISTSIZE=500
-HISTEDIT="$EDITOR"
-
-set -o emacs -o trackall -o globstar
+set -o bgnice \
+ -o braceexpand \
+ -o emacs \
+ -o markdirs \
+ -o monitor \
+ -o nohup \
+ -o trackall
# aliases for various command shortcuts
alias ls='ls --color=auto' # we're on grml, so we do have GNU ls.
# aliases for various command shortcuts
alias ls='ls --color=auto' # we're on grml, so we do have GNU ls.
alias la='ls -LaFb'
alias pu='ps -fu $USER'
alias la='ls -LaFb'
alias pu='ps -fu $USER'
-# Use keyboard trap to map keys to other keys
-# note that escape sequences vary for different terminals so these
-# may not work for you
-trap '.sh.edchar=${keymap[${.sh.edchar}]:-${.sh.edchar}}' KEYBD
-
+## Keybindings
+bind '^L=clear-screen'
if [[ -x $(which infocmp) ]] && [[ -x $(which sed) ]] ; then
if [[ -x $(which infocmp) ]] && [[ -x $(which sed) ]] ; then
- # reading some special keys from terminfo database.
- # should work everywhere. hopefully.
- typeset -A keymap
- infocmp -L | sed '1,2d;s/\t//;s/, /\n/g;s/,$//' | \
+ # Reading some special keys from terminfo database. If `infocmp'
+ # cannot be found, we rely on mksh to do the right thing.
+ infocmp -x1L | sed '/^\t[^k]/d;/^[^\t]/d;s/\t//;s/,$//' | \
while read -r line ; do
key="${line%=*}"
while read -r line ; do
key="${line%=*}"
+ [[ "${key}" != k* ]] && continue
+ seq="$(print "${line#*=}")"
- key_left) keymap+=( [$(print "$seq")]=$'\cb' ) ;;
- key_right) keymap+=( [$(print "$seq")]=$'\cf' ) ;;
- key_up) keymap+=( [$(print "$seq")]=$'\cp' ) ;;
- key_down) keymap+=( [$(print "$seq")]=$'\cn' ) ;;
- key_home) keymap+=( [$(print "$seq")]=$'\ca' ) ;;
- key_end) keymap+=( [$(print "$seq")]=$'\ce' ) ;;
- key_backspace) keymap+=( [$(print "$seq")]=$'\ch' ) ;;
- key_dc) keymap+=( [$(print "$seq")]=$'\cd' ) ;;
+ key_left) bind "${seq}"='backward-char' ;;
+ key_right) bind "${seq}"='forward-char' ;;
+ key_up) bind "${seq}"='up-history' ;;
+ key_down) bind "${seq}"='down-history' ;;
+ key_ppage) bind "${seq}"='search-history-up' ;;
+ key_npage) bind "${seq}"='search-history-down' ;;
+ key_home) bind "${seq}"='beginning-of-line' ;;
+ key_end) bind "${seq}"='end-of-line' ;;
+ key_backspace) bind "${seq}"='delete-char-backward' ;;
+ key_dc) bind "${seq}"='delete-char-forward' ;;
-else
- # fallback, does not work in all terminals.
- keymap=(
- [$'\eOD']=$'\eb' # Ctrl-Left -> move word left
- [$'\eOC']=$'\ef' # Ctrl-Right -> move word right
- [$'\e[3~']=$'\cd' # Delete -> delete to right
- [$'\e[1~']=$'\ca' # Home -> move to beginning of line
- [$'\e[4~']=$'\ce' # End -> move to end of line
- )
+function _lrv {
+ local rv="$?"
+ if [[ "${rv}" != 0 ]]; then
+ print -- "[${rv}]-"
+ fi
+ return 0
+}
# put the current directory and history number in the prompt.
# use a wrapper for 'cd' to get '~' instead of /home/foo/.
function _cd {
# put the current directory and history number in the prompt.
# use a wrapper for 'cd' to get '~' instead of /home/foo/.
function _cd {
+PS1='$(_lrv)(!)-$_pwd'
+if (( USER_ID )); then
+ PS1="$PS1"'\$ '
+else
+ PS1="$PS1"'# '
+fi
+
+HISTSIZE=500
+HISTEDIT="$EDITOR"
+# This is the default in mksh, but we make sure in case people tempered
+# with it in their environment.
+unset HISTFILE
+true
salias dhclient "$(wavemon -d | awk '/device/{print $2}')"
}
salias dhclient "$(wavemon -d | awk '/device/{print $2}')"
}
-# spawn a minimally set up ksh - useful if you want to umount /usr/.
+# spawn a minimally set up mksh - useful if you want to umount /usr/.
- exec env -i ENV="/etc/minimal-shellrc" HOME="$HOME" TERM="$TERM" ksh
+ emulate -L zsh
+ local shell="mksh"
+
+ if ! check_com -c ${shell}; then
+ printf '`%s'\'' not available, giving up.\n' ${shell} >&2
+ return 1
+ fi
+
+ exec env -i ENV="/etc/minimal-shellrc" HOME="$HOME" TERM="$TERM" ${shell}
}
# a wrapper for vim, that deals with title setting
}
# a wrapper for vim, that deals with title setting