-
Notifications
You must be signed in to change notification settings - Fork 1
/
.bash_custom
192 lines (158 loc) · 5.28 KB
/
.bash_custom
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
# -*- mode: sh; -*-
# TODO: git custom
# TODO: max promt size /home/foo/.../bar/bax
# TODO: look into cool PS1 alternatives
# TODO: eix colors https://projects.gentooexperimental.org/eix/wiki/FAQ
# TODO: PIPESTATUS http://www.jonno.org/drupal/node/4
# https://blogs.gentoo.org/mgorny/2011/10/18/027-umask-a-compromise-between-security-and-simplicity/
# -rw-r-----
umask 027
# Include local ~/bin in PATH, and local python bin
PATH=~/bin/:~/.local/bin:$PATH
PATH=~/.cargo/bin:$PATH
# Enable history appending instead of overwriting. #139609
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# ** pattern
shopt -s globstar
# Make sure this is sourced
export INPUTRC='~/.inputrc'
# Switch to be likes emacs
bind '\C-w:backward-kill-word'
bind 'Meta-Rubout: unix-word-rubout'
export EDITOR='emacs -nw'
export SVN_EDITOR=$EDITOR
export GIT_EDITOR=$EDITOR
export HISTCONTROL=ignoreboth
export HISTSIZE=32768
export HISTFILESIZE=32768
export HISTTIMEFORMAT='%Y-%m-%d_%H:%M:%S '
export PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
export PAGER='less'
export LESS="-R -M --shift 5"
unset LESSOPEN
# aliases
alias ll='ls -lh'
alias mkdir='mkdir -p'
alias du='du -h'
alias py='python'
alias ipy='ipython --profile csb'
alias e='emacs'
alias ec='emacsclient -t --alternate-editor=""'
alias nano='nano -w'
alias grep='grep --color '
alias fgrep='fgrep --color'
alias egrep='egrep --color'
alias epoch='date +%s'
# from: https://unix.stackexchange.com/questions/32182/simple-command-line-http-server
alias webshare='python3 -m http.server'
# made up commands
mkcd() {
mkdir $1 && cd $1
}
# cd directly to a dir and list contents
cdls() {
if [ "$1" ]
then builtin cd "$1" && ll
else builtin cd && ll
fi
}
if [[ -f /etc/gentoo-release ]] ; then
explainuseflag() {
sed -ne "s,^\([^ ]*:\)\?$1 - ,,p" \
/usr/portage/profiles/use.desc \
/usr/portage/profiles/use.local.desc
}
fi
# http://www.shell-fu.org/lister.php?id=375
function extract() {
ee() { # echo and execute
echo "$@"
$1 "$2"
}
for x in "$@"; do
[[ -f $x ]] || continue
case "$x" in
*.tar.bz2 | *.tbz2 ) ee "tar xvjf" "$x" ;;
*.tar.gz | *.tgz ) ee "tar xvzf" "$x" ;;
*.bz2 ) ee "bunzip2" "$x" ;;
*.rar ) ee "unrar x" "$x" ;;
*.gz ) ee "gunzip" "$x" ;;
*.tar ) ee "tar xvf" "$x" ;;
*.zip | *.jar ) ee "unzip" "$x" ;;
*.Z ) ee "uncompress" "$x" ;;
*.7z ) ee "7z x" "$x" ;;
esac
done
}
# .. - Does a 'cd ..'
# .. 3 - Does a 'cd ../../..'
# http://www.shell-fu.org/lister.php?id=550
function .. (){
local arg=${1:-1};
while [ $arg -gt 0 ]; do
cd .. >&/dev/null;
arg=$(($arg - 1));
done
}
# other
bind "set completion-ignore-case on"
# does not seem to work
function common { history | awk '{print $9}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail -n 20 | sort -nr ;}
# git stuff
source ~/.config/git-prompt.sh
export TWO_LINE_PROMT=0
export PROMPT_COMMAND=__prompt_command
function __prompt_command() {
local EXIT="$?"
PS1=""
# heuristics for switching to two line promt
MAX_PATH_LEN=$(($COLUMNS / 2))
if [[ $MAX_PATH_LEN -gt 120 ]]; then
MAX_PATH_LEN=120
fi
local NoColor='\[\e[0m\]'
local BlueBold='\[\e[1;34m\]';
local GreenBold='\[\e[1;32m\]';
local RedBold='\[\e[1;31m\]';
local YellowLight='\[\e[0;93m\]';
local USER_AT_DIR="${GreenBold}\u@\h ${BlueBold}\w${NoColor}"
local GIT_PROMT='$(__git_ps1 " (%s)")'
local SUFFIX="${BlueBold} \$${NoColor} "
# https://unix.stackexchange.com/questions/570419/python-venv-module-cannot-add-virtual-environment-name-to-ps1-when-using-prompt
local VENV=""
if [ -n "${VIRTUAL_ENV}" ] && [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ]; then
VENV="(`basename \"$VIRTUAL_ENV\"`) "
fi
if [[ $EXIT -gt 0 ]]; then
# Tried (Explosion U+1F4A5 💥) but it makes things wonky
PS1+="${RedBold}${EXIT}${NoColor} "
fi
if [[ $(command jobs 2>/dev/null) ]]; then
PS1+="${YellowLight}[\j] "
fi
PS1+="${NoColor}${VENV}"
PS1+=${USER_AT_DIR}
PS1+="${BlueBold}$GIT_PROMT${NoColor}"
if [[ $TWO_LINE_PROMT -gt 0 ]] || [[ ${#PWD} -gt $MAX_PATH_LEN ]]; then
PS1+="\n"
fi
PS1+=$SUFFIX
}
# http://linuxtidbits.wordpress.com/2009/03/23/less-colors-for-man-pages/
# Less Colors for Man Pages
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
### http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
# ~sigh~
# better to add to /etc/profile.d/fix-scrollbars.sh
export GTK_OVERLAY_SCROLLING=0
# https://debbugs.gnu.org/cgi/bugreport.cgi?bug=15154#11
export NO_AT_BRIDGE=1