]> code.delx.au - dotfiles/blob - .bashrc
d12bc4ea64dcefa1fbc0406517910f87d6f600e0
[dotfiles] / .bashrc
1 # Run when a random bash is started. This is always run after the login
2 # shell. It sets up the shell to have a nice prompt and xterm titlebar, etc.
3 # It should NOT set any environment variables like the PATH.
4 # Copy this around to all your machines and make machine specific
5 # customisations to ~/.bashrc_local
6
7 # Run .bash_profile if logging in from ssh
8 [ ${RUN_BASH_PROFILE:-0} -eq 1 -a -f ~/.bash_profile ] && source ~/.bash_profile && return
9
10 # If not running interactively do nothing
11 [ -z "$PS1" ] && return
12
13 # Terminals that we want coloured prompts in
14 [ -n "$COLORTERM" ] && PS1_COLOR=1
15 [ "$TERM" = "linux" ] && PS1_COLOR=1 && DARK=1
16 [ "$TERM" = "screen" ] && PS1_COLOR=1
17 [ "$TERM" = "xterm" ] && PS1_COLOR=1
18 [ "$TERM" = "xterm-color" ] && PS1_COLOR=1
19 [ "$TERM" = "rxvt" ] && PS1_COLOR=1
20 [ "$TERM" = "rxvt-unicode" ] && PS1_COLOR=1
21
22 # Use colours appropriate to a light on dark terminal, we can autodetect
23 # this for some terminals, for others we define it above.
24 if [ -n "$COLORFGBG" ]; then
25 FGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 1)
26 BGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 3)
27 if [ "$FGCOLOR" -gt "$BGCOLOR" ]; then
28 DARK=1
29 fi
30 unset FGCOLOR
31 unset BGCOLOR
32 elif [ ${DARK:-0} -eq 0 ]; then
33 export COLORFGBG="0;default;15"
34 elif [ ${DARK:-0} -eq 1 ]; then
35 export COLORFGBG="15;default;0"
36 fi
37
38 # Set the prompt colour, and the colors for the 'ls' command appropriately,
39 # depending on the background of the terminal.
40 if [ ${PS1_COLOR:-0} -eq 1 ]; then
41 if [ ${DARK:-0} -eq 0 ]; then
42 LS_COLORS="no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35"
43 PS1='\[\033[31m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[00m\]\$ '
44 else
45 LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
46 PS1='\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
47 fi
48
49 export LS_COLORS
50 unset PS1_COLOR
51 unset DARK
52 else
53 PS1='\u@\h:\w\$ '
54 fi
55
56 function DARKTERM {
57 unset COLORFGBG
58 DARK=1 && source ~/.bashrc
59 }
60
61 # xterm titlebar displays current command
62 case "$TERM" in
63 xterm*|rxvt*)
64 HOSTNAME="$(hostname | cut -d '.' -f 1)"
65 CWD_WITHHOME='"$(echo "$PWD" | sed "s|^$HOME|~|")"'
66 PROMPT_COMMAND="echo -ne \"\033]0;${HOSTNAME}: ${CWD_WITHHOME}\007\""
67 ;;
68 *)
69 ;;
70 esac
71
72 # Useful aliases
73 alias ls='ls --color=auto'
74 alias ll='ls -hlF'
75 alias la='ls -ha'
76 alias l='ls -halF'
77 alias rm='rm -i'
78 alias less='less -R'
79 alias screen='TERM=xterm screen'
80
81 shopt -s checkwinsize
82
83 # Local customisations
84 [ -r ~/.bashrc_local ] && source ~/.bashrc_local
85