├── lib ├── cowboy ├── mathiasbynens ├── paulirish └── thomasjbradley ├── package.json ├── prompt-so-fancy └── readme.md /lib/cowboy: -------------------------------------------------------------------------------- 1 | # My awesome bash prompt 2 | # 3 | # Copyright (c) 2012 "Cowboy" Ben Alman 4 | # Licensed under the MIT license. 5 | # http://benalman.com/about/license/ 6 | # 7 | # Example: 8 | # [master:!?][cowboy@CowBook:~/.dotfiles] 9 | # [11:14:45] $ 10 | # 11 | # Read more (and see a screenshot) in the "Prompt" section of 12 | # https://github.com/cowboy/dotfiles 13 | 14 | # ANSI CODES - SEPARATE MULTIPLE VALUES WITH ; 15 | # 16 | # 0 reset 4 underline 17 | # 1 bold 7 inverse 18 | # 19 | # FG BG COLOR FG BG COLOR 20 | # 30 40 black 34 44 blue 21 | # 31 41 red 35 45 magenta 22 | # 32 42 green 36 46 cyan 23 | # 33 43 yellow 37 47 white 24 | 25 | if [[ ! "${prompt_colors[@]}" ]]; then 26 | prompt_colors=( 27 | "36" # information color 28 | "37" # bracket color 29 | "31" # error color 30 | ) 31 | 32 | if [[ "$SSH_TTY" ]]; then 33 | # connected via ssh 34 | prompt_colors[0]="32" 35 | elif [[ "$USER" == "root" ]]; then 36 | # logged in as root 37 | prompt_colors[0]="35" 38 | fi 39 | fi 40 | 41 | # Inside a prompt function, run this alias to setup local $c0-$c9 color vars. 42 | alias prompt_getcolors='prompt_colors[9]=; local i; for i in ${!prompt_colors[@]}; do local c$i="\[\e[0;${prompt_colors[$i]}m\]"; done' 43 | 44 | # Exit code of previous command. 45 | function prompt_exitcode() { 46 | prompt_getcolors 47 | [[ $1 != 0 ]] && echo " $c2$1$c9" 48 | } 49 | 50 | # Git status. 51 | function prompt_git() { 52 | prompt_getcolors 53 | local status output flags branch 54 | status="$(git status 2>/dev/null)" 55 | [[ $? != 0 ]] && return; 56 | output="$(echo "$status" | awk '/# Initial commit/ {print "(init)"}')" 57 | [[ "$output" ]] || output="$(echo "$status" | awk '/# On branch/ {print $4}')" 58 | [[ "$output" ]] || output="$(git branch | perl -ne '/^\* \(detached from (.*)\)$/ ? print "($1)" : /^\* (.*)/ && print $1')" 59 | flags="$( 60 | echo "$status" | awk 'BEGIN {r=""} \ 61 | /^(# )?Changes to be committed:$/ {r=r "+"}\ 62 | /^(# )?Changes not staged for commit:$/ {r=r "!"}\ 63 | /^(# )?Untracked files:$/ {r=r "?"}\ 64 | END {print r}' 65 | )" 66 | if [[ "$flags" ]]; then 67 | output="$output$c1:$c0$flags" 68 | fi 69 | echo "$c1[$c0$output$c1]$c9" 70 | } 71 | 72 | # hg status. 73 | function prompt_hg() { 74 | prompt_getcolors 75 | local summary output bookmark flags 76 | summary="$(hg summary 2>/dev/null)" 77 | [[ $? != 0 ]] && return; 78 | output="$(echo "$summary" | awk '/branch:/ {print $2}')" 79 | bookmark="$(echo "$summary" | awk '/bookmarks:/ {print $2}')" 80 | flags="$( 81 | echo "$summary" | awk 'BEGIN {r="";a=""} \ 82 | /(modified)/ {r= "+"}\ 83 | /(unknown)/ {a= "?"}\ 84 | END {print r a}' 85 | )" 86 | output="$output:$bookmark" 87 | if [[ "$flags" ]]; then 88 | output="$output$c1:$c0$flags" 89 | fi 90 | echo "$c1[$c0$output$c1]$c9" 91 | } 92 | 93 | # SVN info. 94 | function prompt_svn() { 95 | prompt_getcolors 96 | local info="$(svn info . 2> /dev/null)" 97 | local last current 98 | if [[ "$info" ]]; then 99 | last="$(echo "$info" | awk '/Last Changed Rev:/ {print $4}')" 100 | current="$(echo "$info" | awk '/Revision:/ {print $2}')" 101 | echo "$c1[$c0$last$c1:$c0$current$c1]$c9" 102 | fi 103 | } 104 | 105 | # Maintain a per-execution call stack. 106 | prompt_stack=() 107 | trap 'prompt_stack=("${prompt_stack[@]}" "$BASH_COMMAND")' DEBUG 108 | 109 | function prompt_command() { 110 | local exit_code=$? 111 | # If the first command in the stack is prompt_command, no command was run. 112 | # Set exit_code to 0 and reset the stack. 113 | [[ "${prompt_stack[0]}" == "prompt_command" ]] && exit_code=0 114 | prompt_stack=() 115 | 116 | # Manually load z here, after $? is checked, to keep $? from being clobbered. 117 | [[ "$(type -t _z)" ]] && _z --add "$(pwd -P 2>/dev/null)" 2>/dev/null 118 | 119 | # While the simple_prompt environment var is set, disable the awesome prompt. 120 | [[ "$simple_prompt" ]] && PS1='\n$ ' && return 121 | 122 | prompt_getcolors 123 | # http://twitter.com/cowboy/status/150254030654939137 124 | PS1="\n" 125 | # svn: [repo:lastchanged] 126 | PS1="$PS1$(prompt_svn)" 127 | # git: [branch:flags] 128 | PS1="$PS1$(prompt_git)" 129 | # hg: [branch:flags] 130 | PS1="$PS1$(prompt_hg)" 131 | # misc: [cmd#:hist#] 132 | # PS1="$PS1$c1[$c0#\#$c1:$c0!\!$c1]$c9" 133 | # path: [user@host:path] 134 | PS1="$PS1$c1[$c0\u$c1@$c0\h$c1:$c0\w$c1]$c9" 135 | PS1="$PS1\n" 136 | # date: [HH:MM:SS] 137 | PS1="$PS1$c1[$c0$(date +"%H$c1:$c0%M$c1:$c0%S")$c1]$c9" 138 | # exit code: 127 139 | PS1="$PS1$(prompt_exitcode "$exit_code")" 140 | PS1="$PS1 \$ " 141 | } 142 | 143 | prompt_command 144 | -------------------------------------------------------------------------------- /lib/mathiasbynens: -------------------------------------------------------------------------------- 1 | # Shell prompt based on the Solarized Dark theme. 2 | # Screenshot: http://i.imgur.com/EkEtphC.png 3 | # Heavily inspired by @necolas’s prompt: https://github.com/necolas/dotfiles 4 | # iTerm → Profiles → Text → use 13pt Monaco with 1.1 vertical spacing. 5 | 6 | if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then 7 | export TERM='gnome-256color'; 8 | elif infocmp xterm-256color >/dev/null 2>&1; then 9 | export TERM='xterm-256color'; 10 | fi; 11 | 12 | prompt_git() { 13 | local s=''; 14 | local branchName=''; 15 | 16 | # Check if the current directory is in a Git repository. 17 | if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then 18 | 19 | # check if the current directory is in .git before running git checks 20 | if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then 21 | 22 | # Ensure the index is up to date. 23 | git update-index --really-refresh -q &>/dev/null; 24 | 25 | # Check for uncommitted changes in the index. 26 | if ! $(git diff --quiet --ignore-submodules --cached); then 27 | s+='+'; 28 | fi; 29 | 30 | # Check for unstaged changes. 31 | if ! $(git diff-files --quiet --ignore-submodules --); then 32 | s+='!'; 33 | fi; 34 | 35 | # Check for untracked files. 36 | if [ -n "$(git ls-files --others --exclude-standard)" ]; then 37 | s+='?'; 38 | fi; 39 | 40 | # Check for stashed files. 41 | if $(git rev-parse --verify refs/stash &>/dev/null); then 42 | s+='$'; 43 | fi; 44 | 45 | fi; 46 | 47 | # Get the short symbolic ref. 48 | # If HEAD isn’t a symbolic ref, get the short SHA for the latest commit 49 | # Otherwise, just give up. 50 | branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ 51 | git rev-parse --short HEAD 2> /dev/null || \ 52 | echo '(unknown)')"; 53 | 54 | [ -n "${s}" ] && s=" [${s}]"; 55 | 56 | echo -e "${1}${branchName}${2}${s}"; 57 | else 58 | return; 59 | fi; 60 | } 61 | 62 | if tput setaf 1 &> /dev/null; then 63 | tput sgr0; # reset colors 64 | bold=$(tput bold); 65 | reset=$(tput sgr0); 66 | # Solarized colors, taken from http://git.io/solarized-colors. 67 | black=$(tput setaf 0); 68 | blue=$(tput setaf 33); 69 | cyan=$(tput setaf 37); 70 | green=$(tput setaf 64); 71 | orange=$(tput setaf 166); 72 | purple=$(tput setaf 125); 73 | red=$(tput setaf 124); 74 | violet=$(tput setaf 61); 75 | white=$(tput setaf 15); 76 | yellow=$(tput setaf 136); 77 | else 78 | bold=''; 79 | reset="\e[0m"; 80 | black="\e[1;30m"; 81 | blue="\e[1;34m"; 82 | cyan="\e[1;36m"; 83 | green="\e[1;32m"; 84 | orange="\e[1;33m"; 85 | purple="\e[1;35m"; 86 | red="\e[1;31m"; 87 | violet="\e[1;35m"; 88 | white="\e[1;37m"; 89 | yellow="\e[1;33m"; 90 | fi; 91 | 92 | # Highlight the user name when logged in as root. 93 | if [[ "${USER}" == "root" ]]; then 94 | userStyle="${red}"; 95 | else 96 | userStyle="${orange}"; 97 | fi; 98 | 99 | # Highlight the hostname when connected via SSH. 100 | if [[ "${SSH_TTY}" ]]; then 101 | hostStyle="${bold}${red}"; 102 | else 103 | hostStyle="${yellow}"; 104 | fi; 105 | 106 | # Set the terminal title and prompt. 107 | PS1="\[\033]0;\W\007\]"; # working directory base name 108 | PS1+="\[${bold}\]\n"; # newline 109 | PS1+="\[${userStyle}\]\u"; # username 110 | PS1+="\[${white}\] at "; 111 | PS1+="\[${hostStyle}\]\h"; # host 112 | PS1+="\[${white}\] in "; 113 | PS1+="\[${green}\]\w"; # working directory full path 114 | PS1+="\$(prompt_git \"\[${white}\] on \[${violet}\]\" \"\[${blue}\]\")"; # Git repository details 115 | PS1+="\n"; 116 | PS1+="\[${white}\]\$ \[${reset}\]"; # `$` (and reset color) 117 | export PS1; 118 | 119 | PS2="\[${yellow}\]→ \[${reset}\]"; 120 | export PS2; 121 | -------------------------------------------------------------------------------- /lib/paulirish: -------------------------------------------------------------------------------- 1 | # This prompt inspired by gf3, sindresorhus, alrra, and mathiasbynens. 2 | # but customized to me. <3 3 | 4 | default_username='paulirish' 5 | 6 | 7 | if [[ -n "$ZSH_VERSION" ]]; then # quit now if in zsh 8 | return 1 2> /dev/null || exit 1; 9 | fi; 10 | 11 | 12 | if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then 13 | export TERM=gnome-256color 14 | elif infocmp xterm-256color >/dev/null 2>&1; then 15 | export TERM=xterm-256color 16 | fi 17 | 18 | 19 | set_prompts() { 20 | 21 | local black="" blue="" bold="" cyan="" green="" orange="" \ 22 | purple="" red="" reset="" white="" yellow="" 23 | 24 | local dateCmd="" 25 | 26 | if [ -x /usr/bin/tput ] && tput setaf 1 &> /dev/null; then 27 | 28 | tput sgr0 # Reset colors 29 | 30 | bold=$(tput bold) 31 | reset=$(tput sgr0) 32 | 33 | # Solarized colors 34 | # (https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized#the-values) 35 | black=$(tput setaf 0) 36 | blue=$(tput setaf 33) 37 | cyan=$(tput setaf 37) 38 | green=$(tput setaf 190) 39 | orange=$(tput setaf 172) 40 | purple=$(tput setaf 141) 41 | red=$(tput setaf 124) 42 | violet=$(tput setaf 61) 43 | magenta=$(tput setaf 9) 44 | white=$(tput setaf 8) 45 | yellow=$(tput setaf 136) 46 | 47 | else 48 | 49 | bold="" 50 | reset="\e[0m" 51 | 52 | black="\e[1;30m" 53 | blue="\e[1;34m" 54 | cyan="\e[1;36m" 55 | green="\e[1;32m" 56 | orange="\e[1;33m" 57 | purple="\e[1;35m" 58 | red="\e[1;31m" 59 | magenta="\e[1;31m" 60 | violet="\e[1;35m" 61 | white="\e[1;37m" 62 | yellow="\e[1;33m" 63 | 64 | fi 65 | 66 | # Only show username/host if not default 67 | function usernamehost() { 68 | 69 | # Highlight the user name when logged in as root. 70 | if [[ "${USER}" == *"root" ]]; then 71 | userStyle="${red}"; 72 | else 73 | userStyle="${magenta}"; 74 | fi; 75 | 76 | userhost="" 77 | userhost+="\[${userStyle}\]$USER " 78 | userhost+="${white}at " 79 | userhost+="${orange}$HOSTNAME " 80 | userhost+="${white}in" 81 | 82 | if [ $USER != "$default_username" ]; then echo $userhost ""; fi 83 | } 84 | 85 | 86 | function prompt_git() { 87 | # this is >5x faster than mathias's. 88 | 89 | # check if we're in a git repo. (fast) 90 | git rev-parse --is-inside-work-tree &>/dev/null || return 91 | 92 | # check for what branch we're on. (fast) 93 | # if… HEAD isn’t a symbolic ref (typical branch), 94 | # then… get a tracking remote branch or tag 95 | # otherwise… get the short SHA for the latest commit 96 | # lastly just give up. 97 | branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ 98 | git describe --all --exact-match HEAD 2> /dev/null || \ 99 | git rev-parse --short HEAD 2> /dev/null || \ 100 | echo '(unknown)')"; 101 | 102 | 103 | ## early exit for Chromium & Blink repo, as the dirty check takes ~5s 104 | ## also recommended (via goo.gl/wAVZLa ) : sudo sysctl kern.maxvnodes=$((512*1024)) 105 | repoUrl=$(git config --get remote.origin.url) 106 | if grep -q chromium.googlesource.com <<<$repoUrl; then 107 | dirty=" ⁂" 108 | else 109 | 110 | # check if it's dirty (slow) 111 | # technique via github.com/git/git/blob/355d4e173/contrib/completion/git-prompt.sh#L472-L475 112 | dirty=$(git diff --no-ext-diff --quiet --ignore-submodules --exit-code || echo -e "*") 113 | 114 | # mathias has a few more checks some may like: 115 | # github.com/mathiasbynens/dotfiles/blob/a8bd0d4300/.bash_prompt#L30-L43 116 | fi 117 | 118 | 119 | [ -n "${s}" ] && s=" [${s}]"; 120 | echo -e "${1}${branchName}${2}$dirty"; 121 | 122 | return 123 | } 124 | 125 | 126 | 127 | # ------------------------------------------------------------------ 128 | # | Prompt string | 129 | # ------------------------------------------------------------------ 130 | 131 | PS1="\[\033]0;\w\007\]" # terminal title (set to the current working directory) 132 | PS1+="\n\[$bold\]" 133 | PS1+="\[$(usernamehost)\]" # username at host 134 | PS1+="\[$green\]\w" # working directory 135 | PS1+="\$(prompt_git \"\[$white\] on \[$purple\]\" \"\[$cyan\]\")" # git repository details 136 | PS1+="\n" 137 | PS1+="\[$reset$white\]\\$ \[$reset\]" 138 | 139 | export PS1 140 | 141 | # ------------------------------------------------------------------ 142 | # | Subshell prompt string | 143 | # ------------------------------------------------------------------ 144 | 145 | export PS2="⚡ " 146 | 147 | # ------------------------------------------------------------------ 148 | # | Debug prompt string (when using `set -x`) | 149 | # ------------------------------------------------------------------ 150 | 151 | # When debugging a shell script via `set -x` this tricked-out prompt is used. 152 | 153 | # The first character (+) is used and repeated for stack depth 154 | # Then, we log the current time, filename and line number, followed by function name, followed by actual source line 155 | 156 | # FWIW, I have spent hours attempting to get time-per-command in here, but it's not possible. ~paul 157 | export PS4='+ \011\e[1;30m\t\011\e[1;34m${BASH_SOURCE}\e[0m:\e[1;36m${LINENO}\e[0m \011 ${FUNCNAME[0]:+\e[0;35m${FUNCNAME[0]}\e[1;30m()\e[0m:\011\011 }' 158 | 159 | 160 | # shoutouts: 161 | # https://github.com/dholm/dotshell/blob/master/.local/lib/sh/profile.sh is quite nice. 162 | # zprof is also hot. 163 | 164 | } 165 | 166 | 167 | 168 | set_prompts 169 | unset set_prompts 170 | -------------------------------------------------------------------------------- /lib/thomasjbradley: -------------------------------------------------------------------------------- 1 | # @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt” 2 | # Shamelessly copied from https://github.com/gf3/dotfiles 3 | # Screenshot: http://i.imgur.com/s0Blh.png 4 | 5 | MAGENTA="\033[1;31m" 6 | ORANGE="\033[1;33m" 7 | GREEN="\033[1;32m" 8 | PURPLE="\033[1;35m" 9 | WHITE="\033[1;37m" 10 | BOLD="" 11 | RESET="\033[m" 12 | 13 | export MAGENTA 14 | export ORANGE 15 | export GREEN 16 | export PURPLE 17 | export WHITE 18 | export BOLD 19 | export RESET 20 | 21 | function parse_git_dirty() { 22 | [[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && echo " ✘" 23 | } 24 | 25 | function parse_git_branch() { 26 | git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" 27 | } 28 | 29 | PS1="\[${BOLD}${MAGENTA}\]\u \[$RESET\]at \[$ORANGE\]\h \[$RESET\]in \[$GREEN\]\w\[$RESET\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]" 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prompt-so-fancy", 3 | "version": "0.0.0", 4 | "description": "Make your terminal look more fancy", 5 | "bin": { 6 | "prompt-so-fancy": "prompt-so-fancy" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git+https://github.com/stevemao/prompt-so-fancy.git" 11 | }, 12 | "keywords": [ 13 | "git", 14 | "prompt", 15 | "fancy", 16 | "good-lookin'", 17 | "color", 18 | "readable" 19 | ], 20 | "author": "Steve Mao", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/stevemao/prompt-so-fancy/issues" 24 | }, 25 | "homepage": "https://github.com/stevemao/prompt-so-fancy#readme" 26 | } 27 | -------------------------------------------------------------------------------- /prompt-so-fancy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | get_script_dir () { 4 | src="${BASH_SOURCE[0]}" 5 | 6 | while [[ -h "$src" ]]; do 7 | dir="$(cd -P "$( dirname "$src" )" && pwd)" 8 | src="$(readlink "$src")" 9 | [[ $src != /* ]] && src="$dir/$src" 10 | done 11 | 12 | dir="$(cd -P "$( dirname "$src" )" && pwd)" 13 | echo "$dir" 14 | } 15 | 16 | # array of authors 17 | authors=("paulirish" "mathiasbynens" "dholm") 18 | 19 | # seed random generator 20 | RANDOM=$$$(date +%s) 21 | 22 | shopt -s nullglob 23 | authors=(lib/*) 24 | 25 | author=${authors[$RANDOM % ${#authors[@]} ]} 26 | 27 | source "$(get_script_dir)/$author" 28 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # prompt-so-fancy 2 | 3 | ![](http://i.imgur.com/EkEtphC.png) 4 | 5 | ![](http://farm8.staticflickr.com/7142/6754488927_563dd73553_b.jpg) 6 | 7 | 8 | ## Usage 9 | 10 | ```shell 11 | source prompt-so-fancy 12 | ``` 13 | 14 | You could drop an alias in your `~/.bash_profile`: 15 | 16 | ```shell 17 | alias psf='source prompt-so-fancy' 18 | psf 19 | ``` 20 | 21 | 22 | ## Install 23 | 24 | For convenience, the recommended installation is via NPM. If you'd prefer, you may choose to do a [manual installation](#manual-install) instead. 25 | 26 | ```shell 27 | npm install -g prompt-so-fancy 28 | ``` 29 | 30 | This will install and link the `prompt-so-fancy` scripts. You can also upgrade to the latest version with this command. 31 | 32 | 33 | ## Manual install 34 | 35 | If you want, you can choose to install manually: 36 | 37 | 1. Grab the script (`prompt-so-fancy`) via either downloading or cloning the repo. 38 | 1. Place them in a location that is in your `PATH` directly or with symlinks. 39 | 40 | 41 | ## Contributing 42 | 43 | Pull requests quite welcome, along with any feedback or ideas. 44 | 45 | ### Hacking 46 | 47 | ```sh 48 | # fork and clone the prompt-so-fancy repo. 49 | git clone https://github.com//prompt-so-fancy/ && cd prompt-so-fancy 50 | ``` 51 | 52 | Make changes and send a PR! 53 | 54 | 55 | ## Credit 56 | 57 | inspired by paulirish, cowboy, thomasjbradley, and mathiasbynens. 58 | 59 | 60 | ## License 61 | 62 | MIT 63 | --------------------------------------------------------------------------------