move environment stuff from /etc/zsh/zshenv; added function minimal-shell; added...
authorMichael Prokop <mika@grml.org>
Wed, 20 Jun 2007 08:35:00 +0000 (10:35 +0200)
committerMichael Prokop <mika@grml.org>
Wed, 20 Jun 2007 08:35:00 +0000 (10:35 +0200)
debian/changelog
etc/minimal-shellrc [new file with mode: 0644]
etc/zsh/zshenv
etc/zsh/zshrc

index 5e2d51d..c449400 100644 (file)
@@ -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 <mika@grml.org>  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 <mika@grml.org>  Sun, 10 Jun 2007 00:04:08 +0200
 
diff --git a/etc/minimal-shellrc b/etc/minimal-shellrc
new file mode 100644 (file)
index 0000000..f01580b
--- /dev/null
@@ -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\$ '
index 7e0d2f3..6bf2742 100644 (file)
 # 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`
index 92a9634..60a67b3 100644 (file)
@@ -3,7 +3,7 @@
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # 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,
   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 "$@"