-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncs
More file actions
62 lines (53 loc) · 1.22 KB
/
funcs
File metadata and controls
62 lines (53 loc) · 1.22 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
#!/bin/bash
# Copyright (C) 2025 Robert A. Wallis, All Rights Reserved.
function trcut() {
tr -s ' ' | cut -d ' ' "$@"
}
function killport() {
port=${@:$#}
if [ -z "$port" ]; then
echo "usage: killport [args for kill] <tcp port>"
echo " kills whichever process is using the port"
echo " useful because grunt keeps node running"
return 1
fi
pid=$(lsof -t -i tcp:$port)
if [ -z "$pid" ]; then
echo "port $port not in use"
return 1
fi
# get rid of last param
args=${@:1:$#-1}
kill $args $pid
}
# simple load of .env as exported variables
function dotenv() {
if [ $# -gt 1 ]; then
echo "Usage: dotenv <file>"
echo " or: dotenv"
echo " to load the .env file"
return 1
fi
local file
if [ -f "$1" ]; then
file="$1"
else
file=".env"
fi
if [ ! -f "$file" ]; then
echo "File $file does not exist."
return 1
fi
echo "sourcing $file"
set -o allexport
# set IFS internal file spacing to blank to capture blank spaces
while IFS= read -r line; do
if [[ "$line" == *=* ]]; then
var_name="${line%%=*}"
var_val="${line#*=}"
echo "exporting $var_name"
export "$var_name"="$var_val"
fi
done <"$file"
set +o allexport
}