X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=bashrc;h=9fccbbb481bab06fd00174a28bdb1fc62a8157a8;hb=a5db382ceaaa972250509f4c1f1f8831cf8e09ed;hp=d3b4a7662d3366f2d4107781654b881d1b526d62;hpb=33f978f402c0b4138fab453d94c4eab6ff6a523c;p=max%2Fdotfiles.git diff --git a/bashrc b/bashrc index d3b4a76..9fccbbb 100644 --- a/bashrc +++ b/bashrc @@ -4,8 +4,8 @@ # If not running interactively, don't do anything case $- in - *i*) ;; - *) return;; + *i*) ;; + *) return;; esac # don't put duplicate lines or lines starting with space in the history. @@ -23,84 +23,25 @@ HISTFILESIZE=2000 # update the values of LINES and COLUMNS. shopt -s checkwinsize -# If set, the pattern "**" used in a pathname expansion context will -# match all files and zero or more directories and subdirectories. -#shopt -s globstar - # make less more friendly for non-text input files, see lesspipe(1) -#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" +[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" # set variable identifying the chroot you work in (used in the prompt below) if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) + debian_chroot=$(cat /etc/debian_chroot) fi -# set a fancy prompt (non-color, unless we know we "want" color) -case "$TERM" in - xterm-color) color_prompt=yes;; -esac - -# uncomment for a colored prompt, if the terminal has the capability; turned -# off by default to not distract the user: the focus in a terminal window -# should be on the output of commands, not on the prompt -force_color_prompt=yes - -if [ -n "$force_color_prompt" ]; then - if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - color_prompt=yes - else - color_prompt= - fi -fi - -if [ "$color_prompt" = yes ]; then - PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' -else - PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -fi -unset color_prompt force_color_prompt - -# If this is an xterm set the title to user@host:dir -case "$TERM" in -xterm*|rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; -*) - ;; -esac - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - alias dir='dir --color=auto' - alias vdir='vdir --color=auto' - - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' -fi # colored GCC warnings and errors export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' -# some more ls aliases -#alias ll='ls -l' -alias la='ls -lA' -#alias l='ls -CF' - -# Alias definitions. -# You may want to put all your additions into a separate file like -# ~/.bash_aliases, instead of adding them here directly. -# See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then - . ~/.bash_aliases + . ~/.bash_aliases fi +eval `dircolors ~/.dir_colors` + # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). @@ -121,3 +62,64 @@ n() { nls() { ls -cR ~/notes/ | grep "$*" } + + +Green=$(tput setaf 64) +Red=$(tput setaf 160) +Yellow=$(tput setaf 136) +Purple=$(tput setaf 61) +BGreen=$Green$(tput bold) +BRed=$Red$(tput bold) +BYellow=$Yellow$(tput bold) +BPurple=$Purple$(tput bold) + +Color_Off=$(tput sgr0) + +# set up command prompt +function __prompt_command() +{ + # capture the exit status of the last command + EXIT="$?" + PS1="" + + if [ $EXIT -eq 0 ]; then PS1+="\[$Green\][\!]\[$Color_Off\] "; else PS1+="\[$Red\][\!]\[$Color_Off\] "; fi + + # if logged in via ssh shows the ip of the client + if [ -n "$SSH_CLIENT" ]; then + IP=${SSH_CLIENT%% *} + PS1+="\[$Yellow\]("$IP")\[$Color_Off\]"; + fi + + # debian chroot stuff (take it or leave it) + PS1+="${debian_chroot:+($debian_chroot)}" + + # basic information (user@host:path) + PS1+="\[$BRed\]\u\[$Color_Off\]@\[$BRed\]\h\[$Color_Off\]:\[$BPurple\]\w\[$Color_Off\] " + + # check if inside git repo + local git_status="`git status -unormal 2>&1`" + if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then + # parse the porcelain output of git status + if [[ "$git_status" =~ nothing\ to\ commit ]]; then + local Color_On=$Green + elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then + local Color_On=$Purple + else + local Color_On=$Red + fi + + if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then + branch=${BASH_REMATCH[1]} + else + # Detached HEAD. (branch=HEAD is a faster alternative.) + branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null || echo HEAD`)" + fi + + # add the result to prompt + PS1+="\[$Color_On\][$branch]\[$Color_Off\] " + fi + + # prompt $ or # for root + PS1+="\$ " +} +PROMPT_COMMAND=__prompt_command