-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils
executable file
·65 lines (56 loc) · 1.17 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
64
65
#!/usr/bin/env bash
# utils
# based on: https://github.com/necolas/dotfiles/
# set -x
set -o errexit
set -o pipefail
# Header logging
e_header() {
printf "\n$(tput setaf 7)%s$(tput sgr0)\n" "$@"
}
typeset -fx e_header
# Success logging
e_success() {
printf "$(tput setaf 64)✓ %s$(tput sgr0)\n" "$@"
}
typeset -fx e_success
# Error logging
e_error() {
printf "$(tput setaf 1)x %s$(tput sgr0)\n" "$@"
}
typeset -fx e_error
# Warning logging
e_warning() {
printf "$(tput setaf 136)! %s$(tput sgr0)\n" "$@"
}
typeset -fx e_warning
# Ask for confirmation before proceeding
seek_confirmation() {
printf "\n"
e_warning "$@"
read -p "Continue? (y/n) " -n 1
printf "\n"
}
typeset -fx seek_confirmation
# Test whether the result of an 'ask' is a confirmation
is_confirmed() {
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
return 0
fi
return 1
}
typeset -fx is_confirmed
# Test whether we're in a git repo
is_git_repo() {
$(git rev-parse --is-inside-work-tree &> /dev/null)
}
typeset -fx is_git_repo
# Test whether a command exists
# $1 - cmd to test
type_exists() {
if [ $(type -P $1) ]; then
return 0
fi
return 1
}
typeset -fx type_exists