-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommon
More file actions
74 lines (65 loc) · 1.58 KB
/
common
File metadata and controls
74 lines (65 loc) · 1.58 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# sets it for all
# set -e
# Helper vars
GREEN='\033[0;32m'
RED='\033[0;31m'
NO_COLOR='\033[0m'
# Helper functions
command_exists() {
type "$1" &> /dev/null ;
}
infoprint() {
echo -e "${GREEN}${1}${NO_COLOR}"
}
errorprint() {
echo -e "${RED}${1}${NO_COLOR}" >&2
}
is_work() {
[[ "$DOTFILES_PROFILE" == "work" ]]
}
is_personal() {
[[ "$DOTFILES_PROFILE" == "personal" ]]
}
is_work_or_hybrid() {
[[ "$DOTFILES_PROFILE" == "work" || "$DOTFILES_PROFILE" == "hybrid" ]]
}
is_personal_or_hybrid() {
[[ "$DOTFILES_PROFILE" == "personal" || "$DOTFILES_PROFILE" == "hybrid" ]]
}
prepare_profiled_config() {
if [ -z "$module_name" ]; then
errorprint "error: \$module_name not set!"
return 1
fi
local filename="$1"
local target="${SCRIPT_BASE_DIR}/${module_name}/${filename}"
# reset from base
cp "${target}.base" "$target"
if is_personal_or_hybrid && [ -f "${target}.personal" ]; then
cat "${target}.personal" >> "$target"
fi
if is_work_or_hybrid && [ -f "${target}.work" ]; then
cat "${target}.work" >> "$target"
fi
}
remove_profiled_config() {
if [ -z "$module_name" ]; then
errorprint "error: \$module_name not set!"
return 1
fi
local target="${SCRIPT_BASE_DIR}/${module_name}/$1"
if [ -f "${target}" ]; then
rm "$target"
fi
}
# Appends a line ($1) to the given file ($2) if it doesn't exist already
add_if_not_there() {
touch "$2"
grep -qxF "$1" "$2" || echo "$1" >> "$2"
}
# Wrapper for add_if_not_there with the global gitignore file
gitignore() {
infoprint "[$module_name] adding $1 to global gitignore"
add_if_not_there "$1" ~/.gitignore
}