This repository has been archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutils.sh
executable file
·125 lines (100 loc) · 2.73 KB
/
utils.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
# Borrowed from https://natelandau.com/bash-scripting-utilities/
# ============================================================================ #
# Set Colors
# ============================================================================ #
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
purple=$(tput setaf 171)
red=$(tput setaf 1)
green=$(tput setaf 76)
tan=$(tput setaf 3)
blue=$(tput setaf 38)
# ============================================================================ #
# Headers and Logging
# ============================================================================ #
e_header() {
printf "\n${bold}${purple}========== %s ==========${reset}\n" "$@"
}
e_arrow() {
printf "➜ $@\n"
}
e_success() {
printf "${green}✔ %s${reset}\n" "$@"
}
e_error() {
printf "${red}✖ %s${reset}\n" "$@"
}
e_warning() {
printf "${tan}➜ %s${reset}\n" "$@"
}
e_underline() {
printf "${underline}${bold}%s${reset}\n" "$@"
}
e_bold() {
printf "${bold}%s${reset}\n" "$@"
}
e_note() {
printf "${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@"
}
# ============================================================================ #
# Confirmations
# ============================================================================ #
# ============================================================================ #
# USAGE FOR SEEKING CONFIRMATION
# seek_confirmation "Ask a question"
# Credt: https://github.com/kevva/dotfiles
#
# if is_confirmed; then
# some action
# else
# some other action
# fi
# ============================================================================ #
seek_confirmation() {
printf "\n${bold}$@${reset}"
read -p " (y/n) " -n 1
printf "\n"
}
# underlined
seek_confirmation_head() {
printf "\n${underline}${bold}$@${reset}"
read -p "${underline}${bold} (y/n)${reset} " -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 a command exists
# $1 = cmd to test
# Usage:
# if type_exists 'git'; then
# some action
# else
# some other action
# fi
# ============================================================================ #
type_exists() {
if [ $(type -P $1) ]; then
return 0
fi
return 1
}
# ============================================================================ #
# Test which OS the user runs
# $1 = OS to test
# Usage: if is_os 'darwin'; then
# ============================================================================ #
is_os() {
if [[ "${OSTYPE}" == $1* ]]; then
return 0
fi
return 1
}
# TODO: read https://github.com/shellfire-dev/shellfire