These were in my .bashrc at some point, or I put them in scripts, or what not. Now they're here.
# An example of a bash function which kills a particular process, in this case one with "xp -grabtime" in its name.
function killrsi {
kill -9 $(ps -ux | grep 'xp -grabTime' | awk '/.*/{print $2}')
}
Some more useful scripts can be found in this file: moreusefulscripts.rar
They include a reasonably good word counter for tex files, better than detex anyway, a file which will help you set up your ssh keys so you don't always have to type in your password every time and bcalc, which lets you do maths from the bash prompt. Kinda like Google but not in a web browser.
It's good, it works, it's customised for me. If you want to use it you will need to change some things in it, but if you're anything like me you don't get a good .bashrc file (or a good .emacs file or anything else like that) by starting from scratch and writing your own. Instead you just hack it together, copying and pasting scraps from other people in and modifying it.
Oh, and for the record - this .bashrc did triple duty, cygwin on my laptop, NetBSD at my old university and Fedora at Oxford, so not all of it works at each place, some of it doesn't work anywhere and when I move it to a new machine I mostly just comment bits out and otherwise hack it up.
EDIT: Actually, it dates from the university I started my undergrad at, so some of it could be well redundant - they ran some version of Linux, I forget which, then it got ported to NetBSD etc. It's been around :)
# System wide functions and aliases
# Environment stuff goes in /etc/profile
if [ -z "$PROFILE_LOADED" -a -e /etc/profile ]; then
. /etc/profile
fi
# Set no group or world access by default.
umask 077
# Mod history - don't keep consecutive duplicates, bg, fg or exit's,
# make it work if I have multiple shells open
export HISTIGNORE="&:[bf]g:exit"
export HISTSIZE=8000
export HISTFILESIZE=8000
export HISTCONTROL=erasedups # don't keep any duplicates...
export PROMPT_COMMAND='history -a'
# Some useful variables to make SSH etc easier
export MCSNS='USER@HOST - they're all like this'
export OXMNS='^^^^^^^'
export OXLNS='^^^^^^'
export PHILNS='^^^^^^'
# prevent huge coredumps
ulimit -c 0
export PATH=$PATH:~/bin:/cygdrive/c/Program\ Files/graphviz-2.12/bin:/cygdrive/c/Program\ Files/Java/jdk1.6.0_02/bin
export PYTHONPATH=~/bin
unset PROFILE_LOADED
# Global Aliases.
alias hs='history | grep $1'
alias ls='ls -lAF --color=auto'
alias df='df -h'
alias du='du -h'
alias sweep='rm -f *.aux *.bbl *.bak *.dvi *.log *.blg .*~ *.toc *.lot *.lof *.loa *~ \#*'
alias mcs="ssh $MCSNS "
alias mcsx="ssh -X $MCSNS"
alias oxm="ssh $OXMNS "
alias oxmx="ssh -X $OXMNS "
alias oxl="ssh $OXLNS "
alias oxlx="ssh -X $OXLNS "
# SVN Stuff
export SVN_EDITOR=emacs
export SVN_ROOT=svn+ssh:///users/chrf/svn-repo
#export SVN_ROOT=file:///home/Christo/svn-repo
# Prompt stuff.
# set_clock is not currently used, so comment it out for effiecency/error prevention
#function set_clock {
# # prompt_x is where to position the cursor to write the clock
# let prompt_x=$(tput cols)-6
# tput sc
# tput cup 0 ${prompt_x}
# tput setaf 4 ; tput bold
# echo -n "["
# tput setaf 1
# echo -n "$(date +%H%M)"
# tput setaf 4 ; tput bold
# echo -n "]"
# tput rc
#}
function set_prompt {
# Define Colours:
local CYAN="\[\033[0;36m\]" # For the pwd
local LIGHT_GRAY="\[\033[0;37m\]"
local LIGHT_GREEN="\[\033[1;32m\]" # For the connection type - SSH
local NO_COLOUR="\[\033[0m\]"
local PURPLE="\[\033[1;35m\]" # For the connection type - telnet
local RED="\[\033[1;31m\]" # For user type - root
local WHITE="\[\033[1;37m\]" # For user type - non-root
local YELLOW="\[\033[1;33m\]" # For the time
local BLUE="\[\033[1;34m\]" # For the connection type - local
# Currently Unused Colours:
local GRAY="\[\e[1;30m\]"
local GREEN="\[\033[0;32m\]"
local BROWN="\[\033[0;33m\]"
local LIGHT_CYAN="\[\033[1;36m\]"
# Build the clock/time this prompt was generated:
#local CLOCK="$YELLOW$(date +%H%M)$LIGHT_GRAY"
# Assemble full, colour-coded path to pwd
if [ "${PS1+set}" = set ]; then
#local CURDIR='${PWD}' # Replaces ~ with real path
local CURDIR='\w' # Uses ~ rather than full path
local DIR="$CYAN\[\]$CURDIR\[\]$NO_COLOUR"
fi
# Assemble username and host, colour code by name and connection type:
# Many thanks to the Bash Prompt Howto :)
# User Name:
# Red for root
# White for user logins
# Host Name:
# Green for ssh connection
# Purple for telnet connection
# Blue for local connection
# Figure out how we are connected:
#local THIS_TTY=tty`ps aux | grep $$ | grep bash | awk '{ print $7 }'`
#local SESS_SRC=`who | grep $THIS_TTY | awk '{ print $6 }'`
SSH_FLAG=0
SSH_IP=`echo $SSH_CLIENT | awk '{ print $1 }'`
if [ $SSH_IP ] ; then
SSH_FLAG=1
fi
SSH2_IP=`echo $SSH2_CLIENT | awk '{ print $1 }'`
if [ $SSH2_IP ] ; then
SSH_FLAG=1
fi
if [ $SSH_FLAG -eq 1 ] ; then
CONN=ssh
elif [ -z $SESS_SRC ] ; then
CONN=lcl
elif [ $SESS_SRC = "(:0.0)" -o $SESS_SRC = "" ] ; then
CONN=lcl
else
CONN=tel
fi
# Assemble Hostname String:
if [ $CONN = ssh ] ; then
HOST="$LIGHT_GREEN\h$NO_COLOUR"
elif [ $CONN = lcl ] ; then
HOST="$BLUE\h$NO_COLOUR"
elif [ $CONN = tel ] ; then
HOST="$PURPLE\h$NO_COLOUR"
fi
# Okay...Now who we be?
# Assemble username string in this if statement - could be done above,
# but for now it's ok.
if [ `/usr/bin/whoami` = "root" ] ; then
USR=priv
USER="$RED\u$NO_COLOUR"
else
USR=nopriv
USER="$WHITE\u$NO_COLOUR"
fi
# Set Titlebar:
case $TERM in
xterm*|rxvt*)
local TITLEBAR='\[\033]0;\u@\h : ${PWD}\007\]' #Optionally, replace ${PWD} with \w
;;
*)
local TITLEBAR=""
;;
esac
# The work is done, now we merely put it together:
#PROMPT_COMMAND=set_clock
# Original PS1:
#PS1="$TITLEBAR[$YELLOW\D{%H%M}$LIGHT_GRAY][$USER@$HOST $DIR]\\$ "
# Make PS1 multi-line for clarity/long paths
PS1="
$TITLEBAR[$YELLOW\D{%H%M}$LIGHT_GRAY][$USER@$HOST $DIR]
$ "
PS2="> "
PS3="+ "
}
function nethack {
emacs ~/nethacknotes.txt &
ssh nethack@aphasic.com
}
# Function from Philip Dowie
function em() {
case $1 in
# if we have no parameters, we want a blank window
"")
if jobs %emacs 2> /dev/null
then
emacsclient --no-wait nullfile
else
emacs &
sleep 5
fi ;;
*)
if jobs %emacs 2> /dev/null
then
emacsclient --no-wait "$1"
else
emacs "$1" &
sleep 5
fi ;;
esac
}
# Function to scp something to Sage box at Phil's:
function scpp() {
scp $1 DELETED-FOR-PUBLIC:~/share/$1
}
# Function to print 1 up at MCS - uses scribble-2up
function mcslp() {
scp $1 $MCSNS:~/$1
mcs lpr1 $1 -Pscribble-2up
mcs rm $1
}
# My external hard drive mounting stuff:
function hddm {
mount f: ~/hdd/big
mount g: ~/hdd/small
mount h: ~/hdd/med
}
function hddu {
umount ~/hdd/big
umount ~/hdd/small
umount ~/hdd/med
}
# Make latex quicker:
function latexc {
latex $1
bibtex $1
latex $1
latex $1
dvips $1.dvi
gv $1.ps
}
# Call set_prompt function
set_prompt
shopt -s histappend
shopt -s cdspell
. /etc/bash_completion
# MCS Stuff
#need postgresql
#need java2-latest
#need sgegrid