From 1c9fe535aef45739bf2f34178ba642fd4ffcbde0 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Tue, 24 Jan 2012 15:30:13 +0100 Subject: [Funcs] when / todo if exists --- .zlogin | 2 +- 01_Functions.zsh | 48 +++++++++++++++++++++------------------------ user:hugues/KeyBindings.zsh | 5 ++++- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/.zlogin b/.zlogin index 449706b..599b45f 100644 --- a/.zlogin +++ b/.zlogin @@ -1,6 +1,6 @@ cmd_exists keychain && eval $(keychain --eval --inherit any-once --quick) -when +cmd_exists when && when true diff --git a/01_Functions.zsh b/01_Functions.zsh index d421602..3b49825 100644 --- a/01_Functions.zsh +++ b/01_Functions.zsh @@ -405,47 +405,43 @@ set_prompt_colors () guilt_colors[unapplied]=$color[black] } +cmd_exists when && \ when() { TODAY_FILE=~/.when/.today - if cmd_exists when - then - $(which -p when) $@ | tail -n+3 | \ - sed 's/^\(aujourd.hui *[0-9][0-9][0-9][0-9] [A-Z][a-z]\+ [0-9][0-9][ ]*\)\(.*\)/'$c_'1;33'$_c'\1\2'$c_'0'$_c'/; - s/^\(demain *[0-9][0-9][0-9][0-9] [A-Z][a-z]\+ [0-9][0-9][ ]*\)\(.*\)/'$c_'1'$_c'\1\2'$c_'0'$_c'/; - s/^\(hier *[0-9][0-9][0-9][0-9] [A-Z][a-z]\+ [0-9][0-9][ ]*\)\(.*\)/'$c_'3'$_c'\1\2'$c_'0'$_c'/' \ - > $TODAY_FILE + $(which -p when) $@ | tail -n+3 | \ + sed 's/^\(aujourd.hui *[0-9][0-9][0-9][0-9] [A-Z][a-z]\+ [0-9][0-9][ ]*\)\(.*\)/'$c_'1;33'$_c'\1\2'$c_'0'$_c'/; + s/^\(demain *[0-9][0-9][0-9][0-9] [A-Z][a-z]\+ [0-9][0-9][ ]*\)\(.*\)/'$c_'1'$_c'\1\2'$c_'0'$_c'/; + s/^\(hier *[0-9][0-9][0-9][0-9] [A-Z][a-z]\+ [0-9][0-9][ ]*\)\(.*\)/'$c_'3'$_c'\1\2'$c_'0'$_c'/' \ + > $TODAY_FILE - if [ -s $TODAY_FILE ] - then - preprint "À ne pas manquer" $color[red] ; echo - cat $TODAY_FILE - preprint "" $color[red] ; echo - echo - fi | sed 's/^/ /' - fi + if [ -s $TODAY_FILE ] + then + preprint "À ne pas manquer" $color[red] ; echo + cat $TODAY_FILE + preprint "" $color[red] ; echo + echo + fi | sed 's/^/ /' } +cmd_exists todo && \ todo() { - if cmd_exists todo + TODO=${=$(whereis -b todo | cut -d: -f2)} + if [ $($TODO $@ | wc -l) -gt 0 ] then - TODO=${=$(whereis -b todo | cut -d: -f2)} - if [ $($TODO $@ | wc -l) -gt 0 ] - then - preprint "À faire" $color[yellow] && echo - $TODO $@ --force-colour - preprint "" $color[yellow] && echo - echo - fi | sed 's/^/ /' - fi + preprint "À faire" $color[yellow] && echo + $TODO $@ --force-colour + preprint "" $color[yellow] && echo + echo + fi | sed 's/^/ /' } chpwd() { - todo + cmd_exists todo && todo if ( cmd_exists git && test -d .git ) then diff --git a/user:hugues/KeyBindings.zsh b/user:hugues/KeyBindings.zsh index 60648c7..ff23dac 100644 --- a/user:hugues/KeyBindings.zsh +++ b/user:hugues/KeyBindings.zsh @@ -201,10 +201,13 @@ do bindkey -M $keymap -s 'r' 'Q rehash\n' bindkey -M $keymap -s 'R' 'Q reset\n' - bindkey -M $keymap -s 'w' 'Q birthdays\n' + cmd_exists when && \ + bindkey -M $keymap -s 'w' 'Q when\n' + cmd_exists todo && ( bindkey -M $keymap -s 't' 'Q todo\n' bindkey -M $keymap -s 'T' 'Q todo all -c\n' + ) bindkey -M $keymap -s 'c' 'Q ./configure\n' bindkey -M $keymap -s '©' 'Q !?configure\n' -- cgit v1.2.3