-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
177 lines (147 loc) · 4.62 KB
/
Copy pathbashrc
File metadata and controls
177 lines (147 loc) · 4.62 KB
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
#
# ~/.bashrc
#
bind 'set show-all-if-ambiguous on'
bind 'TAB:menu-complete'
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# FZF fuzzy file search
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# ls colors
LS_COLORS="$LS_COLORS:ow=1;34;47:"
alias ls='ls --color=auto --group-directories-first'
#less
export LESS='-MRi#8j.5'
# |||| `- center on search matches
# |||`--- scroll horizontally 8 columns at a time
# ||`---- case-insensitive search unless pattern contains uppercase
# |`----- parse color codes
# `------ show more information in promp
# grep
alias grep='grep --color --binary-files=without-match --exclude-dir .git'
# git
alias g='git'
complete -o default -o nospace -F _git g
. /usr/share/bash-completion/completions/git 2> /dev/null
# vim
alias v='vim'
# alert
# Show a desktop notification when a command finishes. Use like this:
# sleep 5; alert
function alert() {
if [ $? = 0 ]; then icon=terminal; else icon=error; fi
last_cmd="$(history | tail -n1 | sed 's/^\s*[0-9]*\s*//' | sed 's/;\s*alert\s*$//')"
notify-send -i $icon "$last_cmd"
}
# FZF fuzzy file search
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# ls colors
LS_COLORS="$LS_COLORS:ow=1;34;47:"
alias ls='ls --color=auto --group-directories-first'
#less
export LESS='-MRi#8j.5'
# |||| `- center on search matches
# |||`--- scroll horizontally 8 columns at a time
# ||`---- case-insensitive search unless pattern contains uppercase
# |`----- parse color codes
# `------ show more information in promp
# grep
alias grep='grep --color --binary-files=without-match --exclude-dir .git'
# git
alias g='git'
complete -o default -o nospace -F _git g
. /usr/share/bash-completion/completions/git 2> /dev/null
# vim
alias v='vim'
# alert
# Show a desktop notification when a command finishes. Use like this:
# sleep 5; alert
function alert() {
if [ $? = 0 ]; then icon=terminal; else icon=error; fi
last_cmd="$(history | tail -n1 | sed 's/^\s*[0-9]*\s*//' | sed 's/;\s*alert\s*$//')"
notify-send -i $icon "$last_cmd"
}
# docker
# add ppurge command
docker() {
if [[ $@ == "purge" ]]; then
command docker rm $(docker ps -a -q) && docker rmi $(docker images -q)
else
command docker "$@"
fi
}
# make directory and go there
mkcd() {
mkdir "$@" && cd "$@"
}
# simplified python virtual env mangling
alias lsvenv='ls ~/.venv'
alias unvenv='deactivate'
mkvenv() {
mkdir -p ~/.venv
python3 -m venv ~/.venv/"$1"
}
rmvenv() {
rm -rf ~/.venv/"$1"
}
venv() {
source ~/.venv/"$1"/bin/activate
}
# SETTINGS
# shell history is useful, let's have more of it
export HISTFILESIZE=1000000
export HISTSIZE=1000000
export HISTCONTROL=ignoredups # don't store duplicated commands
shopt -s histappend # don't overwrite history file after each session
# run cnf on unknown command (openSUSE)
export COMMAND_NOT_FOUND_AUTO=1
# let Ctrl-O open ranger, a console file manager (http://nongnu.org/ranger/):
bind '"\C-o":"ranger\C-m"'
# this wrapper lets bash automatically change current directory to the last one
# visited inside ranger. (Use "cd -" to return to the original directory.)
function ranger {
tempfile="$(mktemp)"
/usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}"
test -f "$tempfile" && cd -- "$(cat "$tempfile")"
rm -f -- "$tempfile"
}
# Prompt
# custom virtualenv prompt
export VIRTUAL_ENV_DISABLE_PROMPT=1
virtualenv_info() {
[[ -n "$VIRTUAL_ENV" ]] && echo "(\[\033[0;31m\]${VIRTUAL_ENV##*/}\[\033[0m\])"
}
# custom git prompt
git_info() {
local DIRTY="\[\033[0;31m\]"
local CLEAN="\[\033[0;32m\]"
local UNMERGED="\[\033[0;33m\]"
git rev-parse --git-dir >& /dev/null
if [[ $? == 0 ]]; then
echo -n " "
if [[ `git ls-files -u >& /dev/null` == '' ]]; then
git diff --quiet >& /dev/null
if [[ $? == 1 ]]
then
echo -n $DIRTY
else
git diff --cached --quiet >& /dev/null
if [[ $? == 1 ]]; then
echo -n $DIRTY
else
echo -n $CLEAN
fi
fi
else
echo -n $UNMERGED
fi
echo -n `git branch | grep '* ' | sed 's/..//'`
echo -n "\[\033[0m\]"
fi
}
#PS1='[\u@\h \W]\$ '
set_bash_prompt(){
# PS1="$(virtualenv_info)\[\033[1;35m\]\u\[\033[0m\]@\[\033[1;34m\]\H\[\033[0m\]:\[\033[1;36m\]\w\[\033[0m\]$(git_info)> "
PS1="$(virtualenv_info)\[\033[0;35m\]\u\[\033[0m\]@\[\033[0;34m\]\H\[\033[0m\]:\[\033[0;36m\]\w\[\033[0m\]$(git_info)> "
}
PROMPT_COMMAND=set_bash_prompt