-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.dot_misc
More file actions
84 lines (70 loc) · 2.2 KB
/
.dot_misc
File metadata and controls
84 lines (70 loc) · 2.2 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
#!/bin/bash
debug_out() {
if [[ $- == *i* && $DOT_DEBUG ]]
then
echo $@
fi
}
debug_out "Processing configuration for Miscellaneous Tools"
list_functions() {
echo "listing functions"
for return_status in 0
do
if [[ $1 == "--help" || $1 == "-h" ]]
then
return_status=1
message="Print all the functions defined in a dot file"
message="$message\nUSAGE: ${FUNCNAME[0]} <dot_file>"
break
fi
dotfile=$1
if [[ -z $dotfile ]]
then
return_status=1
message="No dotfile supplied to find functions in"
break
fi
echo "Functions defined in $dotfile"
defined_functions=$(typeset -F | perl -pe "s/declare -f //")
for function in $defined_functions
do
line_info=$(grep -n "^$function\(\)\s*{" $dotfile)
if (( $? ))
then
continue
fi
line_num=$(echo $line_info | perl -pe "s/(\d+):.*/\1/")
echo " $function [$line_num]"
done
message=""
done
echo $message
return $return_status
}
# Heavily adapted from: https://gist.github.com/MarkRose/1772891
bind_ssh_agent() {
debug_out "Binding to ssh agent"
for FILE in $(find /tmp/ssh-* -type s -user ${LOGNAME} -name "agent.[0-9]*" 2> /dev/null)
do
SOCK_PID=${FILE##*.}
PID=$(echo $SOCK_PID | cut -d '.' -f2 | awk '{print $1 + 1}' | xargs ps -o pid= -p | xargs)
if [[ -z "$PID" ]]
then
continue
fi
SSH_AUTH_SOCK=${FILE}
SSH_AGENT_PID=${PID}
debug_out "Trying ssh-add using vars: SSH_AUTH_SOCK=${SSH_AUTH_SOCK}, SSH_AGENT_PID=${SSH_AGENT_PID}"
SSH_AUTH_SOCK=$SSH_AUTH_SOCK SSH_AGENT_PID=$SSH_AGENT_PID ssh-add -l > /dev/null
if (( $? != 2 ))
then
debug_out "Found agent pid: ${PID}. Binding to it"
export SSH_AUTH_SOCK
export SSH_AGENT_PID
return
fi
debug_out "Skipping pid ${PID}"
done
debug_out "Didn't find an existing ssh-agent to bind. Initializing a new agent"
eval $(ssh-agent) 2>&1 > /dev/null
}