From f8dfa7bf4d674d6b5a2b5c02ef484ac1d228a0e0 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Tue, 24 Jan 2012 17:18:40 +0100 Subject: -- HUGE CLEANUP -- Phase #1 --- .zlogin | 4 +- .zlogout | 2 +- 01_Functions.zsh | 452 -------------------------------------------- 01_Internal.zsh | 322 +++++++++++++++++++++++++++++++ 02_Functions.zsh | 63 ++++++ 10_Environment.zsh | 18 +- 11_Colors.zsh | 74 +++++++- 12_Prompts.zsh | 113 ++++++----- 99_Exec.zsh | 2 +- net:foret/Prompts.zsh | 6 +- net:sweethome/Aliases.zsh | 8 +- user:hugues/Aliases.zsh | 26 +-- user:hugues/Environment.zsh | 2 +- user:hugues/KeyBindings.zsh | 4 +- 14 files changed, 555 insertions(+), 541 deletions(-) delete mode 100644 01_Functions.zsh create mode 100644 01_Internal.zsh create mode 100644 02_Functions.zsh diff --git a/.zlogin b/.zlogin index 599b45f..e41ad10 100644 --- a/.zlogin +++ b/.zlogin @@ -1,6 +1,6 @@ -cmd_exists keychain && eval $(keychain --eval --inherit any-once --quick) +__cmd_exists keychain && eval $(keychain --eval --inherit any-once --quick) -cmd_exists when && when +__cmd_exists when && when true diff --git a/.zlogout b/.zlogout index 7e7b00f..7173950 100755 --- a/.zlogout +++ b/.zlogout @@ -1,4 +1,4 @@ #!/bin/zsh -#cmd_exists keychain && keychain --quick --clear +#__cmd_exists keychain && keychain --quick --clear diff --git a/01_Functions.zsh b/01_Functions.zsh deleted file mode 100644 index 3f6f579..0000000 --- a/01_Functions.zsh +++ /dev/null @@ -1,452 +0,0 @@ -## -## Part of configuration files for Zsh 4 -## by Hugues Hiegel -## -## NO WARRANTY PROVIDED, USE AT YOUR OWN RISKS -## -## You are encouraged to use, modify, and redistribute -## these files with or without this notice. -## - -## -## User-defined functions -## -# -# For preexec, precmd, chpwd and other built-in functions, -# go see the file Prompts.zsh -# - - -cmd_exists () -{ - which -p $1 >/dev/null 2>&1 -} - -git () { - GIT=$(which -p git) - case $1 in - init|clone|config) - ;; - *) - if [ "$( ( $GIT ls-files ; $GIT ls-tree HEAD . ) 2>&- | head -n1)" = ""\ - -a \( ! -d .git -o "$($GIT rev-parse --git-dir 2>&-)" != ".git" \)\ - -a "$($GIT rev-parse --is-inside-git-dir 2>&-)" != "true" ] - then - echo >&2 "git $1: the current folder is not managed by git" - return - fi - ;; - esac - - $(which -p git) $@ -} - -term_title() -{ - # Jobs - typeset -A command - for word in ${=@} ; command[$#command]=$word - if [ "$command[0]" = "fg" ] - then - lastjob=$(ps t `tty` | grep "[0-9]\+[[:blank:]]\+`tty | sed 's/\/dev\///'`[[:blank:]]\+T.\? \+.:.. \\\_ " | tail -n1 | cut -c32-) - set "$lastjob" - fi - if [ "$command[0]" = "screen" -o "$command[0]" = "tmux" ] - then - # discards screen args - set $command[0] - fi - - [ ! "$@" = "" ] && set " |" $@ - - if [[ -t 1 ]] - then - case $TERM in - sun-cmd) - print -Pn "\e]l%n@%m %~$@\e\\" # Never tested.. - ;; - *term*|rxvt*|putty) - print -Pn "\e]0;%n@%m (%l) %~$@\a" # Sets term title - ;; - screen*) - local _sep="" - [ $# -gt 0 ] && _sep=$1 && shift # gets and discards the separator, if any. - #if [ ! -z "$TMUX" ] - #then - # Tmux - #print -Pn "\e]0;%n@%m (%l) %~${_sep:+$_sep #[fg=yellow,bold]}$@\a" # Sets term title - print -Pn "\e]0;#[fg=red]%n#[fg=default,bold]@#[fg=red]%m#[default] (#[fg=cyan]%l#[fg=default]) #[fg=red]%~${_sep:+#[default,fg=default]$_sep #[fg=yellow,bold]$@}#[default,fg=default]\a" - #else - # Classic screen - # hardstatus - #print -Pn "\e]2;{+b W}SCREEN #n {-b W}| {R}?u(u) ?{W}{r}%n@%m{W} ({c}%l{W}) {R}%~{W}${_sep:+$_sep \{+b Y\}}$@{-b W}\a" # Sets hardstatus line (term title) - # print -Pn "\e]2;{R}?u(u) ?{W}{r}%n{R}@{r}%m{-b W} ({+b c}%l{-b W}) {R}%~{W}${_sep:+$_sep \{+b Y\}}$@{-b W}\a" # Sets hardstatus line (term title) - # caption - # print -Pn "\ek" - # [ "$SUDO_USER" != "" ] && print -Pn "($USER) " - # print -Pn "${@:-%~}" - # print -Pn "\e\\" - #fi - ;; - *) - ;; - esac - fi -} - -preprint() -{ - local my_color i - my_color=${2-"$prompt_colors[generic]"} - - hbar=$T_ - for i in {1..$((74 - ${#1} - 5))} - do - hbar=${hbar}$_tq_ - done - hbar=${hbar}$_T - - if [ "$1" != "" ] - then - print -Pn "${C_}$my_color;1${_C}${hbar}$T_$_tj_$_T${C_}0;$my_color${_C} $1 ${C_}0;$my_color;1${_C}$T_$_tm_$_tq_$_T\r${C_}0${_C}" - else - print -Pn "${C_}$my_color;1${_C}${hbar}$T_$_tq_$_tq_$_tq_$_tq_$_tq_$_T${C_}0${_C}" - fi -} - -get_gcl_branch () -{ - case $1 in - git) - get_git_branch - ;; - hg) - get_hg_branch - ;; - *) - ;; - esac -} - -get_hg_branch () -{ - HGROOT=$(hg root 2>/dev/null) - if [ ! -z "$HGROOT" ] - then - hg branch - fi -} - -get_git_branch () -{ - local my_git_branch checkouted_branch="yes" - - if [ -f ".repo/manifests.git/config" ] - then - my_git_branch=$(grep merge .repo/manifests.git/config | awk '{print $3}') - if [ $my_git_branch != "" ] - then - echo "[$my_git_branch]" - return - fi - fi - - # Get git branch only from git managed folders (not ignored subfolders..) - [ "$( ( git ls-files ; git ls-tree HEAD . ) 2>&- | head -n1)" = "" -a \( ! -d .git -o "$(git rev-parse --git-dir 2>&-)" != ".git" \) -a "$(git rev-parse --is-inside-git-dir 2>&-)" != "true" ] && return - - GIT_DIR=$(git rev-parse --git-dir) - - # Get current working GIT branch - my_git_branch="$(git branch 2>&- | grep -E '^\* ' | cut -c3-)" - - if [ "$my_git_branch" != "" ] - then - # If not on a working GIT branch, get the named current commit-ish inside parenthesis - [ "$my_git_branch" = "(no branch)" ] &&\ - checkouted_branch="" && \ - my_git_branch="$(git name-rev --name-only HEAD 2>&- | sed 's,^tags/,,;s,^remotes/,,;s,\^0$,,')" - - # If neither on a named commit-ish, show commit-id - if [ "$my_git_branch" = "undefined" ] - then - my_git_branch="$(git rev-parse --verify HEAD 2>&-)" - fi - else - # Initial commit - if [ -L $GIT_DIR/HEAD -a ! -f $GIT_DIR/HEAD ] - then - my_git_branch="$(basename $GIT_DIR/$(LC_ALL=C stat --printf="%N\n" $GIT_DIR/HEAD | tr '`' "'" | cut -d\' -f4))" - else - my_git_branch="$(basename $GIT_DIR/$(cat $GIT_DIR/HEAD | sed 's/^\([0-9a-f]\{2\}\)\([0-9a-f]\{38\}\)$/objects\/\1\/\2/;s/^ref: //'))" - fi - fi - - # Rebase in progress ? - if [ -d $GIT_DIR/rebase-merge -o -d $GIT_DIR/rebase-apply ] - then - local rebase current last - local REBASE_DIR - - if [ -d $GIT_DIR/rebase-merge ] - then - REBASE_DIR=$GIT_DIR/rebase-merge - else - REBASE_DIR=$GIT_DIR/rebase-apply - fi - - if [ "$REBASE_DIR" = "$GIT_DIR/rebase-merge" ] - then - current=$(< $REBASE_DIR/done wc -l) - last=$(( $current + $(< $REBASE_DIR/git-rebase-todo grep -v "^#\|^[[:blank:]]*$" | wc -l) )) - rebase=$rebase$rebase_in_progress": " - else - current=$(cat $REBASE_DIR/next) - last=$(cat $REBASE_DIR/last) - fi - - # Then the result - my_git_branch="[rebase $current/$last: "$(git name-rev --name-only "$(cat $REBASE_DIR/onto 2>/dev/null)" 2>/dev/null)".."$my_git_branch"]" - [ -r $REBASE_DIR/head-name ] && my_git_branch=$my_git_branch" "$(< $REBASE_DIR/head-name sed 's/^refs\///;s/^heads\///') - else - # No rebase in progress, put '(' ')' if needed - [ ! "$checkouted_branch" ] && my_git_branch="($my_git_branch)" - fi - - if [ "$(git status 2>&- | grep "new file" | head -n1)" != "" ] ; then - # ADDED FILES - my_git_branch=$my_git_branch - fi - - echo $my_git_branch -} - -get_guilt_series () -{ - # Guilt - # - guilt="" - - if ( cmd_exists guilt && guilt status >/dev/null 2>&- ) - then - applied=$(guilt applied 2>/dev/null | wc -l) - unapplied=$(guilt unapplied 2>/dev/null | wc -l) - if [ $(($applied + $unapplied)) -gt 0 ] - then - guilt=" "$C_$guilt_colors[applied]$_C - while [ $applied -gt 0 ] - do - guilt=$guilt"·" - applied=$(($applied - 1)) - done - guilt=$guilt$C_$guilt_colors[unapplied]$_C - while [ $unapplied -gt 0 ] - do - guilt=$guilt"·" - unapplied=$(($unapplied - 1)) - done - guilt=$guilt$C_$colors[none]$_C - fi - fi - - echo $guilt -} - -# We *must* have previously checked that -# we obtained a correct GIT branch with -# a call to `get_git_branch` -get_git_status () -{ - local my_git_status cached not_up_to_date managment_folder - - if [ ! -z "$DO_NOT_CHECK_GIT_STATUS" ] - then return - fi - - if [ -f ".repo/manifests.git/config" ] - then - echo "$git_colors[up_to_date]"; - return - fi - - if [ "$(git rev-parse --is-inside-git-dir)" = "true" -o "$(git config --get core.bare)" = "true" ] ; then - echo "$git_colors[managment_folder]" - return - fi - - if [ "$(git diff --cached 2>&- | grep '^diff ' | head -n1 )" != "" ] ; then - cached="yes" - fi - if [ "$(git ls-files -m 2>&- | head -n1)" != "" ] ; then - not_up_to_date="yes" - fi - - GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) - - if [ "$cached" != "" -a "$not_up_to_date" != "" ] ; then - my_git_status="$git_colors[cached_and_not_up_to_date]" - elif [ "$cached" != "" ] ; then - my_git_status="$git_colors[cached]" - elif [ "$not_up_to_date" != "" ] ; then - my_git_status="$git_colors[not_up_to_date]" - elif [ "$(git cat-file -t HEAD 2>/dev/null)" != "commit" ] ; then - if [ ! -z "$(git ls-files)" ] ; then - my_git_status="$git_colors[cached]" - else - my_git_status="$git_colors[init_in_progress]" - fi - else - if [ -f $GIT_DIR/MERGE_HEAD ] - then - my_git_status="$git_colors[cached]" - else - my_git_status="$git_colors[up_to_date]" - fi - fi - - echo $my_git_status -} - -zsh_status () -{ - if [ $ZDOTDIR != "" ] - then - cd $ZDOTDIR >/dev/null - _status="$(git describe --always)" - if [ "$( (git diff --cached ; git diff) | head -n1)" != "" ] - then - _status=$_status"-$( (git diff --cached ; git diff) | md5sum | sed 's/^\(.......\).*$/-D1rTY-\1/')" - fi - echo $_status - else - echo - fi -} - -normal_user () -{ - if [ -e /etc/login.defs ] - then - eval `grep -v '^[$#]' /etc/login.defs | grep "^UID_" | tr -d '[:blank:]' | sed 's/^[A-Z_]\+/&=/'` - [ \( $UID -ge $UID_MIN \) ] - else - [ "`whoami`" != "root" ] - fi -} - -privileged_user () -{ - ! normal_user -} - - -# This func is intended to give a quick way to set the colors for the -# prompt inside a running zsh-session -# -set_prompt_colors () -{ - local my_generic - # Get the generic color from cmdline, else from envvar... - my_generic=${1:-$prompt_colors[generic]} - # ...then stores it to envvar. :) - prompt_colors[generic]=$my_generic - - # Get soft and bold values of generic color, whichever it is bold or not - prompt_colors[bold_generic]="$(echo "$prompt_colors[generic]" | tr ';' '\n' | grep -v "^$color[bold]$" | tr '\n' ';' | sed 's/\;$//');$color[bold]" - prompt_colors[soft_generic]="$(echo "$prompt_colors[generic]" | tr ';' '\n' | grep -v "^$color[bold]$" | tr '\n' ';' | sed 's/\;$//')" - - prompt_colors[path]="$prompt_colors[generic];$color[bold]" # pwd - bold generic - #prompt_colors[term]="$prompt_colors[generic]" # tty - unused, see term title - prompt_colors[user]="$prompt_colors[generic]" # login - generic - prompt_colors[host]="$prompt_colors[generic]" # hostname - generic - prompt_colors[display]="$prompt_colors[generic]" # hostname - generic - #prompt_colors[hist]="$color[none]" # history number - unused - prompt_colors[arob]="$color[bold];$prompt_colors[generic]" # @ - bold generic - prompt_colors[dies]="$prompt_colors[generic]" # the bottom-end of the prompt - generic - prompt_colors[doubledot]="$color[none]" # separates pwd from git-branch - none - #prompt_colors[paren]="$color[cyan]" # parenthesis (around tty) - unused, see term title - prompt_colors[bar]="$prompt_colors[generic];$color[bold]" # horizontal bar - bold generic - prompt_colors[braces]="$prompt_colors[bar]" # braces (around date) - bar color - prompt_colors[error]="$color[bold];$color[yellow]" # error code - bold yellow - - prompt_colors[warning]="$color[bold];$color[yellow]" - - date_colors[normal]=$prompt_colors[soft_generic] - date_colors[exec]=$prompt_colors[bold_generic] - prompt_colors[date]=$date_colors[normal] # full date - - prompt_colors[cmd]="$color[none]" # command prompt - prompt_colors[exec]="$color[none]" # command output - - battery_colors[full]="$prompt_colors[soft_generic]" - battery_colors[charging]="$prompt_colors[bold_generic]" - battery_colors[uncharging]="$prompt_colors[soft_generic]" - battery_colors[critical]="$color[bg-red];$prompt_colors[bold_generic]" - - mail_colors[unread]="$color[yellow];$color[bold]" # mail received - mail_colors[listes]="$prompt_colors[generic];$color[bold]" # less important mail received - - agent_colors[empty]="$prompt_colors[soft_generic]" - agent_colors[remote_empty]="$color[bold];$color[black]" - agent_colors[has_keys]="$color[bold];$color[yellow]" - agent_colors[has_remote_keys]="$prompt_colors[bold_generic]" - - prompt_colors[up_to_date]="$prompt_colors[generic]" # up-to-date - prompt_colors[not_up_to_date]="$color[green];$color[bold]" # not up to date - prompt_colors[to_be_commited]="$color[yellow];$color[bold]" # changes in cache - - git_colors[managment_folder]="$color[red];$color[bold]" # .git/... folder browsing - git_colors[cached]="$prompt_colors[to_be_commited]" # git changes in cache - git_colors[cached_and_not_up_to_date]="$prompt_colors[not_up_to_date];$color[bold]" - git_colors[not_up_to_date]="$prompt_colors[not_up_to_date];$color[normal]" # git changes in working tree - git_colors[init_in_progress]="$color[black];$color[bold]" # initialization - git_colors[up_to_date]="$prompt_colors[up_to_date];$color[normal]" # git up-to-date - - guilt_colors[applied]=$git_colors[cached] - guilt_colors[unapplied]=$color[black] -} - -cmd_exists when && \ -when() -{ - TODAY_FILE=~/.when/.today - - $(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/^/ /' -} - -cmd_exists todo && \ -todo() -{ - 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/^/ /' -} - -chpwd() -{ - - cmd_exists todo && todo - - if ( cmd_exists git && test -d .git ) - then - # Shows tracked branches and modified files - git checkout HEAD 2>&1 | sed 's/^/ /' - fi -} - diff --git a/01_Internal.zsh b/01_Internal.zsh new file mode 100644 index 0000000..8e4991a --- /dev/null +++ b/01_Internal.zsh @@ -0,0 +1,322 @@ +## +## Part of configuration files for Zsh 4 +## by Hugues Hiegel +## +## NO WARRANTY PROVIDED, USE AT YOUR OWN RISKS +## +## You are encouraged to use, modify, and redistribute +## these files with or without this notice. +## + +## +## User-defined functions +## +# +# For preexec, precmd, chpwd and other built-in functions, +# go see the file Prompts.zsh +# + + +__cmd_exists () +{ + which -p $1 >/dev/null 2>&1 +} + +__term_title() +{ + # Jobs + typeset -A command + for word in ${=@} ; command[$#command]=$word + if [ "$command[0]" = "fg" ] + then + lastjob=$(ps t `tty` | grep "[0-9]\+[[:blank:]]\+`tty | sed 's/\/dev\///'`[[:blank:]]\+T.\? \+.:.. \\\_ " | tail -n1 | cut -c32-) + set "$lastjob" + fi + if [ "$command[0]" = "screen" -o "$command[0]" = "tmux" ] + then + # discards screen args + set $command[0] + fi + + [ ! "$@" = "" ] && set " |" $@ + + if [[ -t 1 ]] + then + case $TERM in + sun-cmd) + print -Pn "\e]l%n@%m %~$@\e\\" # Never tested.. + ;; + *term*|rxvt*|putty) + print -Pn "\e]0;%n@%m (%l) %~$@\a" # Sets term title + ;; + screen*) + local _sep="" + [ $# -gt 0 ] && _sep=$1 && shift # gets and discards the separator, if any. + #if [ ! -z "$TMUX" ] + #then + # Tmux + #print -Pn "\e]0;%n@%m (%l) %~${_sep:+$_sep #[fg=yellow,bold]}$@\a" # Sets term title + print -Pn "\e]0;#[fg=red]%n#[fg=default,bold]@#[fg=red]%m#[default] (#[fg=cyan]%l#[fg=default]) #[fg=red]%~${_sep:+#[default,fg=default]$_sep #[fg=yellow,bold]$@}#[default,fg=default]\a" + #else + # Classic screen + # hardstatus + #print -Pn "\e]2;{+b W}SCREEN #n {-b W}| {R}?u(u) ?{W}{r}%n@%m{W} ({c}%l{W}) {R}%~{W}${_sep:+$_sep \{+b Y\}}$@{-b W}\a" # Sets hardstatus line (term title) + # print -Pn "\e]2;{R}?u(u) ?{W}{r}%n{R}@{r}%m{-b W} ({+b c}%l{-b W}) {R}%~{W}${_sep:+$_sep \{+b Y\}}$@{-b W}\a" # Sets hardstatus line (term title) + # caption + # print -Pn "\ek" + # [ "$SUDO_USER" != "" ] && print -Pn "($USER) " + # print -Pn "${@:-%~}" + # print -Pn "\e\\" + #fi + ;; + *) + ;; + esac + fi +} + +__preprint() +{ + local my_color i + my_color=${2-"$_prompt_colors[generic]"} + + hbar=$T_ + for i in {1..$((74 - ${#1} - 5))} + do + hbar=${hbar}$_tq_ + done + hbar=${hbar}$_T + + if [ "$1" != "" ] + then + print -Pn "${C_}$my_color;1${_C}${hbar}$T_$_tj_$_T${C_}0;$my_color${_C} $1 ${C_}0;$my_color;1${_C}$T_$_tm_$_tq_$_T\r${C_}0${_C}" + else + print -Pn "${C_}$my_color;1${_C}${hbar}$T_$_tq_$_tq_$_tq_$_tq_$_tq_$_T${C_}0${_C}" + fi +} + +__get_gcl_branch () +{ + case $1 in + git) + __get_git_branch + ;; + hg) + __get_hg_branch + ;; + *) + ;; + esac +} + +__get_hg_branch () +{ + HGROOT=$(hg root 2>/dev/null) + if [ ! -z "$HGROOT" ] + then + hg branch + fi +} + +__get_git_branch () +{ + local my_git_branch checkouted_branch="yes" + + if [ -f ".repo/manifests.git/config" ] + then + my_git_branch=$(grep merge .repo/manifests.git/config | awk '{print $3}') + if [ $my_git_branch != "" ] + then + echo "[$my_git_branch]" + return + fi + fi + + # Get git branch only from git managed folders (not ignored subfolders..) + [ "$( ( git ls-files ; git ls-tree HEAD . ) 2>&- | head -n1)" = "" -a \( ! -d .git -o "$(git rev-parse --git-dir 2>&-)" != ".git" \) -a "$(git rev-parse --is-inside-git-dir 2>&-)" != "true" ] && return + + GIT_DIR=$(git rev-parse --git-dir) + + # Get current working GIT branch + my_git_branch="$(git branch 2>&- | grep -E '^\* ' | cut -c3-)" + + if [ "$my_git_branch" != "" ] + then + # If not on a working GIT branch, get the named current commit-ish inside parenthesis + [ "$my_git_branch" = "(no branch)" ] &&\ + checkouted_branch="" && \ + my_git_branch="$(git name-rev --name-only HEAD 2>&- | sed 's,^tags/,,;s,^remotes/,,;s,\^0$,,')" + + # If neither on a named commit-ish, show commit-id + if [ "$my_git_branch" = "undefined" ] + then + my_git_branch="$(git rev-parse --verify HEAD 2>&-)" + fi + else + # Initial commit + if [ -L $GIT_DIR/HEAD -a ! -f $GIT_DIR/HEAD ] + then + my_git_branch="$(basename $GIT_DIR/$(LC_ALL=C stat --printf="%N\n" $GIT_DIR/HEAD | tr '`' "'" | cut -d\' -f4))" + else + my_git_branch="$(basename $GIT_DIR/$(cat $GIT_DIR/HEAD | sed 's/^\([0-9a-f]\{2\}\)\([0-9a-f]\{38\}\)$/objects\/\1\/\2/;s/^ref: //'))" + fi + fi + + # Rebase in progress ? + if [ -d $GIT_DIR/rebase-merge -o -d $GIT_DIR/rebase-apply ] + then + local rebase current last + local REBASE_DIR + + if [ -d $GIT_DIR/rebase-merge ] + then + REBASE_DIR=$GIT_DIR/rebase-merge + else + REBASE_DIR=$GIT_DIR/rebase-apply + fi + + if [ "$REBASE_DIR" = "$GIT_DIR/rebase-merge" ] + then + current=$(< $REBASE_DIR/done wc -l) + last=$(( $current + $(< $REBASE_DIR/git-rebase-todo grep -v "^#\|^[[:blank:]]*$" | wc -l) )) + rebase=$rebase$rebase_in_progress": " + else + current=$(cat $REBASE_DIR/next) + last=$(cat $REBASE_DIR/last) + fi + + # Then the result + my_git_branch="[rebase $current/$last: "$(git name-rev --name-only "$(cat $REBASE_DIR/onto 2>/dev/null)" 2>/dev/null)".."$my_git_branch"]" + [ -r $REBASE_DIR/head-name ] && my_git_branch=$my_git_branch" "$(< $REBASE_DIR/head-name sed 's/^refs\///;s/^heads\///') + else + # No rebase in progress, put '(' ')' if needed + [ ! "$checkouted_branch" ] && my_git_branch="($my_git_branch)" + fi + + if [ "$(git status 2>&- | grep "new file" | head -n1)" != "" ] ; then + # ADDED FILES + my_git_branch=$my_git_branch + fi + + echo $my_git_branch +} + +__get_guilt_series () +{ + # Guilt + # + guilt="" + + if ( __cmd_exists guilt && guilt status >/dev/null 2>&- ) + then + applied=$(guilt applied 2>/dev/null | wc -l) + unapplied=$(guilt unapplied 2>/dev/null | wc -l) + if [ $(($applied + $unapplied)) -gt 0 ] + then + guilt=" "$c_$_guilt_colors[applied]$_C + while [ $applied -gt 0 ] + do + guilt=$guilt"·" + applied=$(($applied - 1)) + done + guilt=$guilt$c_$_guilt_colors[unapplied]$_C + while [ $unapplied -gt 0 ] + do + guilt=$guilt"·" + unapplied=$(($unapplied - 1)) + done + guilt=$guilt$C_$colors[none]$_C + fi + fi + + echo $guilt +} + +# We *must* have previously checked that +# we obtained a correct GIT branch with +# a call to `__get_git_branch` +__get_git_status () +{ + local my_git_status cached not_up_to_date managment_folder + + if [ ! -z "$DO_NOT_CHECK_GIT_STATUS" ] + then return + fi + + if [ -f ".repo/manifests.git/config" ] + then + echo "$_git_colors[up_to_date]"; + return + fi + + if [ "$(git rev-parse --is-inside-git-dir)" = "true" -o "$(git config --get core.bare)" = "true" ] ; then + echo "$_git_colors[managment_folder]" + return + fi + + if [ "$(git diff --cached 2>&- | grep '^diff ' | head -n1 )" != "" ] ; then + cached="yes" + fi + if [ "$(git ls-files -m 2>&- | head -n1)" != "" ] ; then + not_up_to_date="yes" + fi + + GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) + + if [ "$cached" != "" -a "$not_up_to_date" != "" ] ; then + my_git_status="$_git_colors[cached_and_not_up_to_date]" + elif [ "$cached" != "" ] ; then + my_git_status="$_git_colors[cached]" + elif [ "$not_up_to_date" != "" ] ; then + my_git_status="$_git_colors[not_up_to_date]" + elif [ "$(git cat-file -t HEAD 2>/dev/null)" != "commit" ] ; then + if [ ! -z "$(git ls-files)" ] ; then + my_git_status="$_git_colors[cached]" + else + my_git_status="$_git_colors[init_in_progress]" + fi + else + if [ -f $GIT_DIR/MERGE_HEAD ] + then + my_git_status="$_git_colors[cached]" + else + my_git_status="$_git_colors[up_to_date]" + fi + fi + + echo $my_git_status +} + +__zsh_status () +{ + if [ $ZDOTDIR != "" ] + then + cd $ZDOTDIR >/dev/null + _status="$(git describe --always)" + if [ "$( (git diff --cached ; git diff) | head -n1)" != "" ] + then + _status=$_status"-$( (git diff --cached ; git diff) | md5sum | sed 's/^\(.......\).*$/-D1rTY-\1/')" + fi + echo $_status + else + echo + fi +} + +__normal_user () +{ + if [ -e /etc/login.defs ] + then + eval `grep -v '^[$#]' /etc/login.defs | grep "^UID_" | tr -d '[:blank:]' | sed 's/^[A-Z_]\+/&=/'` + [ \( $UID -ge $UID_MIN \) ] + else + [ "`whoami`" != "root" ] + fi +} + +__privileged_user () +{ + ! __normal_user +} + + diff --git a/02_Functions.zsh b/02_Functions.zsh new file mode 100644 index 0000000..015d277 --- /dev/null +++ b/02_Functions.zsh @@ -0,0 +1,63 @@ +## +## Part of configuration files for Zsh4 +## AUTHOR: Hugues Hiegel +## +## You are encouraged to use, modify, and redistribute +## these files with or without this notice. +## +## NO WARRANTY PROVIDED, USE AT YOUR OWN RISKS +## + +__cmd_exists git && \ +git () { + GIT=$(which -p git) + case $1 in + init|clone|config) + ;; + *) + if [ "$( ( $GIT ls-files ; $GIT ls-tree HEAD . ) 2>&- | head -n1)" = ""\ + -a \( ! -d .git -o "$($GIT rev-parse --git-dir 2>&-)" != ".git" \)\ + -a "$($GIT rev-parse --is-inside-git-dir 2>&-)" != "true" ] + then + echo >&2 "git $1: the current folder is not managed by git" + return + fi + ;; + esac + + $(which -p git) $@ +} + +__cmd_exists when && \ +when() +{ + TODAY_FILE=~/.when/.today + + $(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/^/ /' +} + +__cmd_exists todo && \ +todo() +{ + 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/^/ /' +} + diff --git a/10_Environment.zsh b/10_Environment.zsh index 8ecc892..083fbf4 100644 --- a/10_Environment.zsh +++ b/10_Environment.zsh @@ -13,7 +13,7 @@ ## ## ma politique pour l'export des variables est très simple : ## si elle a pour vocation d'être utilisée en dehors de Zsh, -## on l'exporte. SInon pas. +## on l'exporte. Sinon pas. ## export SHELL=`which zsh` @@ -42,14 +42,14 @@ _tx_=${${has_termcaps:+"x"}:-"|"} # I hate kik00l0l colorized prompts, so I'm using a way to # give a dominant color for each part of the prompt, each of # these remain still configurable one by one. -# Take a look to set_prompt_colors for these colorizations. +# Take a look to _set_prompt_colors (01_Internals) for these colorizations. # # To set the dominant color I'm using this : # # - PS1_ROOT when we are root # - PS1_USER for normal usage # -# I'm storing the resulting dominant color in $prompt_colors[generic] +# I'm storing the resulting dominant color in $_prompt_colors[generic] PS1_ROOT=${PS1_ROOT:-$color[red]} PS1_USER=${PS1_USER:-$color[blue]} @@ -90,17 +90,17 @@ export GPG_TTY=`tty` # YeahConsole.. if ( ps x | grep $$ -B1 | grep -q yeahconsole ) then - YEAHCONSOLE=true + _yeahconsole=true fi # Display guess -CURRENT_DISPLAY=$(finger 2>&- | tail -n+2 | grep -E $USER'[[:blank:]]+.*[[:blank:]]+tty[0-9][[:blank:]]+($DISPLAY)' | head -n1 | cut -d'(' -f2 | cut -d')' -f1) -if [ "$DISPLAY" = "" -a "$CURRENT_DISPLAY" = "" ] +_current_display=$(finger 2>&- | tail -n+2 | grep -E $USER'[[:blank:]]+.*[[:blank:]]+tty[0-9][[:blank:]]+($DISPLAY)' | head -n1 | cut -d'(' -f2 | cut -d')' -f1) +if [ "$DISPLAY" = "" -a "$_current_display" = "" ] then - GUESS_DISPLAY=$(finger 2>&- | tail -n+2 | grep -E $USER'[[:blank:]]+.*[[:blank:]]+tty[0-9]' | head -n1 | cut -d'(' -f2 | cut -d')' -f1) - if [ "$GUESS_DISPLAY" != "" ] + _guess_display=$(finger 2>&- | tail -n+2 | grep -E $USER'[[:blank:]]+.*[[:blank:]]+tty[0-9]' | head -n1 | cut -d'(' -f2 | cut -d')' -f1) + if [ "$_guess_display" != "" ] then - export DISPLAY=$GUESS_DISPLAY + export DISPLAY=$_guess_display else unset DISPLAY fi diff --git a/11_Colors.zsh b/11_Colors.zsh index e194665..8afc82b 100644 --- a/11_Colors.zsh +++ b/11_Colors.zsh @@ -7,8 +7,76 @@ ## You are encouraged to use, modify, and redistribute ## these files with or without this notice. ## -typeset -A prompt_colors git_colors mail_colors correct_colors battery_colors date_colors agent_colors guilt_colors -correct_colors[error]="$color[red];$color[bold]" -correct_colors[suggest]="$color[blue];$color[bold]" +typeset -A _prompt_colors _git_colors _mail_colors _correct_colors _battery_colors _date_colors _agent_colors _guilt_colors + +_correct_colors[error]="$color[red];$color[bold]" +_correct_colors[suggest]="$color[blue];$color[bold]" + +# This func is intended to give a quick way to reset the colors +# from a running zsh-session +# +set_prompt_colors () +{ + local my_generic + # Get the generic color from cmdline, else from envvar... + my_generic=${1:-$_prompt_colors[generic]} + # ...then stores it to envvar. :) + _prompt_colors[generic]=$my_generic + + # Get soft and bold values of generic color, whichever it is bold or not + _prompt_colors[bold_generic]="$(echo "$_prompt_colors[generic]" | tr ';' '\n' | grep -v "^$color[bold]$" | tr '\n' ';' | sed 's/\;$//');$color[bold]" + _prompt_colors[soft_generic]="$(echo "$_prompt_colors[generic]" | tr ';' '\n' | grep -v "^$color[bold]$" | tr '\n' ';' | sed 's/\;$//')" + + _prompt_colors[path]="$_prompt_colors[generic];$color[bold]" # pwd - bold generic + #_prompt_colors[term]="$_prompt_colors[generic]" # tty - unused, see term title + _prompt_colors[user]="$_prompt_colors[generic]" # login - generic + _prompt_colors[host]="$_prompt_colors[generic]" # hostname - generic + _prompt_colors[display]="$_prompt_colors[generic]" # hostname - generic + #_prompt_colors[hist]="$color[none]" # history number - unused + _prompt_colors[arob]="$color[bold];$_prompt_colors[generic]" # @ - bold generic + _prompt_colors[dies]="$_prompt_colors[generic]" # the bottom-end of the prompt - generic + _prompt_colors[doubledot]="$color[none]" # separates pwd from git-branch - none + #_prompt_colors[paren]="$color[cyan]" # parenthesis (around tty) - unused, see term title + _prompt_colors[bar]="$_prompt_colors[generic];$color[bold]" # horizontal bar - bold generic + _prompt_colors[braces]="$_prompt_colors[bar]" # braces (around date) - bar color + _prompt_colors[error]="$color[bold];$color[yellow]" # error code - bold yellow + + _prompt_colors[warning]="$color[bold];$color[yellow]" + + _date_colors[normal]=$_prompt_colors[soft_generic] + _date_colors[exec]=$_prompt_colors[bold_generic] + _prompt_colors[date]=$_date_colors[normal] # full date + + _prompt_colors[cmd]="$color[none]" # command prompt + _prompt_colors[exec]="$color[none]" # command output + + _battery_colors[full]="$_prompt_colors[soft_generic]" + _battery_colors[charging]="$_prompt_colors[bold_generic]" + _battery_colors[uncharging]="$_prompt_colors[soft_generic]" + _battery_colors[critical]="$color[bg-red];$_prompt_colors[bold_generic]" + + _mail_colors[unread]="$color[yellow];$color[bold]" # mail received + _mail_colors[listes]="$_prompt_colors[generic];$color[bold]" # less important mail received + + _agent_colors[empty]="$_prompt_colors[soft_generic]" + _agent_colors[remote_empty]="$color[bold];$color[black]" + _agent_colors[has_keys]="$color[bold];$color[yellow]" + _agent_colors[has_remote_keys]="$_prompt_colors[bold_generic]" + + _prompt_colors[up_to_date]="$_prompt_colors[generic]" # up-to-date + _prompt_colors[not_up_to_date]="$color[green];$color[bold]" # not up to date + _prompt_colors[to_be_commited]="$color[yellow];$color[bold]" # changes in cache + + _git_colors[managment_folder]="$color[red];$color[bold]" # .git/... folder browsing + _git_colors[cached]="$_prompt_colors[to_be_commited]" # git changes in cache + _git_colors[cached_and_not_up_to_date]="$_prompt_colors[not_up_to_date];$color[bold]" + _git_colors[not_up_to_date]="$_prompt_colors[not_up_to_date];$color[normal]" # git changes in working tree + _git_colors[init_in_progress]="$color[black];$color[bold]" # initialization + _git_colors[up_to_date]="$_prompt_colors[up_to_date];$color[normal]" # git up-to-date + + _guilt_colors[applied]=$_git_colors[cached] + _guilt_colors[unapplied]=$color[black] +} + diff --git a/12_Prompts.zsh b/12_Prompts.zsh index d322e05..a9fe07b 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -8,14 +8,15 @@ ## these files with or without this notice. ## -prompt_colors[generic]=${PS1_USER:-} -if privileged_user +_prompt_colors[generic]=${PS1_USER:-} + +if __privileged_user then - prompt_colors[generic]=${PS1_ROOT:-$color[bold];$color[red]} + _prompt_colors[generic]=${PS1_ROOT:-$color[bold];$color[red]} fi -if [ "$YEAHCONSOLE" = "true" ] +if [ "$_yeahconsole" = "true" ] then - prompt_colors[generic]=${PS1_YEAH} + _prompt_colors[generic]=${PS1_YEAH} fi set_prompt_colors @@ -32,7 +33,19 @@ set_prompt_colors # precmd : avant d'afficher le prompt # -expand_text() +chpwd() +{ + + __cmd_exists todo && todo + + if ( __cmd_exists git && test -d .git ) + then + # Shows tracked branches and modified files + git checkout HEAD 2>&1 | sed 's/^/ /' + fi +} + +__expand_text() { # strips the %{...%} and newlines characters print -Pn -- "$(echo $@ | tr -d '\n' | sed 's/%{[^(%})]*%}//g;s/'$T_'//g;s/'$_T'//g')" @@ -40,11 +53,11 @@ expand_text() preexec () { - term_title "$(echo $1 | tr ' \n' ' ;' | sed 's/%/%%/g;s/\\/\\\\/g;s/;$//')" + __term_title "$(echo $1 | tr ' \n' ' ;' | sed 's/%/%%/g;s/\\/\\\\/g;s/;$//')" - prompt_colors[date]=$date_colors[exec] - set_prompt_date "-" - prompt_colors[date]=$date_colors[normal] + _prompt_colors[date]=$_date_colors[exec] + __set_prompt_date "-" + _prompt_colors[date]=$_date_colors[normal] spaceleft=$(($COLUMNS - $AGENTSSIZE - $STLINUXSIZE - $DATESIZE - $BATTERYSIZE)) unset HBAR @@ -54,44 +67,44 @@ preexec () HBAR=${HBAR}$_tq_ done HBAR=$HBAR$_T - redefine_prompt + __redefine_prompt - local lines="$(($(expand_text "$PROMPT$1" | sed "s/\\(.\{0,$COLUMNS\}\\)/\\1\\n/g" | wc -l)))" + local lines="$(($(__expand_text "$PROMPT$1" | sed "s/\\(.\{0,$COLUMNS\}\\)/\\1\\n/g" | wc -l)))" for i in {1..$lines} ; print -Pn "\e[1A\e[2K" print -Pn "\r$PROMPT" print -Pn "$C_$color[cyan]$_C" print "${(q)1}" | sed "s/'$//;s/^'//" - print -Pn "$C_$prompt_colors[exec]$_C" + print -Pn "$C_$_prompt_colors[exec]$_C" } -set_prompt_date() +__set_prompt_date() { begin=${${1:+$_tj_}:-$_tk_} end=${${1:+$_tm_}:-$_tl_} # Date [ "$DEBUG" = "yes" ] && echo -n " Date..." - DATE=$C_$prompt_colors[braces]$_C$T_"${begin}"$_T" "$C_$prompt_colors[date]$_C"%D{%a-%d-%b-%Y %H:%M:%S}"$C_$prompt_colors[braces]$_C" "$C_$prompt_colors[bar]$_C$T_"${end}$_tq_"$_T - DATEEXPAND=$(expand_text "$DATE") + DATE=$C_$_prompt_colors[braces]$_C$T_"${begin}"$_T" "$C_$_prompt_colors[date]$_C"%D{%a-%d-%b-%Y %H:%M:%S}"$C_$_prompt_colors[braces]$_C" "$C_$_prompt_colors[bar]$_C$T_"${end}$_tq_"$_T + DATEEXPAND=$(__expand_text "$DATE") DATESIZE=${#DATEEXPAND} [ "$DEBUG" = "yes" ] && echo } -update_prompt_elements() +__update_prompt_elements() { # Error [ "$DEBUG" = "yes" ] && echo -n " Error code..." ERRORSIZE=${#error} - ERROR="%(?;;"$C_$prompt_colors[bar]$_C$T_"$_tq_"$_T$C_$prompt_colors[error]$_C"%?)" + error="%(?;;"$C_$_prompt_colors[bar]$_C$T_"$_tq_"$_T$C_$_prompt_colors[error]$_C"%?)" [ "$DEBUG" = "yes" ] && echo [ "$DEBUG" = "yes" ] && echo -n " Term title..." # Flush the term title - term_title + __term_title [ "$DEBUG" = "yes" ] && echo - set_prompt_date + __set_prompt_date [ "$DEBUG" = "yes" ] && echo -n " Agents..." # GPG/SSH agents @@ -135,7 +148,7 @@ update_prompt_elements() fi fi - AGENTS=$C_$agent_colors[$AGENTCOLOR]$_C"$AGENTCHAR" + AGENTS=$C_$_agent_colors[$AGENTCOLOR]$_C"$AGENTCHAR" fi [ "$DEBUG" = "yes" ] && echo && echo -n " ......GPG" @@ -145,11 +158,11 @@ update_prompt_elements() if [ "`strings /proc/$GPG_AGENT_PID/cmdline | head -n1`" = "gpg-agent" ] then AGENTCOLOR="has_keys" - AGENTS=$AGENTS$C_$agent_colors[$AGENTCOLOR]$_C${GPG_AGENT_RUNNING:-$( [ $_is_multibyte_compliant ] && echo "⚡" || echo "G" )} + AGENTS=$AGENTS$C_$_agent_colors[$AGENTCOLOR]$_C${GPG_AGENT_RUNNING:-$( [ $_is_multibyte_compliant ] && echo "⚡" || echo "G" )} fi fi - AGENTS=${AGENTS:+$C_$prompt_colors[bar]$_C$T_"$_tq_"$_T$AGENTS} - AGENTSSIZE=$(expand_text $AGENTS) + AGENTS=${AGENTS:+$C_$_prompt_colors[bar]$_C$T_"$_tq_"$_T$AGENTS} + AGENTSSIZE=$(__expand_text $AGENTS) AGENTSSIZE=$#AGENTSSIZE [ "$DEBUG" = "yes" ] && echo @@ -196,8 +209,8 @@ update_prompt_elements() battery[color]="uncharging" fi fi - BATTERY=$C_$prompt_colors[bar]$_C$T_"$_tq_"$_T$C_$battery_colors[$battery[color]]$_C"$battery[remains]" - unset battery + BATTERY=$C_$_prompt_colors[bar]$_C$T_"$_tq_"$_T$C_$_battery_colors[$battery[color]]$_C"$battery[remains]" + unset BATTERY [ "$DEBUG" = "yes" ] && echo else @@ -228,7 +241,7 @@ update_prompt_elements() if [ -d CVS ] then CVSTAG=$(test -e CVS/Tag && cat CVS/Tag || basename $(cat CVS/Root 2>&- || echo "HEAD") ) - CVSTAG=${CVSTAG:+ $C_$prompt_colors[up_to_date]$_C$CVSTAG} + CVSTAG=${CVSTAG:+ $C_$_prompt_colors[up_to_date]$_C$CVSTAG} fi # get svn status @@ -241,22 +254,22 @@ update_prompt_elements() if [ ! -z "$CHECK_SVN_STATUS" ] then SVNSTATUS="$(svn diff 2>&-)" - SVNSTATUS=${${SVNSTATUS:+$prompt_colors[not_up_to_date]}:-$prompt_colors[up_to_date]} + SVNSTATUS=${${SVNSTATUS:+$_prompt_colors[not_up_to_date]}:-$_prompt_colors[up_to_date]} fi fi - SVNREV=${SVNREV:+$C_$prompt_colors[doubledot]$_C $C_$SVNSTATUS$_C"r"$SVNREV} + SVNREV=${SVNREV:+$C_$_prompt_colors[doubledot]$_C $C_$SVNSTATUS$_C"r"$SVNREV} [ "$DEBUG" = "yes" ] && echo # get hg status [ "$DEBUG" = "yes" ] && echo -n " HG status..." - HGBRANCH=$(get_gcl_branch hg) + HGBRANCH=$(__get_gcl_branch hg) [ ! -z "$HGBRANCH" ] && HGBRANCH=" "$HGBRANCH [ "$DEBUG" = "yes" ] && echo # get git status # [ "$DEBUG" = "yes" ] && echo -n " GIT status..." - GITBRANCH=$(get_gcl_branch git) + GITBRANCH=$(__get_gcl_branch git) GITBRANCHSIZE=${#GITBRANCH} [ $GITBRANCHSIZE -gt 0 ] && GITBRANCHSIZE=$(($GITBRANCHSIZE)) [ "$DEBUG" = "yes" ] && echo @@ -267,7 +280,7 @@ update_prompt_elements() PATHSIZE=${#PATHSIZE} [ "$DEBUG" = "yes" ] && echo [ "$DEBUG" = "yes" ] && echo -n " Resize path / gitbranch..." - spaceleft=`print -Pn "$SHLVL - %n@%m $ ls -laCdtrux $(expand_text "$DATE")"` + spaceleft=`print -Pn "$SHLVL - %n@%m $ ls -laCdtrux $(__expand_text "$DATE")"` spaceleft=$(($COLUMNS - ${#spaceleft})) #minimalpathsize=`print -Pn "../%1~"` #minimalpathsize=${#minimalpathsize} @@ -305,43 +318,43 @@ update_prompt_elements() # then we reduce the path until it reaches the last path element, spaceleft=$(($spaceleft - $GITBRANCHSIZE)) [ $spaceleft -lt $minimalpathsize ] && spaceleft=$minimalpathsize - GITBRANCH=${GITBRANCH:+ $C_"$(get_git_status)"$_C$GITBRANCH}"$(get_guilt_series)" - CURDIR="$C_$prompt_colors[path]$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$color[none]$_C" + GITBRANCH=${GITBRANCH:+ $C_"$(__get_git_status)"$_C$GITBRANCH}"$(__get_guilt_series)" + CURDIR="$C_$_prompt_colors[path]$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$color[none]$_C" [ "$DEBUG" = "yes" ] && echo } -redefine_prompt () +__redefine_prompt () { - case "$YEAHCONSOLE" in + case "$_yeahconsole" in "true") - yeah_prompt + __yeah_prompt ;; *) - two_lines_prompt + __two_lines_prompt ;; esac } -yeah_prompt () +__yeah_prompt () { - PS1=$C_$prompt_color[default]$_C$C_$prompt_colors[user]$_C"%n"$C_$prompt_colors[arob]$_C"@"$C_$prompt_colors[host]$_C"%m "$CURDIR" "$C_$prompt_colors[dies]$_C">"$C_$prompt_colors[cmd]$_C" " + PS1=$C_$prompt_color[default]$_C$C_$_prompt_colors[user]$_C"%n"$C_$_prompt_colors[arob]$_C"@"$C_$_prompt_colors[host]$_C"%m "$CURDIR" "$C_$_prompt_colors[dies]$_C">"$C_$_prompt_colors[cmd]$_C" " } -two_lines_prompt () +__two_lines_prompt () { ## Le prompt le plus magnifique du monde, et c'est le mien ! # Affiche l'user, l'host, le tty et le pwd. Rien que ça... - PS1=$AGENTS$MAILSTAT$ERROR$BATTERY$C_$prompt_colors[bar]$_C$STLINUX$HBAR$DATE" -"$C_$prompt_color[default]$_C$C_$prompt_colors[user]$_C"%n"$C_$prompt_colors[arob]$_C"@"$C_$prompt_colors[host]$_C"%m"$C_$prompt_colors[display]$_C"${DISPLAY:+($DISPLAY)} "$CURDIR$CVSTAG$SVNREV$GITBRANCH$HGBRANCH" "$C_$prompt_colors[dies]$_C"%#"$C_$prompt_colors[cmd]$_C" " + PS1=$AGENTS$MAILSTAT$ERROR$BATTERY$C_$_prompt_colors[bar]$_C$STLINUX$HBAR$DATE" +"$C_$prompt_color[default]$_C$C_$_prompt_colors[user]$_C"%n"$C_$_prompt_colors[arob]$_C"@"$C_$_prompt_colors[host]$_C"%M"$C_$_prompt_colors[display]$_C"${DISPLAY:+($DISPLAY)} "$CURDIR$CVSTAG$SVNREV$GITBRANCH$HGBRANCH" "$C_$_prompt_colors[dies]$_C"%#"$C_$_prompt_colors[cmd]$_C" " } -ZSH_STATUS=$(zsh_status) +ZSH_STATUS=$(__zsh_status) if ( echo $ZSH_STATUS | grep -q -- "-D1rTY-" ) then set_prompt_colors "38;5;54" echo - echo -n $c_$prompt_colors[warning]$_c + echo -n $c_$_prompt_colors[warning]$_c #toilet -f bigmono9 "D1rTY Zsh.." HBAR=$(for i in {1..13} ; echo -n - "$_tq_") @@ -360,7 +373,7 @@ then echo -n $HBAR echo -n $_tj_$_T echo - echo $c_$prompt_colors[none]$_c + echo $c_$_prompt_colors[none]$_c fi precmd() @@ -368,8 +381,8 @@ precmd() # this MUST BE the real first operation else we lose the error code... error=$(print -Pn "%(?;;-%?)") - update_prompt_elements - redefine_prompt + __update_prompt_elements + __redefine_prompt } @@ -383,8 +396,8 @@ PS3="?# " PS4="+%N:%i> " # Prompt de droite, pour l'heure et le code d'erreur de la dernière commande -#RPS1="%(?;;"$C_$prompt_colors[error]$_C"%?"$C_$color[none]$_C")" +#RPS1="%(?;;"$C_$_prompt_colors[error]$_C"%?"$C_$color[none]$_C")" # Ultime : prompt de correction :-) -SPROMPT="zsh: $C_$correct_colors[error]$_C'%R'$C_$color[none]$_C ? Vous ne vouliez pas plutôt $C_$correct_colors[suggest]$_C'%r'$C_$color[none]$_C ? [%BN%byae] " +SPROMPT="zsh: $C_$_correct_colors[error]$_C'%r'$C_$color[none]$_C ? Vous ne vouliez pas plutôt $C_$_correct_colors[suggest]$_C'%r'$C_$color[none]$_C ? [%BN%byae] " diff --git a/99_Exec.zsh b/99_Exec.zsh index 07de20b..2a996a1 100644 --- a/99_Exec.zsh +++ b/99_Exec.zsh @@ -8,7 +8,7 @@ ## these files with or without this notice. ## -if cmd_exists fortune +if __cmd_exists fortune then preprint "Pensée du jour" && echo fortune fr | fmt -s -w 74 diff --git a/net:foret/Prompts.zsh b/net:foret/Prompts.zsh index b04648a..c07da1f 100644 --- a/net:foret/Prompts.zsh +++ b/net:foret/Prompts.zsh @@ -8,11 +8,11 @@ ## NO WARRANTY PROVIDED, USE AT YOUR OWN RISKS ## -two_lines_prompt () +__two_lines_prompt () { ## Le prompt le plus magnifique du monde, et c'est le mien ! # Affiche l'user, l'host, le tty et le pwd. Rien que ça... - PS1=$AGENTS$MAILSTAT$ERROR$BATTERY$C_$prompt_colors[bar]$_C$STLINUX$HBAR$DATE" -"$C_$prompt_color[default]$_C$C_$prompt_colors[user]$_C"%n"$C_$prompt_colors[arob]$_C"@"$C_$prompt_colors[host]$_C"%m"$C_$prompt_colors[display]$_C"${DISPLAY:+($DISPLAY)} "$CURDIR$CVSTAG$SVNREV$GITBRANCH$HGBRANCH" "$C_$prompt_colors[soft_generic]$_C${TARGET:+[}$C_$prompt_colors[bold_generic]$_C${TARGET:+$TARGET}$C_$prompt_colors[soft_generic]$_C${TARGET:+] }$C_$prompt_colors[dies]$_C"%#"$C_$prompt_colors[cmd]$_C" " + PS1=$AGENTS$MAILSTAT$ERROR$BATTERY$C_$_prompt_colors[bar]$_C$STLINUX$HBAR$DATE" +"$C_$prompt_color[default]$_C$C_$_prompt_colors[user]$_C"%n"$C_$_prompt_colors[arob]$_C"@"$C_$_prompt_colors[host]$_C"%m"$C_$_prompt_colors[display]$_C"${DISPLAY:+($DISPLAY)} "$CURDIR$CVSTAG$SVNREV$GITBRANCH$HGBRANCH" "$C_$_prompt_colors[soft_generic]$_C${TARGET:+[}$C_$_prompt_colors[bold_generic]$_C${TARGET:+$TARGET}$C_$_prompt_colors[soft_generic]$_C${TARGET:+] }$C_$_prompt_colors[dies]$_C"%#"$C_$_prompt_colors[cmd]$_C" " } diff --git a/net:sweethome/Aliases.zsh b/net:sweethome/Aliases.zsh index 3da4c70..836721d 100644 --- a/net:sweethome/Aliases.zsh +++ b/net:sweethome/Aliases.zsh @@ -10,7 +10,7 @@ ## Paranoid specifics aliases -#cmd_exists mailstat && a maillogs='mailstat -mo ~/.procmail/procmail.log | cut -c8- | sed "s:^[0-9]*::"' -#cmd_exists mailstat && a mailstats='echo ; echo "\tToday" ; awk < ~/.procmail/procmail.log{,.old} "BEGIN {RS=\"From\"} /`LC_ALL=C date "+%a %b %d ..:..:.. %Y"`/ { print \"From \"\$0 }" | grep -v "^$" | mailstat | cut -c8- | sed "s:^[0-9]*::"' -#cmd_exists mailstat && a mails='mailstat -km ~/.procmail/procmail.log | sed "s/^No mail.*/ No mail/" | cut -c8- | sed "s:^[0-9]*::" | egrep -v "## .*:" ; cat ~/.procmail/procmail.log >> ~/.procmail/procmail.log.old ; :> ~/.procmail/procmail.log' -cmd_exists mutt && a junkmail='[ -f ~/Mail/junk.gz ] && mutt -f ~/Mail/junk.gz' +#__cmd_exists mailstat && a maillogs='mailstat -mo ~/.procmail/procmail.log | cut -c8- | sed "s:^[0-9]*::"' +#__cmd_exists mailstat && a mailstats='echo ; echo "\tToday" ; awk < ~/.procmail/procmail.log{,.old} "BEGIN {RS=\"From\"} /`LC_ALL=C date "+%a %b %d ..:..:.. %Y"`/ { print \"From \"\$0 }" | grep -v "^$" | mailstat | cut -c8- | sed "s:^[0-9]*::"' +#__cmd_exists mailstat && a mails='mailstat -km ~/.procmail/procmail.log | sed "s/^No mail.*/ No mail/" | cut -c8- | sed "s:^[0-9]*::" | egrep -v "## .*:" ; cat ~/.procmail/procmail.log >> ~/.procmail/procmail.log.old ; :> ~/.procmail/procmail.log' +__cmd_exists mutt && a junkmail='[ -f ~/Mail/junk.gz ] && mutt -f ~/Mail/junk.gz' diff --git a/user:hugues/Aliases.zsh b/user:hugues/Aliases.zsh index a988add..dffb0a7 100644 --- a/user:hugues/Aliases.zsh +++ b/user:hugues/Aliases.zsh @@ -18,23 +18,23 @@ a -g .......=../../../../../.. a -g ........=../../../../../../.. a -g .........=../../../../../../../.. -cmd_exists emacsclient && a e='emacsclient' -cmd_exists emacs && a ne='emacs -nw' +__cmd_exists emacsclient && a e='emacsclient' +__cmd_exists emacs && a ne='emacs -nw' -if ( cmd_exists vim ) +if ( __cmd_exists vim ) then a v='vim' if ( vim --version | grep -- "+clientserver" >/dev/null ) then - if ( cmd_exists vims ) + if ( __cmd_exists vims ) then a vim='vim --servername `print -P "%l"`' fi fi fi -cmd_exists eject && a close='eject -t' +__cmd_exists eject && a close='eject -t' a goto='cd -P' ## Resolve symlinks @@ -44,9 +44,9 @@ a cp && una cp ## Dé-assigne les alias de ``cp'' autoload zmv a mmv='noglob zmv -W' -normal_user && cmd_exists apt-get && a apt-get='sudo apt-get' -normal_user && cmd_exists pacman && a pacman='sudo pacman' -normal_user && cmd_exists yum && a yum='sudo yum' +__normal_user && __cmd_exists apt-get && a apt-get='sudo apt-get' +__normal_user && __cmd_exists pacman && a pacman='sudo pacman' +__normal_user && __cmd_exists yum && a yum='sudo yum' a _rt='find -maxdepth 1 -type f \( -name "*~" -o -name ".*~" -o -name "#*#" -o -name ".*.swp" \) -exec rm -vf \{\} \;' a _RT='find -type f \( -name "*~" -o -name ".*~" -o -name "#*#" -o -name ".*.swp" \) -exec rm -vf \{\} \;' @@ -70,17 +70,17 @@ a lat='la -tr' a lc='ls -c' a lc1='\ls -c1' -cmd_exists dict && a definition='dict -h dict.org' -cmd_exists dict && a traduction='dict -h hiegel.fr -P-' +__cmd_exists dict && a definition='dict -h dict.org' +__cmd_exists dict && a traduction='dict -h hiegel.fr -P-' -cmd_exists dosbox && a dosbox='dosbox -c "mount c \"`pwd`\"" -c "mount d /cdrom -t cdrom" -c "c:" ' -cmd_exists emacs && a gnus='emacs -f gnus' +__cmd_exists dosbox && a dosbox='dosbox -c "mount c \"`pwd`\"" -c "mount d /cdrom -t cdrom" -c "c:" ' +__cmd_exists emacs && a gnus='emacs -f gnus' #a make='make -j' ## Suffixes Aliases # I don't like this, I never used it. # -cmd_exists editdiff && a -s patch=editdiff +__cmd_exists editdiff && a -s patch=editdiff a -s c=$EDITOR a -s h=$EDITOR diff --git a/user:hugues/Environment.zsh b/user:hugues/Environment.zsh index bfb341d..486e135 100644 --- a/user:hugues/Environment.zsh +++ b/user:hugues/Environment.zsh @@ -49,7 +49,7 @@ done export GREP_COLOR=$color[yellow]\;$color[bold] export GREP_COLORS="sl="":cx="$color[cyan]":ms="$color[yellow]";"$color[bold]":mc="$color[red]";"$color[bold]"" -cmd_exists dircolors && eval $(dircolors ~/.dir_colors) +__cmd_exists dircolors && eval $(dircolors ~/.dir_colors) export TZ="Europe/Paris" export TIME_STYLE="+%Y-%b-%d %H:%M:%S" diff --git a/user:hugues/KeyBindings.zsh b/user:hugues/KeyBindings.zsh index ff23dac..43e75d0 100644 --- a/user:hugues/KeyBindings.zsh +++ b/user:hugues/KeyBindings.zsh @@ -201,10 +201,10 @@ do bindkey -M $keymap -s 'r' 'Q rehash\n' bindkey -M $keymap -s 'R' 'Q reset\n' - cmd_exists when && \ + __cmd_exists when && \ bindkey -M $keymap -s 'w' 'Q when\n' - cmd_exists todo && ( + __cmd_exists todo && ( bindkey -M $keymap -s 't' 'Q todo\n' bindkey -M $keymap -s 'T' 'Q todo all -c\n' ) -- cgit v1.2.3