whatwhen() -- Get what you did when from the history.
authorAlexander 'z3ttacht' Steinböck <z3ttacht@grml.org>
Sun, 27 Jan 2008 15:48:21 +0000 (16:48 +0100)
committerAlexander 'z3ttacht' Steinböck <z3ttacht@grml.org>
Sun, 27 Jan 2008 15:48:21 +0000 (16:48 +0100)
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

index d8fb9f7..4f44c38 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: 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] <searchstring> <search range>'
+    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 `<first> <last>' 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 '-<n>' 'offset to the current history number; (default: -100)'
+            printf $format_s '<[-]first> [<last>]' '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 {{{