-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
145 lines (126 loc) · 3.52 KB
/
zshrc
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Local variables
CURRENT_SOURCE=${1}
DEFAULT_SOURCE=${HOME}/.zshrc_local
DOTFILES_LOC=${DOTFILES}
# LOGIN specific variables
export ZSH=${DOTFILES}/oh-my-zsh
export DEFAULT_LOGIN_ENV=${HOME}/.default_login_env
export DEFAULT_LOGIN_ALIAS=${HOME}/.default_login_alias
export UPDATE_ZSH_FILE=${DOTFILES}/update.zsh
export UPDATE_ZSH_COUNT_FILE=${DOTFILES}/.update_counter
# Check if it is an update or a new session
if [[ ${UPDATE_LOGIN_ENV} != true ]]; then
# Write current environment
export UPDATE_LOGIN_ENV=true
source ${DOTFILES}/write_env.zsh
else
echo "Reset environment"
source ${DOTFILES}/reset_env.zsh
# LOGIN specific variables
export DOTFILES=${DOTFILES_LOC}
export ZSH=${DOTFILES}/oh-my-zsh
export DEFAULT_LOGIN_ENV=${HOME}/.default_login_env
export DEFAULT_LOGIN_ALIAS=${HOME}/.default_login_alias
export UPDATE_LOGIN_ENV=true
export UPDATE_ZSH_FILE=${DOTFILES}/update.zsh
export UPDATE_ZSH_COUNT_FILE=${DOTFILES}/.update_counter
fi
# Check for dotfiles github updates
if [[ -f ${UPDATE_ZSH_COUNT_FILE} ]]; then
update_count=$(cat ${UPDATE_ZSH_COUNT_FILE})
fi
if [[ -z ${update_count} ]]
then
update_count=1
fi
# Layout oh my zsh paths
ZSH_THEME="my_afowler"
ZSH_CUSTOM=${DOTFILES}/oh-my-zsh-custom
# Disable syntax highlighting on clr subnodes
if [[ ${HOSTNAME} =~ 'dn[0-9][0-9]' ]]; then
plugins=(
git
sudo
macos
)
else
plugins=(
git
sudo
macos
zsh-syntax-highlighting
)
fi
ZSH_DISABLE_COMPFIX=true
# Oh my zsh settings
source $ZSH/oh-my-zsh.sh 2>/dev/null
# Load vim alias
if [[ -d "${DOTFILES}/vim-install" ]]; then
for file in ${DOTFILES}/vim-install/*.zsh
do
source $file
done
fi
# Load zsh related settings
if [[ -d "${DOTFILES}/zshrc-settings" ]]; then
for file in ${DOTFILES}/zshrc-settings/*.zsh
do
source $file 2>/dev/null
done
fi
DID_NO_UPDATE=true
#if [[ $((${update_count} % 20)) == 0 ]]; then
# echo $((${update_count}+1)) > ${UPDATE_ZSH_COUNT_FILE}
# echo 'You did not check for updates for several logins: Do you want to check for updates? [y/n]: '
# read input
# if [[ $input == 'y' ]]; then
# source ${UPDATE_ZSH_FILE}
# source ${0} ${CURRENT_SOURCE}
# DID_NO_UPDATE=false
# else
# echo 'Skip update'
# fi
#else
# echo $((${update_count}+1)) > ${UPDATE_ZSH_COUNT_FILE}
#fi
# Source default
if [[ ${DID_NO_UPDATE} = true ]];then
if [[ -f "${DEFAULT_SOURCE}" ]]; then
source ${DEFAULT_SOURCE} ${CURRENT_SOURCE}
fi
fi
# Load the ssh agent
GOT_AGENT=0
for FILE in $(find /tmp/ssh-* -type s -user ${LOGNAME} -name "agent.[0-9]*" 2>/dev/null)
do
SOCK_PID=${FILE##*.}
PID=$(ps -fu${LOGNAME}|awk '/ssh-agent/ && ( $2=='${SOCK_PID}' || $3=='${SOCK_PID}' || $2=='${SOCK_PID}' +1 ) {print $2}')
SOCK_FILE=${FILE}
SSH_AUTH_SOCK=${SOCK_FILE}; export SSH_AUTH_SOCK;
SSH_AGENT_PID=${PID}; export SSH_AGENT_PID;
keys=$(ssh-add -L 2>/dev/null)
if [[ $? != 2 && -n ${PID} ]]
then
GOT_AGENT=1
echo "Agent pid ${PID}"
for key in $(find ${HOME}/.ssh -name '*id_*' -not -name '*.pub')
do
public_key=$(cat ${key}.pub | awk '{ print $2 }')
if ! echo "${keys}" | grep -q "${public_key}"
then
ssh-add ${key}
fi
done
break
fi
#echo "Skipping pid ${PID}"
done
current_host=$(hostname -s)
if [[ ${current_host} == m21003-lin || ${current_host} == markud-t460s ]]
then
if [[ $GOT_AGENT = 0 ]]
then
eval `ssh-agent`
ssh-add
fi
fi