-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh_devconfig
111 lines (92 loc) · 3.57 KB
/
zsh_devconfig
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
#!/bin/zsh
############################################################################
## Common configuration #
############################################################################
export PATH_ORG=$PATH
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=-1;32:locus=01:quote=01'
export PATH="$PATH:/usr/local/opt/qt/bin"
# Simple script for network check
[ -x "$(command -v curl)" ] && alias myip='curl ifconfig.co/'
# Check SSL certificate expiry
if [[ -x "$(command -v openssl)" ]]; then
function ssl_expiry() {
function show_usage() {
echo "Usage: ssl_expiry [domain|file] [domain or certificate file path]"
}
if [[ $# -lt 2 ]]; then
show_usage
return 1
fi
local type="$1"
local target="$2"
local expiration_date
if [[ "${type}" == "domain" ]]; then
expiration_date=$(echo | openssl s_client -connect "${target}:443" -servername "${target}" -in 2>/dev/null | openssl x509 -noout -enddate | awk -F '=' '{print $2}')
elif [[ "${type}" == "file" ]]; then
local cert_path="${target}"
expiration_date=$(openssl x509 -enddate -noout -in "${cert_path}" | awk -F '=' '{print $2}')
else
show_usage
return 1
fi
local expiration_timestamp=$(date -d "${expiration_date}" "+%s")
if [[ "${expiration_timestamp}" -lt $(date +%s) ]]; then
echo "The certificate has already expired. it was valid till: ${expiration_date}"
else
echo "The certificate is valid till: ${expiration_date}"
fi
}
fi
# Generate Openstack Token only
[ -x "$(command -v openstack)" ] && alias os_token='openstack token issue --column id --format value'
# Enable direnv hook
[ -x "$(command -v direnv)" ] && eval "$(direnv hook zsh)"
# Enable nvm
## Set NVM directory
[ -z "$NVM_DIR" ] && [ -z "${XDG_CONFIG_HOME-}" ] \
&& export NVM_DIR="$HOME/.nvm"
## Load nvm.sh from available lists
[ -z "$NVM_SH" ] && [ -s "$NVM_DIR/nvm.sh" ] \
&& export NVM_SH="$NVM_DIR/nvm.sh"
[ -z "$NVM_SH" ] && [ -s "/usr/share/nvm/nvm.sh" ] \
&& export NVM_SH="/usr/share/nvm/nvm.sh"
[ -z "$NVM_SH" ] && [ -s "/usr/local/opt/nvm/nvm.sh" ] \
&& export NVM_SH="/usr/local/opt/nvm/nvm.sh"
[ -s "$NVM_SH" ] && source "$NVM_SH" && unset NVM_SH
# Load nvm bash complettion from available lists
[ -z "$NVM_SCPL" ] && [ -s "$NVM_DIR/bash_completion" ] \
&& export NVM_SCPL="$NVM_DIR/bash_completion"
[ -z "$NVM_SCPL" ] && [ -s "/usr/share/nvm/bash_completion" ] \
&& export NVM_SCPL="/usr/share/nvm/bash_completion"
[ -z "$NVM_SCPL" ] && [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] \
&& export NVM_SCPL="/usr/local/opt/nvm/etc/bash_completion.d/nvm"
[ -s "$NVM_SCPL" ] && source "$NVM_SCPL" && unset NVM_SCPL
# change go envvironment
[ -x "$(command -v go)" ] && [ -z "$GOROOT" ] \
&& export GOROOT="$(go env GOROOT)"
[ -d $GOROOT ] && [ -d "$HOME/Workspace/go" ] \
&& export GOPATH="$HOME/Workspace/go" && export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
# add environment script sourcing function
export ENV_DIR="$HOME/Workspace/.envscripts"
function loadenv() {
local env_dir=${ENV_DIR:-$HOME/.env}
local file=$1
local args=("${@:2}")
source "$env_dir/$file" "${args[@]}"
}
function _loadenv_complete() {
local env_dir=${ENV_DIR:-$HOME/.env}
local search_dir=${1:-$env_dir}
local env_files=(${(f)"$(find $search_dir -name '*.env' -o -name '*.rc' -o -name '*.sh')"})
local completions=()
for file in ${env_files[@]}; do
if [[ ${file#$env_dir/} == $words[CURRENT]* ]]; then
completions+=("${file#$env_dir/}")
fi
done
compadd -a completions
}
compdef _loadenv_complete loadenv
# Reset exit code to 0 for this script
# (Short-circuit condition check & apply may change exit code)
true