-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdot_bash_keys
More file actions
40 lines (33 loc) · 1.06 KB
/
dot_bash_keys
File metadata and controls
40 lines (33 loc) · 1.06 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
#!/usr/bin/env bash
#
# Load API keys and secrets from ~/.keys directory
# IMPORTANT: Keys are never committed to this repository
# They are loaded from local files in ~/.keys
# Create keys directory if it doesn't exist
[[ -d "${HOME}/.keys" ]] || mkdir -p "${HOME}/.keys"
# Load all .sh files from ~/.keys directory
if [[ -d "${HOME}/.keys" ]]; then
for keyfile in "${HOME}"/.keys/*.sh; do
if [[ -f "${keyfile}" ]]; then
# shellcheck source=/dev/null
. "${keyfile}"
fi
done
fi
# Add a helper function to create key files safely
keys_add() {
local key_name="$1"
local key_value="$2"
if [[ -z "${key_name}" || -z "${key_value}" ]]; then
echo "Usage: keys_add KEY_NAME KEY_VALUE"
echo "Example: keys_add GITHUB_TOKEN abcd1234"
return 1
fi
# Create the key file
echo "export ${key_name}=${key_value}" > "${HOME}/.keys/${key_name,,}.sh"
chmod 600 "${HOME}/.keys/${key_name,,}.sh"
# Source it immediately
# shellcheck source=/dev/null
. "${HOME}/.keys/${key_name,,}.sh"
echo "${key_name} added and loaded successfully."
}