Package: zsh
Severity: wishlist

Hi,

as discussed I attached a smallish but featureful zshrc.  It is
currently (including comments) 50 lines long.  The only feature enabled
by default is a rather small but usable prompt, the other features can
be enabled by uncommenting them.

Things I considered important for such an example file are:
 * It should be small enough to be read and understood in a very short
   time.
 * Comments should make it easy to understand what it does, even for new
   zsh users.
 * It should include the (subjectively) most wanted features.
 * By default only a minimal feature set should be enabled, the user
   should choose which additional features he or she wants to enable.
 * There should be no "internal dependencies" to let users enable
   selected features without the need to enable additional ones.
 * It should not break when users also uncomment the comments, thus
   I used "# ### actual comment".

You suggested "/etc/zsh/recommended.zshrc or something", I think
zshrc.recommended would be a better file name because people would get
displayed all zshrcs together if they alphabetically sort these files.
Putting it under /usr/share/doc/examples would not needlessly clutter
/etc.


I also started to create a more fully featured zshrc that includes the
content of zshrc.recommended at the beginning.  This file could be
a base for an additional zshrc in /u/s/d/zsh/examples, possibly named
zshrc.extended.  It is far away from being complete (whatever this would
be for such a skeleton file), but could be brought to a state where it
could be included in the Debian package if a handful zsh users would add
their favorite features (and fix errors of previous contributors).  If
you like this idea, this bug could be cloned to collect these additions
until it has reached a state you consider to be ready to be included in
the Debian package.


Especially zshrc.recommended is hardly copyrightable since it consists
of configuration and comments.  Frank Terbeck, who wrote the last three
lines, said that these lines are nearly identical to the ones in
zshcontrib(1).  The comment at the begin of the file was copied from
/etc/zsh/zshrc and then adapted.  If you really disagree that this is
not copyrightable, feel free to distribute it under any DFSG free
license.

