-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions
More file actions
53 lines (47 loc) · 1.31 KB
/
functions
File metadata and controls
53 lines (47 loc) · 1.31 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
#!/usr/bin/bash
command_exists() {
type "$1" &>/dev/null
}
# https://coderwall.com/p/_s_xda/fix-ssh-agent-in-reattached-tmux-session-shells
fixssh() {
for key in SSH_AUTH_SOCK SSH_CONNECTION SSH_CLIENT; do
if (tmux show-environment | grep "^${key}" >/dev/null); then
value=$(tmux show-environment | grep "^${key}" | sed -e "s/^[A-Z_]*=//")
export ${key}="${value}"
fi
done
}
# Shorten the email to the format x@y; useful in prompt
git_user_name_prompt_mkii() {
git config user.email | sed 's/\(.\).\+@\(..\).\+/\1@\2/'
}
# git quicksave: commit and push
save() {
if [ -z "${1+x}" ]; then
git commit -a -m "update" && git push
else
git commit -a -m "$1" && git push
fi
}
# Print text to terminal centered
center-text() {
colcount=$((COLUMNS - 3))
sed -e :a -e "s/^.\{1,$colcount\}$/ & /;ta"
unset colcount
}
load_secrets() {
local _secrets="$HOME/.secrets"
if [[ ! -f "$_secrets" ]]; then
echo "No secrets file found at $_secrets" >&2
return 1
fi
local _perms
_perms="$(stat -c '%a' "$_secrets" 2>/dev/null || stat -f '%OLp' "$_secrets" 2>/dev/null)"
if [[ "$_perms" != "600" ]]; then
echo "WARNING: $_secrets has permissions $_perms (expected 600). Skipping." >&2
return 1
fi
# shellcheck disable=SC1090
source "$_secrets"
echo "Secrets loaded."
}