-
Notifications
You must be signed in to change notification settings - Fork 3
/
prompt
81 lines (66 loc) · 1.66 KB
/
prompt
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
#!/usr/bin/env bash
# solarized colors
BASE03="\[$(tput setaf 8)\]"
BASE02="\[$(tput setaf 0)\]"
BASE01="\[$(tput setaf 10)\]"
BASE00="\[$(tput setaf 11)\]"
BASE0="\[$(tput setaf 12)\]"
BASE1="\[$(tput setaf 14)\]"
BASE2="\[$(tput setaf 7)\]"
BASE3="\[$(tput setaf 15)\]"
YELLOW="\[$(tput setaf 3)\]"
ORANGE="\[$(tput setaf 9)\]"
RED="\[$(tput setaf 1)\]"
MAGENTA="\[$(tput setaf 5)\]"
VIOLET="\[$(tput setaf 13)\]"
BLUE="\[$(tput setaf 4)\]"
CYAN="\[$(tput setaf 6)\]"
GREEN="\[$(tput setaf 2)\]"
RESET="\[$(tput sgr0)\]"
function git_prompt() {
branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [[ $? == 0 ]]; then
printf "(%.10s%s) " "$branch" "$([[ -n $(git status -s) ]] && echo " ✗")"
fi
}
function status_symbol() {
if [[ $1 != 0 ]]; then
echo -n "⚡ $1 ⚡ "
fi
}
function right_prompt() {
local str="$(date +'%a %H:%M:%S')"
if [[ "$SSH_TTY" ]]; then
str="$(id -u -n)@$(hostname -s) $str"
fi
tput sc
printf "%*s" $COLUMNS "$str"
tput rc
}
function ppwd() {
[[ $COLUMNS -lt 60 ]] && return
local path="$PWD"
local path_depth=$(grep -o "/" <<< "$path" | wc -l)
local cols=$((($COLUMNS * 2 / 5) - 10))
for (( i=1; i<=$path_depth; i++))
do
if [[ ${#path} -gt $cols ]]; then
path="$(echo "$path" | sed -e "s;\(/.\)[^/][^/]*;\1;")"
fi
done
if [[ ${#path} -gt $cols ]]; then
path="«${path:0-$cols}"
fi
echo "$path "
}
function root_check() {
if [[ "$(id -u)" == 0 ]]; then
echo "[ROOT] "
fi
}
PS1="$BASE1\$(LS=\$?; right_prompt; exit \$LS)"
PS1+="$RED\$(status_symbol \$?)$RESET\n"
PS1+="$BASE0\$(ppwd)$GREEN\$(git_prompt)"
PS1+="$ORANGE\$(root_check)"
PS1+="$BASE01\\$ $RESET"
export PS1