-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprompt.sh
91 lines (77 loc) · 2.55 KB
/
prompt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -------------------------------------------------------
# Original Author: Nathan Broadbent
# Modified By: Michael-Keith Bernard
# Source: https://github.com/ndbroadbent/ubuntu_config
# Retrieved: Oct 19, 2011
# -------------------------------------------------------
# -------------------------------------------------------
# Prompt / Xterm
# -------------------------------------------------------
# Prompt colors
_txt_col="\e[00m" # Std text (white)
_bld_col="\e[01;37m" # Bold text (white)
_wrn_col="\e[01;31m" # Warning
_sep_col=$_txt_col # Separators
_usr_col="\e[01;32m" # Username
_cwd_col=$_txt_col # Current directory
_hst_col="\e[0;32m" # Host
_env_col="\e[0;36m" # Prompt environment
_git_col="\e[01;36m" # Git branch
# Returns the current git branch (returns nothing if not a git repository)
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "±"
}
# Returns the current ruby version.
parse_ruby_version() {
if (which ruby | grep -q ruby); then
ruby -v | cut -d ' ' -f2
fi
}
# Set the prompt string (PS1)
# Looks like this:
# user@computer ~/src/ubuntu_config [master|1.8.7]$
# (Prompt strings need '\['s around colors.)
set_ps1() {
user_str="\[$_usr_col\]\u\[$_hst_col\]@\h\[$_txt_col\]"
dir_str="\[$_cwd_col\]\w"
git_branch=`parse_git_branch`
git_dirty=`parse_git_dirty`
#ruby=`parse_ruby_version`
ruby=""
git_str="\[$_git_col\]$git_branch\[$_wrn_col\]$git_dirty"
# Git repo & ruby version
if [ -n "$git_branch" ] && [ -n "$ruby" ]; then
env_str="\[$_env_col\][$git_str\[$_env_col\]|$ruby]"
# Just git repo
elif [ -n "$git_branch" ]; then
env_str="\[$_env_col\][$git_str\[$_env_col\]]"
# Just ruby version
elif [ -n "$ruby" ]; then
env_str="\[$_env_col\][$ruby]"
else
unset env_str
fi
# < username >@< hostname > < current directory > [< git branch >|< ruby version >]
PS1="${debian_chroot:+($debian_chroot)}$user_str:$dir_str $env_str\[$_sep_col\]$ \[$_txt_col\]"
}
# Set custom prompt
PROMPT_COMMAND='set_ps1;'
# Set GREP highlight color
export GREP_COLOR='1;32'
# Custom Xterm/RXVT Title
# case "$TERM" in
# xterm*|rxvt*)
# PROMPT_COMMAND+='echo -ne "\e]0;${USER}@${HOSTNAME}: ${PWD}\007";'
# ;;
# *)
# ;;
# esac
# Correct spelling errors for 'cd' command, and auto cd to directory
# Only run this for debian systems (AWS doesn't have 'shopt')
if [ -f /etc/debian_version ]; then
shopt -s cdspell
shopt -s autocd
fi