-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.sh
More file actions
59 lines (44 loc) · 1.03 KB
/
utils.sh
File metadata and controls
59 lines (44 loc) · 1.03 KB
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
#!/usr/bin/env bash
source "fn.sh"
repo() {
repo=$(git remote show origin -n | grep "Fetch" | awk '{print $3}')
repo=${repo:15:-4}
echo "${repo}"
}
current_branch() {
git symbolic-ref --short -q HEAD
}
previous_branch() {
git describe --all $(git rev-parse @{-1}) | cut -c7-
}
colorstring() {
declare -A MYMAP
MYMAP[red]="\\e[91m"
MYMAP[green]="\\e[92m"
MYMAP[yellow]="\\e[93m"
MYMAP[blue]="\\e[94m"
MYMAP[magenta]="\\e[95m"
MYMAP[cyan]="\\e[96m"
line="${1}"
re='<([^/>]+)>'
while [[ $line =~ $re ]]; do
color="${BASH_REMATCH:1:${#BASH_REMATCH}-2}"
if [[ "${MYMAP[${color}]}" == "" ]]; then break; fi
line=${line/${BASH_REMATCH}/${MYMAP[${color}]}}
# and replace the closing
line=${line/<\/${color}>/\\e[0m}
done
echo -en "${line}"
}
write() {
str=$(colorstring "${1}")
echo -en "${str}"
}
writeln() {
write "${1}"
echo ""
}
gh_exists() {
gh > /dev/null 2>&1
[[ "${?}" != "127" ]] && echo "1" || echo "0"
}