-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc_xeioex
199 lines (163 loc) · 4.79 KB
/
.bashrc_xeioex
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
#! /bin/bash
# FIXME: with checkbashisms
# Bash snippets
# for i in {1..500}; do curl 'url' > /dev/null & done
# Generic routines
function __source-if-exist() {
if [ -f $1 ]; then
. $1
fi
}
function __create-if-not-exist() {
if [ ! -d $1 ]; then
mkdir -p $1 2>/dev/null
fi
}
function __is-exist() {
which $1 2>/dev/null
}
function __dir_is-accessable() {
(cd ${1:?pathname expected} 2>/dev/null) || return
}
# Customization
USERPROFILERC=~/.bashrc_user_profile
__source-if-exist $USERPROFILERC
__source-if-exist ~/.bashrc_private
export PROJECT=$PROJECT
export HOSTIP=$(ip addr|egrep 'inet.*eth0'|egrep -m 1 -o 'inet [0-9]+.[0-9]+.[0-9]+.[0-9]+' | sed 's/inet //')
export ESSENTIALCONFIGS="$USERPROFILERC $ESSENTIALCONFIGS"
#Colors aliases
# Reset
Color_Off="\[\e[0m\]"
Color_OffE="\e[0m"
# Bold Regular Colors
Red="\[\033[1;31m\]"
RedE="\033[1;31m"
Green="\[\033[1;32m\]"
GreenE="\033[1;32m"
Yellow="\[\033[1;33m\]"
YellowE="\033[1;33m"
Blue="\[\033[1;34m\]"
BlueE="\033[1;34m"
Purple="\[\033[1;35m\]"
PurpleE="\033[1;35m"
Cyan="\[\033[1;36m\]"
CyanE="\033[1;36m"
White="\[\033[1;37m\]"
WhiteE="\033[1;37m"
function info-message () {
echo -e "${GreenE}$1${Color_OffE}"
}
function important-message () {
echo -e "${YellowE}$1${Color_OffE}"
}
function warning-message () {
echo -e "${RedE}$1${Color_OffE}"
}
export PS1HOST="$Red $HOSTIP $Color_Off"
if [[ $HOSTIP == $BASEHOSTIP ]]; then
export HOSTIP='HOME'
export PS1HOST="$Green $HOSTIP $Color_Off"
fi
export SHELLRC="~/.bashrc_$USER"
export SHELLCMD="bash --rcfile $SHELLRC -i"
export PS1="$Yellow[\@] $Red\#$Red$PS1HOST$Blue\u@\h$Yellow \w\n$Color_Off\$ "
if [ -n "$(type __git_ps1 2>/dev/null)" ]; then
export PS1="\$(__git_ps1) $PS1"
fi
__create-if-not-exist $WORKSPACE
__create-if-not-exist ~/.gdb
# Sources
__source-if-exist /etc/bashrc
__source-if-exist ~/.cargo/env
__source-if-exist /usr/share/doc/cdargs/examples/cdargs-bash.sh
__source-if-exist /etc/bash_completion
PATH=$PATH:~/bin/
PATH=$PATH:~/bin/depot_tools
PATH=$PATH:~/bin/node-v20.7.0-linux-arm64/bin/
# Aliases
if [[ $TMUX || $EXPALIAS ]]; then
shopt -s expand_aliases #expand aliases in non-interactive shell
fi
alias ss="source $SHELLRC"
# Generic
alias ainstall='sudo apt-get install'
alias asearch='sudo apt-cache search'
alias vim="env --unset=DISPLAY nvim -u ~/.vimrc"
alias ldd='bash ldd'
alias cursor-invisible='tput cinvis'
alias cursor-visible='tput cnorm'
alias reload-ssh-agent='eval `ssh-agent -s`; ssh-add ~/.ssh/nginx_id_rsa'
alias ssh-copy-id='ssh-copy-id -i ~/.ssh/id_rsa.pub'
# Interactive
# It's best if there's no output to stdout from login rc files such as ~/.bash_profile
# or ~/.profile since it can interfere with the proper operation of rsync for example.
if [[ $- == *i* ]]; then
if [ -n "$(__is-exist keychain)" ]; then
keychain -q --eval --agents ssh -Q --quiet id_rsa
fi
# disabling XOFF
if [[ -t 0 ]]; then
stty ixany
stty ixoff -ixon
fi
fi
# TMUX
# reload environment
if [ -n "$(__is-exist tmux)" ]; then
function tmux() {
local tmux=$(type -fp tmux)
case "$1" in
update-environment|update-env|env-update)
local v
while read v; do
echo "processing $v"
if [[ $v == -* ]]; then
v=$(echo "$v" | sed -e 's/=.*//')
unset ${v/#-/}
else
# Add quotes around the argument
v=${v/=/=\"}
v=${v/%/\"}
eval export $v
fi
done < <(tmux show-environment)
;;
*)
$tmux "$@"
;;
esac
}
fi
if [[ -n $PROJECT ]]; then
PROJECTPREFIX="${PROJECT}-"
else
PROJECTPREFIX=""
fi
alias tmux-enter-dev="~/.tmux/${PROJECTPREFIX}dev"
alias tmux-enter-aux="~/.tmux/${PROJECTPREFIX}aux"
alias tmux-kill-dev='tmux kill-session -t dev'
alias tmux-kill-aux='tmux kill-session -t aux'
function vim-enter-session() {
info-message "Running vim..."
vim -S ~/.vimrc
}
function vim-enter-clean-session() {
rm -fr ~/.vim/backups/*; rm -fr ~/.vim/sessions/$USER-$1.vim; vim-enter-session $1
}
# HOST only
if [[ $(hostname) == $BASEHOST ]]; then
alias elecard-open="DISPLAY=:0.0 xtightvncviewer $ELECARD_SERVER"
if [[ $(whoami) == $USER ]]; then
# Interactive
# It's best if there's no output to stdout from login rc files such as ~/.bash_profile
# or ~/.profile since it can interfere with the proper operation of rsync for example.
if [[ $- == *i* ]]; then
if [[ -z $TMUX ]]; then
echo "tmux-enter-dev - to enter development session"
echo "tmux-enter-aux - to enter aux session"
echo "WORKSPACE $WORKSPACE"
fi
fi
fi
fi