-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathfunctions
More file actions
91 lines (88 loc) · 2.67 KB
/
Copy pathfunctions
File metadata and controls
91 lines (88 loc) · 2.67 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
server(){
if [ -f "./.workspace" ] || \
{ [ -f "./.conductor/conductor.json" ] && grep -q 'workspace run' "./.conductor/conductor.json"; } || \
{ [ -f "./.superset/config.json" ] && grep -q 'workspace' "./.superset/config.json"; }; then
echo "Starting workspace run...";
workspace run
elif [ -f "./bin/server" ]; then
echo "Starting bin/server...";
./bin/server
elif [ -f "./script/server" ]; then
echo "Starting script/server...";
./script/server
elif [ -f "./bin/start" ]; then
echo "Starting bin/start...";
./bin/start
elif [ -f "./bin/dev" ]; then
echo "Starting bin/dev...";
./bin/dev
elif [ -f "./Procfile" ]; then
echo "Starting foreman from Procfile...";
bundle exec foreman start
elif [ -f "./bin/rails" ]; then
local port=${1:-3000}
echo "Starting Rails server at port $port...";
bin/rails server -p $port --binding=0.0.0.0
elif [ -f "./bin/middleman" ]; then
echo "Starting Middleman server...";
./bin/middleman
elif [ -f "./package.json" ] && jq -e '.scripts.start' package.json > /dev/null; then
echo "Starting npm server...";
npm start
else
local port=${1:-8080}
echo "Starting static python server...";
python3 -m http.server $port
fi
}
_rails_credentials_env() {
# Echoes chosen env name, or empty string to signal "use default credentials".
# $1 = optional env arg
if [ -n "$1" ]; then
echo "$1"
return
fi
[ -d "./config/credentials" ] || return
local keys=(./config/credentials/*.key(N))
[ ${#keys[@]} -eq 0 ] && return
if [ ${#keys[@]} -eq 1 ]; then
basename "${keys[1]}" .key
return
fi
echo "Multiple credential environments found:" >&2
local i=1
for k in "${keys[@]}"; do
echo " $i) $(basename "$k" .key)" >&2
((i++))
done
printf "Select environment [1-%d]: " "${#keys[@]}" >&2
local choice
read -r choice
basename "${keys[$choice]}" .key
}
creds() {
[ -f "./bin/rails" ] || { echo "Not a Rails project (no bin/rails)"; return 1; }
[ $# -gt 1 ] && { echo "Usage: creds [env|--help]"; return 1; }
case "$1" in
-h|--help) bin/rails credentials:show --help; return ;;
esac
local env=$(_rails_credentials_env "$1")
if [ -n "$env" ]; then
bin/rails credentials:show -e "$env"
else
bin/rails credentials:show
fi
}
crede() {
[ -f "./bin/rails" ] || { echo "Not a Rails project (no bin/rails)"; return 1; }
[ $# -gt 1 ] && { echo "Usage: crede [env|--help]"; return 1; }
case "$1" in
-h|--help) bin/rails credentials:edit --help; return ;;
esac
local env=$(_rails_credentials_env "$1")
if [ -n "$env" ]; then
bin/rails credentials:edit -e "$env"
else
bin/rails credentials:edit
fi
}