From e7f84863ff37d54cc2b99e259b4aa2698543a767 Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Mon, 1 Mar 2010 17:50:10 +0100 Subject: [PATCH] zshrc: Switch `minimal-shell()' from ksh93 to mksh As announced in: 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. --- debian/changelog | 6 ++++ etc/minimal-shellrc | 82 ++++++++++++++++++++++++++++++----------------------- etc/zsh/zshrc | 12 ++++++-- 3 files changed, 62 insertions(+), 38 deletions(-) diff --git a/debian/changelog b/debian/changelog index ddcf173..14cf58b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +grml-etc-core (0.3.80) UNRELEASED; urgency=low + + * zshrc: Switched `minimal-shell' from ksh93 to mksh. + + -- Frank Terbeck Mon, 01 Mar 2010 17:48:01 +0100 + grml-etc-core (0.3.79) unstable; urgency=low [ Ulrich Dangel ] diff --git a/etc/minimal-shellrc b/etc/minimal-shellrc index f01580b..68dccdf 100644 --- a/etc/minimal-shellrc +++ b/etc/minimal-shellrc @@ -1,7 +1,6 @@ # vim:ft=sh:fdm=marker -# -# 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 @@ -20,12 +19,14 @@ else export PAGER='more' fi -FPATH=/usr/share/ksh/functions -HISTSIZE=500 -HISTEDIT="$EDITOR" - # some options. -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. @@ -33,41 +34,38 @@ alias ll='ls -lFb' 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 - # 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%=*}" - seq="${line#*=}" + [[ "${key}" != k* ]] && continue + seq="$(print "${line#*=}")" case "$key" in - 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' ;; esac done -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 - ) fi +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 { @@ -77,4 +75,16 @@ function _cd { } alias cd=_cd _cd . -PS1='(!)-$_pwd\$ ' +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 diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 036b4e7..e30f511 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -2953,9 +2953,17 @@ iwclient() { 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/. minimal-shell() { - 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 -- 2.1.4