-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc.symlink
executable file
·247 lines (204 loc) · 7 KB
/
bashrc.symlink
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# Change history Size
export HISTORY=3000
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+:}ignoredups
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
# Colors
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
LIME_YELLOW=$(tput setaf 190)
YELLOW=$(tput setaf 3)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
EDITOR=`which vim`
screen_set_window_title () {
local HPWD="$PWD"
case $HPWD in
$HOME) HPWD="~";;
$HOME/*) HPWD="~${HPWD#$HOME}";;
esac
printf '\ek%s\e\\' "$(basename "$HPWD")"
}
# /etc/bash_completion.d/git-prompt
# https://git-scm.com/book/pl/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Bash
export GIT_PS1_SHOWDIRTYSTATE=1
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}${GREEN}\u@\h${NORMAL}|${POWDER_BLUE}k8s:$(kubectl config current-context|xargs -r basename)${NORMAL}|${YELLOW}aws:${AWS_PROFILE}${NORMAL}|:${CYAN}\w${NORMAL}${RED}$(__git_ps1)${NORMAL}\n\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h|:\w$(__git_ps1)\n\$ '
fi
unset color_prompt
# FIXME: Make this be the case only if the window has no explicit title
# case "$TERM" in
# screen-bce)
# PS1='$(screen_set_window_title)'$PS1
# ;;
# esac
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# Enable programmable completion features
# This is enabled for login shells usually with /etc/profile.d/bash_completion.sh
# Since profile is sourced before bashrc here we might end having
# the bash completion scripts sourced already.
# It seems to be a bug with wheezy if we source it twice so here
# we mimic both profile.d and bash.bashrc behaviors
if [ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION_COMPAT_DIR" ]; then
:;
elif ! shopt -oq posix && shopt -q progcomp; then
if [ -r /usr/share/bash-completion/bash_completion ]; then
# Source completion code.
. /usr/share/bash-completion/bash_completion
elif [ -r /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
# Private bashrc
if [ -f ~/.private/bashrc ]; then
. ~/.private/bashrc
fi
# VirtualEnvWrapper
# pip install virtualenvwrapper
WORKON_HOME=~/venv
if [ -f /usr/share/virtualenvwrapper/virtualenvwrapper.sh ]; then
. /usr/share/virtualenvwrapper/virtualenvwrapper.sh
fi
export EDITOR=vim
# Prefer the classical middle-click/paste
# https://wiki.archlinux.org/index.php/Pass
export PASSWORD_STORE_X_SELECTION=primary
# https://gist.github.com/thomasdarimont/46358bc8167fce059d83a1ebdb92b0e7
decode_base64_url() {
local len=$((${#1} % 4))
local result="$1"
if [ $len -eq 2 ]; then result="$1"'=='
elif [ $len -eq 3 ]; then result="$1"'='
fi
echo "$result" | base64 -d
}
decode_jwt(){
decode_base64_url $(echo -n $2 | cut -d "." -f $1) | jq .
}
# Decode JWT header
alias jwth="decode_jwt 1"
# Decode JWT Payload
alias jwtp="decode_jwt 2"
epoch2date() {
ts=$1
date --iso-8601=sec -u -d @$ts
}
date2epoch() {
ts="$*"
date --date="$ts" +"%s"
}
export PDSH_GENDERS_FILE=~/.pdsh/genders
export PDSH_RCMD_TYPE=ssh
export PATH=$PATH:~/scripts
export GOWORK=off
get_random_port() {
read lower upper < /proc/sys/net/ipv4/ip_local_port_range
# XXX: Hope we get lucky and it is unused...
port=$(shuf -n1 -i ${lower}-${upper})
echo ${port}
}
socks() {
host=$1
port=$(get_random_port)
workdir=$(mktemp -d --tmpdir socks.XXXX)
logfile=${workdir}/ssh.log
socket=${workdir}/ssh-control-socket
ssh -vvv -o ControlMaster=yes -E ${logfile} -NfS ${socket} -D ${port} ${host} || tail ${logfile}
echo socks://127.0.0.1:${port}
}
chromeproxy() {
proxy=$1
workdir=$(mktemp -d --tmpdir chrome.XXXX)
chrome=$(which chrome || which google-chrome || echo "/opt/google/chrome/chrome")
${chrome} \
--incognito \
--user-data-dir=${workdir} \
--proxy-server=${proxy} \
--enable-logging=stderr \
--dns-prefetch-disable \
--v=1
rm -rfv ${workdir}
}
socksproxy() {
port=$1
http_proxy=socks5://127.0.0.1:${port}
https_proxy=socks5://127.0.0.1:${port}
no_proxy=127.0.0.1,localhost
HTTP_PROXY=$http_proxy
HTTPS_PROXY=$https_proxy
NO_PROXY=$no_proxy
export http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY
}
noproxy() {
unset http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY
}
proxy() {
printenv | grep -i proxy
}
docker-login-ecr() {
AWS_ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
AWS_REGION=$(aws configure get region)
aws ecr get-login-password | docker login --username AWS --password-stdin ${AWS_ACCOUNT?}.dkr.ecr.${AWS_REGION?}.amazonaws.com
}
aws-ec2-describe-instances() {
aws ec2 describe-instances \
--query 'Reservations[].Instances[].{ID:InstanceId, Name:Tags[?Key==`Name`]|[0].Value, Cluster:Tags[?Key==`eks:cluster-name`]|[0].Value, Owner:Tags[?Key==`Owner`]|[0].Value, State:State.Name}'\
--output table
}
redsocks-docker() {
# This is the default docker network for docker0 bridge
network=${1?}
proxy_address=${2?}
proxy_port=${3?}
network_id=$(docker network inspect -f {{.Id}} $network)
[[ -z "${network_id}" ]] && echo Network not found && return
bridge=$(docker network inspect -f '{{index .Options "com.docker.network.bridge.name"}}' $network)
[[ -z "$bridge" ]] && bridge="br-${network_id:0:12}"
name=redsocks-$network
echo Starting docker container $name for bridge $bridge using proxy $proxy_address:$proxy_port...
docker run -d --rm --name ${name?} --restart=no --privileged=true --net=host -e DOCKER_NET=${bridge?} ncarlier/redsocks:latest ${proxy_address?} ${proxy_port?}
}