From 63d4b8c1fdba15944f6f2b82bbe0d4025e74e789 Mon Sep 17 00:00:00 2001 From: Martinez Date: Thu, 26 Feb 2015 22:01:11 +0100 Subject: [PATCH] removed bash-init, added simple git branch indicator --- bash-init | 78 ------------------------------------------------------- zsh-init | 24 +++++++++++++++-- 2 files changed, 22 insertions(+), 80 deletions(-) delete mode 100755 bash-init diff --git a/bash-init b/bash-init deleted file mode 100755 index 37e2f47..0000000 --- a/bash-init +++ /dev/null @@ -1,78 +0,0 @@ -#! /bin/bash -# *very* dirty, but this inferior excuse for a shell deserves nothing better - -OVER_PROMPT_CFG="/etc/over/prompt.cfg" - -if [ -a "$OVER_PROMPT_CFG" ]; then - source "$OVER_PROMPT_CFG" -fi - -function precmd() -{ - EXITUS=$? - RAW_DATA="$(/usr/share/over-prompt/data $OVER_PROMPT_OPTS)" - - if [ $EXITUS = 0 ]; then - CROSS="|CYAN|\\$|NONE|" - else - CROSS="|RED|${EXITUS}|NONE|:|RED|\\$|NONE|" - fi - if [ $EUID = 0 ]; then - USER_PART="|RED|\\u|NONE|" - else - USER_PART="|GREEN|\\u|NONE|" - fi - - home_len=${#HOME} - if [ "${PWD:0:$home_len}" = "$HOME" ]; then - pwd="~${PWD:$home_len}" - else - pwd="$PWD" - fi - - if [ -n "$RAW_DATA" ]; then - LOGIN_PART="${RAW_DATA%:::*}" - STATS_PART="[ ${RAW_DATA#*:::} " - - pwd_len=${#pwd} - user_len=${#USER} - host_len=${#HOSTNAME} - win_len=${#WINDOW} - STATS_PART_="$(echo ${STATS_PART}|sed 's/|[A-Z]*|//g')" - stats_len=${#STATS_PART_} - - max_pwd_len=$((${COLUMNS}-${user_len}-${host_len}-${win_len}-${stats_len}-5)) - - # 1 kB of spaces... that should be enough. DIRTY, YEAH! - spaces=" " - padding="" - if [ ${pwd_len} -gt ${max_pwd_len} ]; then - pwd="<${pwd:(($pwd_len - $max_pwd_len)):$pwd_len}" - elif [ ${pwd_len} -lt ${max_pwd_len} ]; then - padto=$((${max_pwd_len} - ${pwd_len} + 1)) - padding="${spaces:0:$padto}" - fi - - PS1="${USER_PART}@${LOGIN_PART} ${padding}${STATS_PART}\n$CROSS " - else - PS1="${USER_PART}@|HOST| |CWD| [|RFLASH|data gathering error|NONE|]\n$CROSS " - fi - - PS1="${PS1//|NONE|/\[\033[0m\]}" - PS1="${PS1//|RED|/\[\033[1;31m\]}" - PS1="${PS1//|RFLASH|/\[\033[5;31m\]}" - PS1="${PS1//|GREEN|/\[\033[1;32m\]}" - PS1="${PS1//|DARKGREEN|/\[\033[0;32m\]}" - PS1="${PS1//|BLUE|/\[\033[1;34m\]}" - PS1="${PS1//|YELLOW|/\[\033[1;33m\]}" - PS1="${PS1//|CYAN|/\[\033[1;36m\]}" - PS1="${PS1//|HOST|/$HOSTNAME}" - PS1="${PS1//|TTY|/$WINDOW}" - PS1="${PS1//|CWD|/$pwd}" - - unset -v LOGIN_PART STATS_PART pwd_len user_len host_len win_len STATS_PART_ stats_len max_pwd_len spaces padding pwd padto padding -} - -PROMPT_COMMAND="precmd" - -unset OVER_PROMPT_CFG diff --git a/zsh-init b/zsh-init index 60e9b37..f9c722c 100755 --- a/zsh-init +++ b/zsh-init @@ -16,14 +16,34 @@ function strlen { } function precmd { - local OVER_OPTS RAW_DATA LOGIN_PART STATS_PART DATA TOP_LEFT TOP_RIGHT PADDING PADDING_SIZE + local OVER_OPTS RAW_DATA LOGIN_PART STATS_PART DATA TOP_LEFT TOP_RIGHT PADDING PADDING_SIZE GIT_BRANCH COLOR set -A OVER_OPTS ${(s. .)OVER_PROMPT_OPTS} PS1="$(print "%(?.%{\e[1;36m%}.%{\e[1;31m%}%?%{\e[0m%}:%{\e[1;31m%})%(\!.#.$)%{\e[0m%} ")" RAW_DATA="$(/usr/share/over-prompt/data $OVER_OPTS[1] $OVER_OPTS[2] $OVER_OPTS[3])" - if [ -n "$RAW_DATA" ]; then + GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" + + if [[ -n "$GIT_BRANCH" ]]; then + # rebuild index + git update-index -q --ignore-submodules --refresh + + # so that I can check if there are unstaged changes + git diff-files --quiet --ignore-submodules + + if [[ $? -eq 0 ]]; then + COLOR="%{\e[1;32m%}" + else + COLOR="%{\e[1;31m%}" + fi + + RPS1="$(print "$COLOR$GIT_BRANCH%{\e[0m%}")" + else + unset RPS1 + fi + + if [[ -n "$RAW_DATA" ]]; then set -A DATA ${(s.:::.)RAW_DATA} LOGIN_PART=${DATA[1]} STATS_PART=${DATA[2]}