-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
Β·130 lines (111 loc) Β· 2.57 KB
/
run.sh
File metadata and controls
executable file
Β·130 lines (111 loc) Β· 2.57 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
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
126
127
128
129
130
#!/usr/bin/env bash
# This is the generic harness for running each of my setup scripts.
# Usage: ./run.sh [filter] [--dry]
# This ensures that if this is run via symlink, we still get the correct path
if [[ -L "$0" ]]; then
script_path=$(readlink -f "$0")
else
script_path="$0"
fi
# The directory of this script
script_dir=$(cd "$(dirname "$script_path")" && pwd)
filter=""
dry="0"
args=()
while [[ $# -gt 0 ]]; do
# Make this script dry
if [[ $1 == "--dry" ]]; then
dry="1"
# Make the scripts this script runs dry
elif [[ $1 == "--drier" ]]; then
dry="2"
elif [[ $1 == "--" ]]; then
# Everything after this we pass through as arguments to the scripts
shift
while [[ $# -gt 0 ]]; do
args+=("$1")
shift
done
break
else
filter="$1"
fi
shift
done
export script_dir="$script_dir"
export dry="$dry"
# Colors
BOLD='\033[1m'
DIM='\033[2m'
CYAN='\033[0;36m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
header() {
echo ""
if [[ -n "$filter" ]]; then
echo -e "${BOLD}${CYAN}dotfiles${NC} ${DIM}>${NC} ${BOLD}$filter${NC}"
else
echo -e "${BOLD}${CYAN}dotfiles${NC} ${DIM}> all${NC}"
fi
if [[ $dry == "1" ]] || [[ $dry == "2" ]]; then
echo -e " ${YELLOW}(dry run)${NC}"
fi
echo ""
}
log() {
if [[ $dry == "1" ]] || [[ $dry == "2" ]]; then
echo -e "${DIM}[dotfiles]${NC} ${YELLOW}[DRY_RUN]${NC} $*"
else
echo -e "${DIM}[dotfiles]${NC} $*"
fi
}
execute() {
echo -e "${DIM}[dotfiles]${NC} ${GREEN}Running${NC} $*"
if [[ $dry == "1" ]]; then
return
fi
if [[ ${#args[@]} -gt 0 ]]; then
"$@" "${args[@]}"
else
"$@"
fi
}
header
cd "$script_dir"/scripts || exit
# Detect if running on Windows
is_windows() {
case "$(uname -s)" in
CYGWIN*|MINGW*|MSYS*|Windows*)
return 0
;;
*)
return 1
;;
esac
}
# Determine which find command to use
if command -v gfind >/dev/null 2>&1; then
FIND="gfind"
else
FIND="find"
fi
# Find appropriate scripts based on platform
if is_windows; then
scripts=$($FIND . -maxdepth 1 -mindepth 1 -name "*.ps1" -type f)
else
scripts=$($FIND . -maxdepth 1 -mindepth 1 -executable -name "*.sh" -type f)
fi
for script in $scripts; do
if echo "$script" | grep -qv "$filter"; then
# Only show skipped scripts when running all (no filter)
[[ -z "$filter" ]] && log "${DIM}Skipped $script${NC}"
continue
fi
# Execute PowerShell scripts differently on Windows
if is_windows && [[ "$script" == *.ps1 ]]; then
execute powershell.exe -ExecutionPolicy Bypass -File "$script"
else
execute "$script"
fi
done