]> git.phdru.name Git - dotfiles.git/blobdiff - .bash_prompt
.shellrc: Check if file `bash_completion` exists
[dotfiles.git] / .bash_prompt
index 1d4f24535cddfce7d5297b73ca309a4728e0ecad..6126ef25240e8358dbb2ef4f25f09c420072f18c 100644 (file)
@@ -1,7 +1,8 @@
 #!/bin/bash
 
 # bash_prompt; adapted from
-# https://github.com/necolas/dotfiles/blob/master/shell/bash_prompt
+# https://github.com/necolas/dotfiles/blob/master/shell/bash_prompt and
+# http://vitus-wagner.livejournal.com/1176589.html?thread=40146189#t40146189
 
 prompt_git() {
     local s=""
@@ -136,34 +137,53 @@ set_prompts() {
         dim_yellow="\e[1;33m"
     fi
 
-    # build the prompt
+    charStyle="$reset$bold$black"
+    gitStyle="\[$white\]on \[$magenta\]"
+    case "$BACKGROUND" in
+       DARK|dark)
+          hostStyle="$reset$cyan"
+       ;;
+       LIGHT|light)
+          hostStyle="$reset$blue"
+       ;;
+    esac
+    wdirStyle="$reset$green"
+
 
     # logged in as root
     if [[ "$USER" == "root" ]]; then
-        userStyle="\[$bold$red\]"
+        userStyle="$bold$red"
     else
-        userStyle="\[$orange\]"
+        userStyle="$orange"
     fi
 
-    # connected via ssh
-    if [[ "$SSH_TTY" ]]; then
-        hostStyle="\[$bold$red\]"
-    else
-        hostStyle="\[$yellow\]"
-    fi
-
-    # set the terminal title to the current working directory
-    PS1="\[\033]0;\w\007\]"
-
-    PS1+="\n" # newline
+    # build the prompt
+    # display the user, host and current working directory in the terminal title
+    case "$TERM" in
+       *rxvt*|screen*|*term*|vt100)
+          PS1="\[\033]0;\u@\h:\w\007\]"
+          case "$TERM" in
+             screen*)
+                PS1+"\[\033k\u@\h:\w\033\\\]" # Set screen/tmux caption
+             ;;
+          esac
+       ;;
+
+       *)
+          PS1=""
+       ;;
+    esac
+
+    #PS1+="\n" # newline
     PS1+="\[$userStyle\]\u" # username
-    PS1+="\[$reset$white\]@"
-    PS1+="\[$hostStyle\]\h" # host
-    PS1+="\[$reset$white\]: "
-    PS1+="\[$green\]\w" # working directory
-    PS1+="\$(prompt_git \"$white on $cyan\")" # git repository details
-    PS1+="\n"
-    PS1+="\[$reset$white\]\$ \[$reset\]" # $ (and reset color)
+    PS1+="\[$charStyle\]@"
+    PS1+="\[$hostStyle\]\h " # host
+    #PS1+="\[$charStyle\]: "
+    PS1+="\[$wdirStyle\]\W " # working directory
+    PS1+='`erco=$?; [ $erco == 0 ] && echo -n ":)" || echo -n '"\"\[$red\]:(\[$reset\] $\""'?=$erco` '
+    PS1+="\$(prompt_git \"$gitStyle\")" # git repository details
+    #PS1+="\n"
+    PS1+="\[$charStyle\]\$ \[$reset\]" # $ (and reset color)
 
     export PS1
 }