-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
218 lines (177 loc) · 3.73 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
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
# .bashrc
## ---------------------
## Environment variables
## ---------------------
export PATH=$PATH:/home/samuel/bin/:/home/samuel/.local/bin/
export SVN_EDITOR=nvim
export EDITOR=nvim
export VISUAL=nvim
export PAGER=less
export SUDO_ASKPASS=/usr/libexec/openssh/ssh-askpass
## ---------------------
## Shell settings
## ---------------------
# Don't put duplicate lines in the history
export HISTCONTROL=ignoredups:erasedups
# append to the history file, don't overwrite
shopt -s histappend
# Increase size of history file
export HISTSIZE=1000
export HISTFILESIZE=2000
# Add timestamps to history
export HISTTIMEFORMAT="%d/%m/%y %T "
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Switch to fish if available
if command -v fish &> /dev/null &&
[[ $(ps --no-header --pid=$PPID --format=comm) != "fish" &&
-z ${BASH_EXECUTION_STRING} ]]
then
shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION=''
exec fish $LOGIN_OPTION
return
fi
function __setprompt() {
#local RED="0;31m"
#local WHITE="0;37m"
local RESET=$(tput sgr0)
local BOLD=$(tput bold)
local BLACK=$(tput setaf 0)
local RED=$(tput setaf 1)
local GREEN=$(tput setaf 2)
local YELLOW=$(tput setaf 3)
local BLUE=$(tput setaf 4)
local MAGENTA=$(tput setaf 5)
local CYAN=$(tput setaf 6)
local WHITE=$(tput setaf 7)
# Set the color for the bash prompt to red if root, else white
#if [ "$(id -u)" == "0" ]; then
# color="$RED"
#else
# color="$WHITE"
#fi
#
#export PS1='\e[${color}[\u@\h \W]\$ \e[m'
export PS1="\n[\[$CYAN\]\$(date %H:%M)\[$RESET\]]\
\[$GREEN\]\u@\h\[$RESET\]: \[$BOLD\]\w\[$RESET\]\n\$ "
}
if [[ $- == *i* ]]; then
__setprompt
fi
# zsh style TAB completion (TAB: next, Shift TAB: prev)
#bind 'set show-all-if-ambiguous on'
#bind 'TAB:menu-complete'
#bind '"\e[Z":menu-complete-backwards'
## ---------------------
## Utility functions
## ---------------------
# Function to set the title of the terminal
function set-title() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$@\a\]"
PS1=${ORIG}${TITLE}
}
svn()
{
case "$1" in
grep)
local flags expr paths
shift
flags=""
expr=""
paths=""
while [ $# -gt 0 ]; do
case "$1" in
"-"*)
flags="$flags $1"
;;
*)
if [ -z "$expr" ]; then
expr="$1"
else
paths="$paths $1"
fi
;;
esac
shift
done
if [ -z "$paths" ]; then
paths="."
fi
(for path in ${paths}; do
/usr/bin/svn ls -R ${path} | grep -v /$ | sed "s@^@${path}/@"
done) | xargs --delimiter "\n" grep --no-messages --color=always ${flags} "${expr}" | less -FR
return $?
;;
cdiff)
shift
if [[ $rev != r* ]]; then
rev="r$1"
fi
shift
svn diff -c "$rev" "$@" svn://svn
return $?
;;
esac
if ! [ -t 1 ]; then
/usr/bin/svn "$@"
return $?
fi
case "$1" in
diff)
/usr/bin/svn "$@" | colordiff | perl /home/samuel/bin/diff-highlight | less -FR
;;
log|blame)
/usr/bin/svn "$@" | less -F
;;
*)
/usr/bin/svn "$@"
;;
esac
return $?
}
git()
{
case "$1" in
rshow)
local svnrev githash
shift
if [ $# -ne 1 ]; then
echo "Please specify a revision number"
return 1
fi
svnrev="$1"
if [[ $svnrev != r* ]]; then
svnrev="r$svnrev"
fi
githash=`git svn find-rev "$svnrev"`
shift
/usr/bin/git show "$githash" "$@"
;;
*)
/usr/bin/git "$@"
;;
esac
return $?
}
## ---------------------
## Aliases
## ---------------------
alias vim="nvim"
alias lf="less --follow-name F"
alias px="ps aux | grep"
alias vecka='date %V'
alias diskspace="du -S | sort -n -r |more"
alias sudo='sudo '
alias untar='tar -xvf'
alias cdc='cd ~/devel/ctc-git'
# git diff for any diff
alias diff="git diff --no-index"
## ---------------------
## Completion
## ---------------------
source /etc/profile.d/bash_completion.sh