]> code.delx.au - dotfiles/blob - .bash/interactive
terminal title for man pages
[dotfiles] / .bash / interactive
1 #! bash
2
3 # Check for unsupported TERM variable
4 if ! tput init &> /dev/null; then
5 echo "Warning! TERM=$TERM unsupported, using TERM=xterm"
6 export TERM=xterm
7 fi
8
9
10
11 # Fancy PS1 with revision control status for git, hg, svn
12
13 [ -r /usr/share/git/completion/git-prompt.sh ] && source /usr/share/git/completion/git-prompt.sh
14 function my_git_ps1 {
15 find_up_recurse .git || return
16 GIT_PS1_SHOWDIRTYSTATE=1 \
17 GIT_PS1_SHOWUNTRACKEDFILES=1 \
18 __git_ps1 2> /dev/null
19 }
20
21 function my_hg_ps1 {
22 find_up_recurse .hg || return
23 b="$(hg branch 2>/dev/null)" || return
24 s="$(hg status | cut -c1 | sort -u | tr -d " \n")"
25 echo -n " ($b"
26 [ -n "$s" ] && echo -n " $s"
27 echo -n ")"
28 }
29
30 function my_svn_ps1 {
31 find_up_recurse .svn || return
32 s="$(svn status --ignore-externals 2>/dev/null | cut -c1 | sort -u | tr -d " \n")"
33 [ -z "$s" ] && return
34 echo -n " ($s)"
35 }
36
37 if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
38 debian_chroot=$(cat /etc/debian_chroot)
39 fi
40 PS1='${debian_chroot:+($debian_chroot)}'
41 PS1="$PS1"'\[\033[00;31m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]'
42 PS1="$PS1"'\[\033[00;36m\]$(my_git_ps1 ; my_hg_ps1 ; my_svn_ps1)\[\033[00m\]'
43 PS1="$PS1"'\n\$ '
44
45
46
47 # Display return codes on error
48 function print_exit_code {
49 _exit_msg="\033[01;33mexit code: $?\033[00m"
50 if [ -z "${BASH_SOURCE[1]}" ]; then
51 echo -e "$_exit_msg"
52 fi
53 unset _exit_msg
54 }
55 trap print_exit_code ERR
56
57
58
59 # ls colours
60 eval $(TERM=xterm dircolors 2> /dev/null)
61
62 if [ "${DARKTERM:-1}" -eq 1 ]; then
63
64 # Sets colour scheme in apps like Vim
65 export COLORFGBG="15;0"
66
67 # Bold ls colours
68 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/00;/01;/g')"
69 LSCOLORS="ExFxCxDxBxEGEDABAGACAD" # BSD ls
70 PS1="$(echo "${PS1}" | sed 's/00;/01;/g')"
71
72 else
73
74 # Sets colour scheme in apps like Vim
75 export COLORFGBG="0;15"
76
77 # Unbold ls colours
78 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/01;/00;/g')"
79 LSCOLORS="exfxcxdxbxegedabagacad" # BSD ls
80 fi
81
82
83 # xterm titlebar displays 'hostname:workingdir'
84 if tput hs || tput tsl &> /dev/null; then
85 PROMPT_COMMAND='tput tsl; echo -n "$(hostname| cut -d. -f1):${PWD/$HOME/~}"; tput fsl;'
86 fi
87
88 # screen window displays current command
89 case "${TERM}" in
90 screen*)
91 PROMPT_COMMAND="$PROMPT_COMMAND echo -ne '\033k\033\\'"
92 ;;
93 esac
94
95 # Useful aliases
96 alias ls='ls --color=auto'
97 alias ll='ls -hlF'
98 alias la='ls -ha'
99 alias l='ls -halF'
100 alias f='find . -iname'
101 alias webshare='python3 -mhttp.server'
102 alias rm='rm -i'
103 alias less='less -R'
104 alias grep='grep --color=auto --exclude "*.svn-base"'
105 alias scp='scp -o ControlPath=none'
106 alias bc='bc -ql'
107 alias vv='vncviewer -encodings "tight hextile copyrect"'
108 alias watch='watch -n1'
109 alias sudo='sudo ' # ability to use aliases with sudo
110 alias sudosu='sudo su -l -s /bin/bash'
111 alias _psresources='ps -weo pid,user:16,%cpu,%mem,stat,start_time,bsdtime,args'
112 alias pscpu='_psresources --sort -%cpu|less -S'
113 alias psmem='_psresources --sort -%mem|less -S'
114 alias pstree='ps --forest -weo pid,user:16,args --sort start_time|less -S'
115 alias pstime='ps -weo pid,user:16,lstart,args --sort start_time|less -S'
116
117
118 # Super man!
119 # Colourful headings
120 # Terminal title
121 function man {
122 tput tsl; echo "man $@"; tput fsl
123
124 env \
125 LESS_TERMCAP_md=$'\E[01;38;5;74m' \
126 LESS_TERMCAP_me=$'\E[0m' \
127 LESS_TERMCAP_us=$'\E[04;38;5;146m' \
128 LESS_TERMCAP_ue=$'\E[0m' \
129 man "$@"
130 }
131
132 # Usage: mcd somedir
133 # Creates the directory if it doesn't exist, and changes into it
134 function mcd {
135 mkdir -p "${1}" &&
136 cd "${1}"
137 }
138
139 # Usage: vimf somefile
140 # Does a recursive search of the current directory for somefile, then edits it
141 function vimf {
142 find . -iname "${1}" -exec vim '{}' +
143 }
144
145 # Sets the nice and ionice priorities for the current shell to the lowest values
146 function slowshell {
147 ionice -c 3 -p $$
148 renice -n 19 -p $$
149 }
150
151
152 # Bash should check the terminal size after every command terminates
153 shopt -s checkwinsize
154
155 # Don't attempt to tab-complete an empty line
156 shopt -s no_empty_cmd_completion
157
158
159
160 # Local customisations
161 [ -r "${HOME}/.bash/interactive_local" ] && source "${HOME}/.bash/interactive_local"
162
163 # Load bash completion if available
164 [ -r "/etc/bash_completion" ] && source "/etc/bash_completion"
165