From e9eb7498c7ce5f3271d53f0fe2c6a949e2f86eff Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Wed, 20 Jun 2007 10:35:00 +0200 Subject: [PATCH 1/1] move environment stuff from /etc/zsh/zshenv; added function minimal-shell; added keybinding ctrl-x1 to jump behind the first word --- debian/changelog | 16 ++++++----- etc/minimal-shellrc | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ etc/zsh/zshenv | 11 -------- etc/zsh/zshrc | 36 +++++++++++++++++++++++- 4 files changed, 124 insertions(+), 19 deletions(-) create mode 100644 etc/minimal-shellrc diff --git a/debian/changelog b/debian/changelog index 5e2d51d..c449400 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,13 +1,15 @@ -grml-etc-core (0.3.13) unstable; urgency=low - - * /etc/zsh/zshrc: added function dnews (to view Debian's NEWS file of the - package). - - -- Michael Prokop Tue, 12 Jun 2007 14:00:55 +0200 - grml-etc-core (0.3.12) unstable; urgency=low * Added some more examples to /etc/network/interfaces.examples. + * /etc/zsh/zshrc: + - move environment stuff from /etc/zsh/zshenv to + /etc/zsh/zshrc so we don't have all the environment variables + in 'zsh -f', thanks for the patch - ft! + - added function dnews (to view Debian's NEWS file of the package) + - added function minimal-shell (spawn a minimally set up ksh), + thanks ft! + - added keybinding ctrl-x1 to jump behind the first word on the + cmdline, thanks again ft! -- Michael Prokop Sun, 10 Jun 2007 00:04:08 +0200 diff --git a/etc/minimal-shellrc b/etc/minimal-shellrc new file mode 100644 index 0000000..f01580b --- /dev/null +++ b/etc/minimal-shellrc @@ -0,0 +1,80 @@ +# 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. + +# skip this setup for non-interactive shells +[[ -o interactive && -t 0 ]] || return + +export PATH="/bin:/sbin/:/usr/bin/:/usr/sbin:/usr/local/bin:/usr/local/sbin:${HOME}/bin:/opt/bin" +export EDITOR='ed' + +if [[ -x $(which vim) ]] ; then + export VISUAL='vim' +else + export VISUAL='vi' +fi +if [[ -x $(which less) ]] ; then + export PAGER='less' +else + export PAGER='more' +fi + +FPATH=/usr/share/ksh/functions +HISTSIZE=500 +HISTEDIT="$EDITOR" + +# some options. +set -o emacs -o trackall -o globstar + +# aliases for various command shortcuts +alias ls='ls --color=auto' # we're on grml, so we do have GNU ls. +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 + +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/,$//' | \ + while read -r line ; do + key="${line%=*}" + seq="${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' ) ;; + 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 + +# put the current directory and history number in the prompt. +# use a wrapper for 'cd' to get '~' instead of /home/foo/. +function _cd { + "cd" "$@" + [[ $PWD = $HOME* && $HOME != / ]] && _pwd=\~"${PWD#$HOME}" && return + _pwd="$PWD" +} +alias cd=_cd +_cd . +PS1='(!)-$_pwd\$ ' diff --git a/etc/zsh/zshenv b/etc/zsh/zshenv index 7e0d2f3..6bf2742 100644 --- a/etc/zsh/zshenv +++ b/etc/zsh/zshenv @@ -24,17 +24,6 @@ # language settings (read in /etc/environment before /etc/default/locale as # the latter one is the default on Debian nowadays) [ -r /etc/environment ] && source /etc/environment - if [ -n "$LANG" ] ; then - export LANG - else - [ -r /etc/default/locale ] && source /etc/default/locale - fi - [ -n "$LANG" ] && export LANG || export LANG="en_US.iso885915" - [ -n "$LC_ALL" ] && export LC_ALL - [ -n "$LC_MESSAGES" ] && export LC_MESSAGES - - [ -r /etc/sysconfig/keyboard ] && source /etc/sysconfig/keyboard - [ -r /etc/timezone ] && TZ=$(cat /etc/timezone) # set environment variables (important for autologin on tty) [ -z "$HOSTNAME" ] && export HOSTNAME=`hostname` diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 92a9634..60a67b3 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -3,7 +3,7 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Die Jun 12 14:00:47 CEST 2007 [mika] +# Latest change: Mit Jun 20 10:28:28 CEST 2007 [mika] ################################################################################ # This file is sourced only for interactive shells. It # should contain commands to set up aliases, functions, @@ -19,6 +19,20 @@ fi # }}} +# locale setup {{{ + if [ -n "$LANG" ] ; then + export LANG + else + [ -r /etc/default/locale ] && source /etc/default/locale + fi + [ -n "$LANG" ] && export LANG || export LANG="en_US.iso885915" + [ -n "$LC_ALL" ] && export LC_ALL + [ -n "$LC_MESSAGES" ] && export LC_MESSAGES + + [ -r /etc/sysconfig/keyboard ] && source /etc/sysconfig/keyboard + [ -r /etc/timezone ] && TZ=$(cat /etc/timezone) +# }}} + # check for potentially old files in 'completion.d' {{{ setopt extendedglob xof=(/etc/zsh/completion.d/*~/etc/zsh/completion.d/_*(N)) @@ -413,6 +427,21 @@ fi } zle -N sudo-command-line _sudo-command-line bindkey "^Os" sudo-command-line + +### jump behind the first word on the cmdline. +### useful to add options. + function jump_after_first_word() { + local words + words=(${(z)BUFFER}) + if (( ${#words} <= 1 )) ; then + CURSOR=${#BUFFER} + else + CURSOR=${#${words[1]}} + fi + } + zle -N jump_after_first_word + bindkey '^x1' jump_after_first_word + # }}} # {{{ set some important options @@ -1314,6 +1343,11 @@ If you want to use xinit anyway please call \"/usr/bin/xinit\"." salias dhclient "$(wavemon -d | awk '/device/{print $2}')" } + # spawn a minimally set up ksh - useful if you want to umount /usr/. + minimal-shell() { + exec env -i ENV="/etc/minimal-shellrc" HOME="$HOME" TERM="$TERM" ksh + } + # Switching shell safely and efficiently? http://www.zsh.org/mla/workers/2001/msg02410.html # bash() { # NO_SWITCH="yes" command bash "$@" -- 2.1.4