-
Notifications
You must be signed in to change notification settings - Fork 0
/
PS1.sh
61 lines (41 loc) · 877 Bytes
/
PS1.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
#!/usr/bin/env php
<?php
if ($argv[1][0] === "1") {
echo "\033[0;31m";
}
echo "\$ ";
echo "\033[0m";
$user = posix_getpwuid(posix_geteuid())['name'];
echo "\033[0;36m$user\033[0m @ ";
function get_pwd() {
$home = getenv("HOME");
$pwd = getcwd();
if (substr($pwd, 0, strlen($home)) === $home) {
$pwd = "~".substr($pwd, strlen($home));
}
return $pwd;
}
$pwd = get_pwd();
echo "\033[0;37m$pwd\033[0m ";
function is_git() {
exec("git status 2>/dev/null", $out, $code);
return $code === 0;
}
function is_clean() {
$out = exec("git status 2>&1");
return $out === "nothing to commit, working tree clean";
}
function git_branch() {
return exec("git rev-parse --abbrev-ref HEAD 2>&1");
}
if (is_git()) {
$branch = git_branch();
if (is_clean()) {
echo "\033[0;32m";
} else {
echo "\033[0;31m";
}
echo "[$branch] ";
echo "\033[0m";
}
echo ": ";