From 3fd11bbeda8436436384debc479cd1d9c8815de2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20=27z3ttacht=27=20Steinb=C3=83=C2=B6ck?= Date: Sun, 27 Jan 2008 16:48:21 +0100 Subject: [PATCH] whatwhen() -- Get what you did when from the history. e.g. % whatwhen grml 6682 2008-01-27 16:44 vim etc/grml/screenrc 6683 2008-01-27 16:45 screen -c etc/grml/screenrc --- etc/skel/.zshrc | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/etc/skel/.zshrc b/etc/skel/.zshrc index d8fb9f7..4f44c38 100644 --- a/etc/skel/.zshrc +++ b/etc/skel/.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: Son Dez 09 22:58:07 CET 2007 [mika] +# Latest Change: Sat Jan 26 11:55:04 CET 2008 ################################################################################ # source ~/.zshrc.global {{{ @@ -1037,6 +1037,55 @@ zurl() { | sed 's/value=//;s/"//g' } +#f2# Find history events by search pattern and list them by date. +whatwhen() { +# {{{ + local usage help ident format_l format_s first_char remain first last + usage='USAGE: whatwhen [options] ' + help='Use' \`'whatwhen -h'\'' for further explanations.' + ident=${(l,${#${:-Usage: }},, ,)} + format_l="${ident}%s\t\t\t%s\n" + format_s="${format_l//(\\t)##/\\t}" + # Make the first char of the word to search for case + # insensitive; e.g. [aA] + first_char=[${(L)1[1]}${(U)1[1]}] + remain=${1[2,-1]} + # Default search range is `-100'. + first=${2:-\-100} + # Optional, just used for ` ' given. + last=$3 + case $1 in + ("") + printf '%s\n\n' 'ERROR: No search string specified. Aborting.' + printf '%s\n%s\n\n' ${usage} ${help} && return 1 + ;; + (-h) + printf '%s\n\n' ${usage} + print 'OPTIONS:' + printf $format_l '-h' 'show help text' + print '\f' + print 'SEARCH RANGE:' + printf $format_l "'0'" 'the whole history,' + printf $format_l '-' 'offset to the current history number; (default: -100)' + printf $format_s '<[-]first> []' 'just searching within a give range' + printf '\n%s\n' 'EXAMPLES:' + printf ${format_l/(\\t)/} 'whatwhen grml' '# Range is set to -100 by default.' + printf $format_l 'whatwhen zsh -250' + printf $format_l 'whatwhen foo 1 99' + ;; + (\?) + printf '%s\n%s\n\n' ${usage} ${help} && return 1 + ;; + (*) + # -l list results on stout rather than invoking $EDITOR. + # -i Print dates as in YYYY-MM-DD. + # -m Search for a - quoted - pattern within the history. + fc -li -m "*${first_char}${remain}*" $first $last + ;; + esac +# }}} +} + # change fluxbox keys from 'Alt-#' to 'Alt-F#' and vice versa fluxkey-change() { [[ -n "$FLUXKEYS" ]] || local FLUXKEYS="$HOME/.fluxbox/keys" @@ -1095,8 +1144,6 @@ weather() { return 1 fi } - - # }}} # mercurial related stuff {{{ -- 2.1.4