forked from necolas/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathutils
63 lines (53 loc) · 1.16 KB
/
utils
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
#!/bin/bash
# Header logging
e_header() {
printf "\n$(tput setaf 7)%s$(tput sgr0)\n" "$@"
}
# Success logging
e_success() {
printf "$(tput setaf 64)✓ %s$(tput sgr0)\n" "$@"
}
# Error logging
e_error() {
printf "$(tput setaf 1)x %s$(tput sgr0)\n" "$@"
}
# Warning logging
e_warning() {
printf "$(tput setaf 136)! %s$(tput sgr0)\n" "$@"
}
# Ask for confirmation before proceeding
seek_confirmation() {
printf "\n"
e_warning "$@"
read -p "Continue? (y/n) " -n 1
printf "\n"
}
# Test whether the result of an 'ask' is a confirmation
is_confirmed() {
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
return 0
fi
return 1
}
# Test whether we're in a git repo
is_git_repo() {
$(git rev-parse --is-inside-work-tree &> /dev/null)
}
# Test whether a command exists
# $1 - cmd to test
type_exists() {
if [ $(type -P $1) ]; then
return 0
fi
return 1
}
# Test whether a Homebrew formula is already installed
# $1 - formula name (may include options)
formula_exists() {
if $(brew list $1 >/dev/null); then
printf "%s already installed.\n" "$1"
return 0
fi
e_warning "Missing formula: $1"
return 1
}