zshrc.extended additionally includes bk(), new()[1] and a fixed sll()
from grml and a code snippet from [2]. If you think the rest is
copyrightable (I don't) feel free to distribute it under any DFSG free
license.


Regards
Carsten

 [1] new.(), changed() and changed.() were written by me based on new()
 [2] http://chris-lamb.co.uk/2009/11/19/transparent-directory-replacement-zsh/
# ~/.zshrc file for zsh(1).
#
# This file is sourced only for interactive shells. It should contain
# commands to set up aliases, functions, options, key bindings, etc.
#
# Global Order: zshenv, zprofile, zshrc, zlogin
#
# To enable the below-mentioned features uncomment the according lines.


# ### Include user name, host name and current working directory in the prompt:
PS1='%(!..%n@)%m:%~%# '

# ### Select emacs like key bindings:
# bindkey -e

# ### Define some useful aliases:
# alias ls='ls --color=auto'
# alias l='ls -F'
# alias ll='ls -F -l'
# alias la='ls -F -A'

# ### Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
# HISTSIZE=1000
# SAVEHIST=1000
# HISTFILE=~/.zsh_history

# ### Teach less, e.g., reading compressed files and listing archive content:
# which lesspipe >/dev/null && eval "$(lesspipe)"

# ### Turn on completion with the default options:
# autoload -Uz compinit; compinit
# ### Enable completion menu:
# zstyle ':completion:*' menu select=2
# ### Activate colored completion:
# which dircolors >/dev/null && eval "$(dircolors -b)"
# zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}

# ### If we are in a Debian chroot display its name in the prompt:
# [[ -r /etc/debian_chroot ]] && : ${debian_chroot:="$(cat /etc/debian_chroot)"}
# PS1="${debian_chroot:+($debian_chroot)}%(!..%n@)%m:%~%# "

# ### Use vcs_info to include version control system information in the prompt:
# setopt prompt_subst
# autoload -Uz vcs_info; vcs_info && precmd() { vcs_info }
# PS1="${debian_chroot:+($debian_chroot)}%(!..%n@)%m:%~\${vcs_info_msg_0_}%# "
# ### Configure vcs_info to be colorful:
# zstyle ':vcs_info:*' actionformats ' 
%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
# zstyle ':vcs_info:*' formats ' %F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
# zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
# ~/.zshrc file for zsh(1).
#
# This file is sourced only for interactive shells. It should contain
# commands to set up aliases, functions, options, key bindings, etc.
#
# Global Order: zshenv, zprofile, zshrc, zlogin
#
# To enable the below-mentioned features uncomment the according lines.


# ### Include user name, host name and current working directory in the prompt:
PS1='%(!..%n@)%m:%~%# '

# ### Select emacs like key bindings:
# bindkey -e

# ### Define some useful aliases:
# alias ls='ls --color=auto'
# alias l='ls -F'
# alias ll='ls -F -l'
# alias la='ls -F -A'

# ### Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
# HISTSIZE=1000
# SAVEHIST=1000
# HISTFILE=~/.zsh_history

# ### Teach less, e.g., reading compressed files and listing archive content:
# which lesspipe >/dev/null && eval "$(lesspipe)"

# ### Turn on completion with the default options:
# autoload -Uz compinit; compinit
# ### Enable completion menu:
# zstyle ':completion:*' menu select=2
# ### Activate colored completion:
# which dircolors >/dev/null && eval "$(dircolors -b)"
# zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}

# ### If we are in a Debian chroot display its name in the prompt:
# [[ -r /etc/debian_chroot ]] && : ${debian_chroot:="$(cat /etc/debian_chroot)"}
# PS1="${debian_chroot:+($debian_chroot)}%(!..%n@)%m:%~%# "

# ### Use vcs_info to include version control system information in the prompt:
# setopt prompt_subst
# autoload -Uz vcs_info; vcs_info && precmd() { vcs_info }
# PS1="${debian_chroot:+($debian_chroot)}%(!..%n@)%m:%~\${vcs_info_msg_0_}%# "
# ### Configure vcs_info to be colorful:
# zstyle ':vcs_info:*' actionformats ' 
%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
# zstyle ':vcs_info:*' formats ' %F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
# zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'



# ### ########################################################################
# ### The lines before this section equal the file zshrc.recommended.  All   #
# ### features below this line are disabled, uncomment the according lines   #
# ### to enable them.                                                        #
# ### ########################################################################



# ### ########################################################################
# ### Environment variables:                                                 #
# ### ########################################################################

# ### TODO LESS, TIMEFMT, PAGER, GIT_EXEC_PATH, ...


# ### ########################################################################
# ### Zsh options:                                                           #
# ### ########################################################################

# ### Make cd push the old directory onto the directory stack.
# setopt autopushd

# ### TODO Add more options.


# ### ########################################################################
# ### Precmd / preexec:                                                      #
# ### ########################################################################

# ### Set xterm/rxvt title:
# preexec_xterm_title() {
#     [[ "$TERM" != "xterm" && "$TERM" == "${TERM#rxvt}" ]] && return
#     print -nR $'\033]0;'$1$'\a'
# }
# precmd_xterm_title() {
#     [[ "$TERM" != "xterm" && "$TERM" == "${TERM#rxvt}" ]] && return
#     print -nR $'\033]0;'Terminal$'\a'
# }
# preexec_functions=( ${preexec_functions} preexec_xterm_title )
# precmd_functions=(  ${precmd_functions}  precmd_xterm_title )

# ### Set screen's window title:
# preexec_screen_window_title() {
#     [[ "$TERM" == "${TERM#screen}" ]] && return
#     setopt localoptions extendedglob shwordsplit
#     typeset -a cmd
#     cmd=(${${1}[(wr)^(*=*|nice|sudo|time|env|fakeroot|trickle|-*),-1]})
#     local cmd1="$cmd[1]"
#     local m1='' m2=''
#     [[ -n "$cmd[2]" ]] || { echo -ne "\ek$m1$cmd[1]$m2\e\\"; return; }
#     if   { [[ "$cmd1" == "man"     ]] && m1="(" && m2=")" } \
#       || { [[ "$cmd1" == "perldoc" ]] && m1="(" && m2=")" } \
#       || { [[ "$cmd1" == "make"    ]] && m1="%" && m2="%" } \
#       || { [[ "$cmd1" == "vim"     ]] && m1="[" && m2="]" } \
#       || { [[ "$cmd1" == "vi"      ]] && m1="[" && m2="]" } \
#       || { [[ "$cmd1" == "emacs"   ]] && m1="[" && m2="]" } \
#       || { [[ "$cmd1" == "mcedit"  ]] && m1="[" && m2="]" } \
#       || { [[ "$cmd1" == "nano"    ]] && m1="[" && m2="]" } \
#       || { [[ "$cmd1" == "ee"      ]] && m1="[" && m2="]" } \
#       || { [[ "$cmd1" == "joe"     ]] && m1="[" && m2="]" } \
#       || { [[ "$cmd1" == "less"    ]] && m1="[" && m2="]" } \
#       || { [[ "$cmd1" == "more"    ]] && m1="[" && m2="]" } \
#       || { [[ "$cmd1" == "most"    ]] && m1="[" && m2="]" }
#     then
#         shift 1 cmd
#         cmd=(${${cmd}[(wr)^(*=*|-*|1|2|3|4|5|6|7|8),-1]})
#         cmd[1]="${${${${cmd[1]}##*/}%=}:-$cmd1}"
#     fi
#     echo -ne "\ek$m1$cmd[1]$m2\e\\"
# }
# precmd_screen_window_title() {
#     [[ "$TERM" == "${TERM#screen}" ]] && return
#     echo -ne "\ekzsh\e\\"
# }
# preexec_functions=( ${preexec_functions} preexec_screen_window_title )
# precmd_functions=(  ${precmd_functions}  precmd_screen_window_title )

# ### Transparent directory replacement:
# ### http://chris-lamb.co.uk/2009/11/19/transparent-directory-replacement-zsh/
# precmd_transparent_dir_replacement() {
#     [ . -ef "$PWD" ] && return 0
#     local OLDOLDPWD="$OLDPWD"
#     cd -- "$PWD" >/dev/null 2>&1 || {
#         echo >&2 "W: $PWD does not exist anymore."
#         return 1
#     }
#     OLDPWD="$OLDOLDPWD"
# }
# precmd_functions=( ${precmd_functions} precmd_transparent_dir_replacement )


# ### ########################################################################
# ### Aliases:                                                               #
# ### ########################################################################

# ### Ordinary aliases:
# (which grep  && grep --help  2>/dev/null | grep -- --color)  >/dev/null && \
#     alias grep='grep --color=auto'
# (which egrep && egrep --help 2>/dev/null | egrep -- --color) >/dev/null && \
#     alias egrep='egrep --color=auto'
# alias cp='nocorrect cp'
# alias ln='nocorrect ln'
# alias mkdir='nocorrect mkdir'
# alias mv='nocorrect mv'
# alias rm='nocorrect rm'

# ### Suffix aliases:
# ### TODO
# ###  * See http://dev.codemac.net/config.git?p=config.git;a=blob;f=zsh/alias
# ###    for an example
# ###  * Should probably be combined with `which'.


# ### ########################################################################
# ### Functions:                                                             #
# ### ########################################################################

# ### bk():   Make a backup of a file.
# bk() {
#     cp -a "$1" "${1}_$(date --iso-8601=seconds)";
# }

# ### cdt():  Create temporary directory and chdir into it.
# cdt() {
#     [[ $# -eq 0 ] || printf 'Usage: %s\n' "$0";
#     cd "$(mktemp -t -d cdt.XXXXXXXXXX)";
# }

# ### changed(), changed.():
# ###   List files which have been changed within the last n days,
# ###   n defaults to 1.  changed.() lists changed files starting with a dot.
# changed()   { emulate -L zsh; print -l  *(c-${1:1}); }
# changed.()  { emulate -L zsh; print -l .*(c-${1:1}); }

# ### md():   Create given directory recursively and chdir into it.
# md() {
#     [[ $# -eq 1 ]] || printf 'Usage: %s <directory>\n' "$0";
#     mkdir -p "$1" && cd "$1";
# }

# ### new(), new.():
# ###   List files which have been modified within the last n days,
# ###   n defaults to 1.  new.() lists new files starting with a dot.
# new()       { emulate -L zsh; print -l  *(m-${1:1}); }
# new.()      { emulate -L zsh; print -l .*(m-${1:1}); }

# ### sll():  List symlinks in detail (more detailed version of 'readlink -f')
# sll() {
#     [[ -z "$1" ]] && printf 'Usage: %s <file(s)>\n' "$0" && return 1
#     (
#         for file in "$@"; do
#             while [[ -h "$file" ]]; do
#                 ls -l "$file"
#                 cd "$(dirname "$file")"
#                 file="$(readlink "$file")"
#             done
#             ls -l "$file"
#         done
#     )
# }

# ### unik(): Print unique lines, input does not need to be sorted.
# unik()      { perl -ne 'print unless $seen{$_}++' "$@"; }

# ### TODO Include more functions, e.g., from grml's zshrc.


# ### ########################################################################
# ### Misc:                                                                  #
# ### ########################################################################

# ### Chdir to ~ if zsh was started in a non-existent directory.
# [[ "$PWD" == '.' ]] && cd

# ### Cat dead.letter.
# if [[ -f "$HOME/dead.letter" ]]; then
#     echo "$HOME/dead.letter:"
#     cat "$HOME/dead.letter"
#     echo
# fi
# if [[ "$USERNAME" == "root" ]] && [[ -f  "/dead.letter" ]]; then
#     echo "/dead.letter:"
#     cat "/dead.letter"
#     echo
# fi

# ### Source ~/.zshrc.local if it exists and is readable.
# [[ -r ~/.zshrc.local ]] && . ~/.zshrc.local

Reply via email to