-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
169 lines (139 loc) · 4.38 KB
/
.bashrc
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
[[ -f /etc/bashrc ]] && source /etc/bashrc
[[ -f /etc/bash_completion ]] && source /etc/bash_completion
# Set PATH, MANPATH, etc., for Homebrew.
if [[ $(uname -s) == Darwin* ]];then
eval "$(/opt/homebrew/bin/brew shellenv)"
pinentry=$(echo $(brew --prefix)/bin/pinentry-mac)
gpg=$(echo $(brew --prefix)/bin/gpg)
else
pinentry=$(which pinentry)
gpg=$(which gpg)
gitdiff="/usr/share/git-core/contrib/diff-highlight"
fi
for dir in .cache .gnupg; do
if ! [[ -d ${HOME}/${dir} ]]; then
mkdir -v ${HOME}/${dir}
if [[ "${dir}" == ".gnupg" ]]; then
chmod 700 "${dir}"
fi
fi
done
for file in gpg.conf gpg-agent.conf; do
if ! [[ -f "${HOME}/.gnupg/${file}" ]]; then
echo "creating ${HOME}/.gnupg/${file}"
touch "${HOME}/.gnupg/${file}"
fi
done
if ! grep pinentry-program -q ${HOME}/.gnupg/gpg-agent.conf; then
echo "pinentry-program ${pinentry}" >> ${HOME}/.gnupg/gpg-agent.conf
fi
if ! grep use-agent -q ${HOME}/.gnupg/gpg.conf; then
echo "use-agent" >> ${HOME}/.gnupg/gpg.conf
fi
if ! grep "program = ${gpg}" -q ${HOME}/.gitconfig; then
sed -i "s|\(program =\) .*|\1 ${gpg}|" ${HOME}/.gitconfig
fi
for param in show diff; do
if ! grep -v auto ${HOME}/.gitconfig | grep "${param} = ${gitdiff}$" -q; then
sed -i "s|\(${param} =\)\(?!auto\).*|\1 ${gitdiff}|" ${HOME}/.gitconfig
sed -i "/diff = auto/! s|\(${param} =\) .*|\1 ${gitdiff}|" ~/.gitconfig
fi
done
alias ss='netstat -anvp tcp'
export ANDROID_SDK_ROOT=${HOME}/android/
export ANDROID_HOME=${ANDROID_SDK_ROOT}
export GOPATH=${HOME}/go
export PATH="${ANDROID_SDK_ROOT}/platform-tools/:${PATH}"
export PATH="/usr/share/android-studio/jre/bin/:${PATH}"
export PATH="${HOME}/.gradle/wrapper/dists/gradle-5.4.1-all/3221gyojl5jsh0helicew7rwx/gradle-5.4.1/bin/:${PATH}"
export EDITOR='vim'
export GREP_COLORS='31'
# Magical history handling,
# export HISTTIMEFORMAT="%Y-%m-%d %T "
export HISTFILESIZE=-1
export HISTSIZE=-1
HISTCONTROL=ignoredups:erasedups
shopt -s histappend
function historymerge {
history -n; history -w; history -c; history -r;
}
trap historymerge EXIT
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
# Some aliases.
alias ll='ls -ahlF --color=auto'
alias gvim='gvim -p'
alias dun="du -ah | grep -E \"[0-9]*[0-9][M|G][^a-z|0-9]\" | sort -n"
alias agrep="/usr/bin/grep --color=auto --exclude-dir=.svn --exclude=*.swp --exclude-dir=DEV --exclude-dir=named -ri $1"
alias grep="/usr/bin/grep --color=auto"
alias kssh="export KRB5_TRACE=/dev/stderr; ssh $1"
# Bash completion.
if [[ -t 0 ]]; then # only run if stdin is a terminal
bind "set completion-ignore-case on"
bind "set bell-style none"
bind "set show-all-if-ambiguous on"
bind "set visible-stats on"
complete -d cd rmdir
stty -ctlecho
fi
# Source pureline,
if [[ -f ~/dotfiles/pureline ]]; then
source ~/dotfiles/pureline ~/dotfiles/.pureline.conf
fi
gpg-connect-agent /bye
export GPG_TTY=$(tty)
# Random, kinda not used,
# View HTTP traffic
alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
# Use Git’s colored diff when available
hash git &>/dev/null
if [[ $? -eq 0 ]]; then
diff() {
git diff --no-index --color-words "$@"
}
fi
# Get colors in manual pages
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
check_port(){
local host=${1%:*}
local port=${1#*:}
local colon="${1//[^:]}"
local re_num='^[0-9]+$'
local err=0
if [[ ${#colon} -ne 1 ]];then
echo -e " \n Usage :"
echo -e " check_port addr:port \n"
return
fi
if [[ -z $host ]];then
echo "\n Missing host" && err=1
fi
if [[ ! $port ]]; then
echo "\n Port missing" && err=1
fi
if ! [[ $port =~ $re_num ]];then
echo -e " \n Port invalid, number expected ($port)" && err=1
fi
if [[ $err -ne 0 ]]; then
echo -e " \n Usage :"
echo -e " check_port addr:port \n"
return
fi
(echo > /dev/tcp/$host/$port) >/dev/null 2>&1 \
&& echo "Yes connection." || echo "No connection."
}