-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotbashrc
134 lines (113 loc) · 3.52 KB
/
dotbashrc
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
#!/bin/bash
### This top part should be POSIX sh compatible, so that we can source
### it non-interactively and get our path
shell="$(ps -p $$ -o comm | sed '1d; s/^-//; s/ *$//')"
prepend_path () {
old_ifs="$IFS"
IFS=:
while [ -n "$1" ]; do
for path in $PATH; do
[ "$path" = "$1" ] && shift && continue 2;
done;
PATH="$1:$PATH"
done;
IFS="$old_ifs"
}
prepend_path $HOME/local/bin $HOME/scripts
# Only continue if we're interactively running bash
[ -z "$PS1" ] || [ "$shell" != "bash" ] && return
### end of POSIX compatibility
# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
# 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 "$(lesspipe)"
# set a fancy prompt
case $TERM in
dumb)
;;
*)
c_bright='\[\e[1m\]'
c_yellow='\[\e[0;33m\]'
c_green='\[\e[0;32m\]'
c_blue='\[\e[0;34m\]'
c_red='\[\e[0;31m\]'
c_nc='\[\e[0m\]'
;;
esac
[ $EUID = 0 ] && c_user=$c_red || c_user=$c_green
[ "$SSH_CLIENT" ] && c_host=$c_green$c_bright || c_host=$c_green
__jobcount () {
local stopped=$(jobs -s | wc -l)
local result=" "
[ $stopped -gt 0 ] && result="$result($stopped) "
echo "$result"
}
__shorten () {
local max=$(($COLUMNS/4))
local result="$@"
[[ $result == $HOME* ]] && result="~${result#$HOME}"
local offset=$(( ${#result} - $max + 3 ))
[ $offset -gt 0 ] && result="...$(echo ${result:$offset:$max} | sed 's/[^/]*//')"
echo $result
}
_user="${c_user}\u"
_host="${c_host}@\h"
_jobs="${c_yellow}"'$(__jobcount)'
_cwd='$([ -w "$PWD" ]'" && echo '$c_blue' || echo '$c_red')"'$(__shorten \w)'
_prompt=" ${c_blue}"'\$'" ${c_nc}"
PS1="${_user}${_host}${_jobs}${_cwd}${_prompt}"
unset c_yellow c_green c_brightgreen c_blue c_red c_nc _user _host _cwd _prompt
# Change the window title of X terminals
case $TERM in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${PWD/$HOME\//~/} ($TERM)\007"'
;;
screen)
PROMPT_COMMAND='echo -ne "\033_${PWD/$HOME\//~/} ($TERM)\033\\"'
;;
esac
# disable XON/XOFF (c-s should search, not pause)
stty -ixon
# programmable completion
if [ -r /etc/bash_completion ]; then
. /etc/bash_completion
elif [ -r ~/.bash_completion ]; then
. ~/.bash_completion
fi
# readline behaviour
bind "set bell-style none"
bind "set show-all-if-unmodified on"
bind "set visible-stats on"
if which dircolors >/dev/null; then
# Enable colors for ls, etc.
[ -e ~/.dir_colors ] || dircolors -p >~/.dir_colors
eval `dircolors -b ~/.dir_colors`
fi
isgnu () {
[[ "$($1 --version 2>/dev/null | head)" == *GNU* ]] && return 0
return 1
}
# Alias definitions.
isgnu ls && alias ls="ls --color=auto" || alias ls="ls -F"
alias ll="ls -l"
alias la="ls -A"
alias l="ls -Al"
isgnu grep && alias grep="grep --color=auto"
alias psu="ps -U $USER"
alias enscript="enscript -2rE"
alias lpr="lpr -h"
alias vncviewer='vncviewer -shared'
export EDITOR="emacsclient -t -a emacs"
export VISUAL=$EDITOR
export PAGER="less"
export LESS="-FRX"
# some machines lack rxvt-unicode in their terminfo db, so we bring
# our own db
[ -d ~/.terminfo ] && export TERMINFO=~/.terminfo
# similarly, some boxes have archaic programs which still use termcap
export TERMCAP=$(infocmp -C 2>/dev/null | sed '/^#/d')
# we want to know our fortune
which fortune 2>/dev/null >/dev/null && fortune