-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprompt.sh
72 lines (60 loc) · 1.65 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
source $(dirname "$BASH_SOURCE")/../lib/MSGShellUtils/ui.sh
user() {
echo -n $boldon
if [[ $USER == "matti" ]]
then echo -n $greenf"∵"
else echo -n "$redf$USER"
fi
echo -n "$reset"
}
host() {
echo -n $boldon
if [[ $HOSTNAME == "MBA-Matti.local" ]]
then echo -n $greenf"∴"
else echo -n " $yellowf$HOSTNAME"
fi
echo -n " $reset"
}
directory() {
local pwd="$(pwd)"
echo -n $purplef
if [[ $pwd == $HOME ]]
then echo -n $boldon'~'
elif [[ $pwd == '/' ]]
then echo -n $boldon'/'
else
echo -n $(basename "$(dirname "$pwd")")/$boldon$(basename "$pwd")
fi
echo -n $reset
}
timestamp() {
echo -n "⦑ $(date '+%H:%M:%S') "
}
# Exit code of previous command.
# Credit: <https://github.com/cowboy/dotfiles/blob/master/source/50_prompt.sh>
exit_code() { # [exit code]
if [[ $1 != 0 ]]
then echo " $redb $1 $reset"
fi
}
parse_git_dirty() {
[[ $(git status 2> /dev/null | wc -l) != " 2" ]] && echo '⊛'
}
gitinfo() {
result=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/")
if [[ -n $result ]]
then echo -n " $cyanf[$result]$boldon$(parse_git_dirty)$reset"
fi
}
# Credit: <http://frantic.im/notify-on-completion>
notify_if_not_frontmost() {
local exit_code=$1
local previous_command=$(history | tail -1 | cut -d ' ' -f 5-)
osascript "$(dirname "$BASH_SOURCE")/../lib/notify-if-not-terminal.scpt" "$previous_command" "$exit_code" || "$(dirname "$BASH_SOURCE")/../session/enable-terminal-notifications.sh"
}
prompt_command() {
local exit_code=$?
(notify_if_not_frontmost $exit_code &) > /dev/null
PS1="$(user)$(host)$(directory)$(gitinfo) $(timestamp)$(exit_code $exit_code)\n› "
}
PROMPT_COMMAND="prompt_command"