Skip to content

Instantly share code, notes, and snippets.

@hced
Created May 18, 2012 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hced/2724090 to your computer and use it in GitHub Desktop.
Save hced/2724090 to your computer and use it in GitHub Desktop.
My current shell prompt
# ---------
# prompt.sh
# ---------
####################################################################
# #
# This is probably a mess, with bad scoping and what not, but it #
# works and looks just awesome. (Modified for Mac OS X.) #
# #
# It's a mix between two prompt stylings that can be found #
# here: http://j.mp/w5FgUT …and here: http://j.mp/xoUVlD #
# #
# To be cleaned up & refactored when time allows (probably never) #
# #
# /hced #
# #
####################################################################
# Fill with minuses (this is recalculated every time the prompt
# is shown in function prompt_command):
fill="--- "
reset_style='\[\033[00m\]'
status_style=$reset_style'\[\033[0;37m\]' # white color; use 0;90m for darker (gray) color
prompt_style=$reset_style
command_style=$reset_style'\[\033[1;29m\]' # bold black
# Prompt variable:
# git bash completion.
# Required for the prompt. Also provides autocompletion of git commands and branch names.
. ~/.dotfiles/bash/lib/git-completion.bash
function __git_prompt {
GIT_PS1_SHOWDIRTYSTATE=1
__git_ps1 "[ %s]" | sed 's/ \([+*]\{1,\}\)$/\1/'
}
# Only show username@server over SSH.
function __name_and_server {
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
echo "`whoami`@`hostname -s` "
fi
}
bash_prompt() {
# regular colors
local K="\[\033[0;30m\]" # black
local R="\[\033[0;31m\]" # red
local G="\[\033[0;32m\]" # green
local Y="\[\033[0;33m\]" # yellow
local B="\[\033[0;34m\]" # blue
local M="\[\033[0;35m\]" # magenta
local C="\[\033[0;36m\]" # cyan
local W="\[\033[0;37m\]" # white
# emphasized (bolded) colors
local BK="\[\033[1;30m\]"
local BR="\[\033[1;31m\]"
local BG="\[\033[1;32m\]"
local BY="\[\033[1;33m\]"
local BB="\[\033[1;34m\]"
local BM="\[\033[1;35m\]"
local BC="\[\033[1;36m\]"
local BW="\[\033[1;37m\]"
# reset
local RESET="\[\033[0;37m\]"
#PS1="\t $BY\$(__name_and_server)$Y\w$G[\$(__rvm_prompt)$G\$(__git_prompt)]$RESET$ "
PS1="$status_style"'$fill \t\n'"$BY\$(__name_and_server)$Y\w$G\$(__git_prompt)$RESET$ "
}
bash_prompt
unset bash_prompt
# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\033[00m"' DEBUG
function prompt_command {
# create a $fill of all screen width minus the time string and a space:
let fillsize=${COLUMNS}-9
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
bname=`basename "${PWD/$HOME/~}"`
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
;;
*)
;;
esac
}
PROMPT_COMMAND=prompt_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment