## This is a mess, and needs tidying up. Hopefully it works on linux and (free)bsd, and can be sourced repeatedly without making PATH grow each time. export LANG=en_GB.UTF-8 if [[ $- != *i* ]]; then # Non-interactive shell return fi export HOSTNAME=${HOSTNAME:-$(hostname -s)} # need -s above for BSD, but that returns localhost on some linuxen [[ "x${HOSTNAME}" == "xlocalhost" ]] && export HOSTNAME=$(hostname) export HOST=$HOSTNAME export USER=${USER:-$(whoami)} #if [[ x$SCRIPT == x ]] #then # script -q typescripts/script-`date +%Y%m%d%H%M%S``tty|tr / -`-$$ # exit #fi ## use _ for "internal" functions, and - for those intended to be used ## interactively do_interesting_prompt() { prompt_choice=$1 # col for colour, not column reset_col='\[\e[0m\]' sif_col='\[\e[0;35m\]' tyr_col='\[\e[0;36m\]' gaius_col='\[\e[0;33m\]' gendros_col='\[\e[1;37m\]' mnason_col='\[\033[01;32m\]' host_col=$reset_col # TODO make all of these unique again [[ "x$HOST" == "xsif" ]] && host_col=$sif_col [[ "x$HOST" == "xtyr" ]] && host_col=$tyr_col [[ "x$HOST" == "xsagacity" ]] && host_col=$tyr_col [[ "x$HOST" == "xwolfman" ]] && host_col=$tyr_col [[ "x$HOST" == "xgaius" ]] && host_col=$gaius_col [[ "x$HOST" == "xgendros" ]] && host_col=$gendros_col [[ "x$HOST" == "xCHESTER" ]] && host_col=$gendros_col [[ "x$HOST" == "xtriton" ]] && host_col=$gendros_col [[ "x$HOST" == "xmnason" ]] && host_col=$mnason_col djm_col='\[\e[0;32m\]' wiz_col='\[\e[1;32m\]' deejayem_col='\[\e[1;32m\]' user_col=$reset_col [[ "x$USER" == "xdjm" ]] && user_col=$djm_col [[ "x$USER" == "xwizard" ]] && user_col=$wiz_col [[ "x$USER" == "xdeejayem" ]] && user_col=$deejayem_col [[ "x$USER" == "xdavidmo" ]] && user_col=$deejayem_col at_col='\[\e[0;37m\]' [[ -n "$SSH_CLIENT" ]] && at_col='\[\e[1;33m\]' time_col='\[\e[0;36m\]' # don't clash with host_col [[ "x$HOST" == "xtyr" ]] && time_col='\[\e[1;33m\]' [[ "x$HOST" == "xsagacity" ]] && time_col='\[\e[1;33m\]' [[ "x$HOST" == "xwolfman" ]] && time_col='\[\e[1;33m\]' dir_col='\[\e[1;34m\]' sb_col=$reset_col # Square brackets rb_col='\[\e[0;32m\]' # Round brackets cb_col='\[\e[0;32m\]' # Curly brackets cn_col='\[\e[0;35m\]' # Command numbers # Should vaguely correspond to user_col, but emphasise whether or not # we're using ssh (shutting down the wrong machine is not cool) prompt_col='\[\e[0;32m\]' [[ -n "$SSH_CLIENT" ]] && prompt_col='\[\e[1;32m\]' # col for colour, not column (still) # \h on first line as well as the second, because ^R obscures the second if [[ $prompt_choice -eq 1 ]]; then export PS1="$time_col\d \t $cb_col{$host_col\h$cb_col}\n$sb_col[$user_col\u$at_col@$host_col\h $dir_col\w$sb_col]$rb_col($cn_col\#:\j:"'$?'"$rb_col)$prompt_col\$$reset_col " elif [[ $prompt_choice -eq 2 ]]; then export PS1="$sb_col[$user_c
*~
*.pyc
*.pyo
stuff/*
nd ".":insert-last-argument bind -m vi-insert "\C-l.":clear-screen bind -m vi-insert "\C-a.":beginning-of-line bind -m vi-insert "\C-e.":end-of-line bind -m vi-insert "\C-w.":backward-kill-word export HISTSIZE=2000 export HISTFILESIZE=2000 export HISTCONTROL=ignorespace:ignoredups # easily done with tail and head, but where's the fun in that? nth-from-end() { n=$1 sed -n -e :a -e "\${P;q;};N;$((n+1)),\$D;ba" ${2} } most-recent() { ls -t|head -1 } function google () { w3m http://www.google.co.uk/search?q="$@"; } function swap-lines() { sed -n "${1}h;${2}{p;x;p};2,3!p" ${3} } function maths() { echo "scale=6;${@/x/*}"|bc } function title() { wget --quiet -O- "${1}" | sed -n 's/\([^<]*\)<\/title>.*/\1/p' } alias set_last_dir='last_dir=$(expr "`history -p !$`" : "\(.*/\)");' # Run commands on files in the same directory as the file in !$ (old = on last directory) old() { args=($@) command=${args[@]:0:${#args[@]}-1} file=${args[${#args[@]}-1]} last_dir=$(expr "`history -p !$`" : "\(.*/\)") echo ${command} ${last_dir}${file} ${command} ${last_dir}${file} } old2() { command=$1 shift last_dir=$(expr "`history -p !$`" : "\(.*/\)") echo ${command} ${last_dir}${file} for file in $@ do echo \$ ${command} ${last_dir}${file} ${command} ${last_dir}${file} echo done } #get_default_net_if() #{ # sudo route -n get -inet default #} # for use with keyboard shortcuts x() { xclip -o } xspeak() { echo "`x`"|festival --tts #espeak "`x`" } function ag_less() { ag --color "${@}"|less -RXF } function java_run() { javac "${@}" java "${@/.java/}" } # useful for aliases function chdir() { if [ $# -eq 0 ]; then #cd - echo -n "popd: " popd else #cd $@ #pwd echo -n "pushd: " pushd $@ fi } function run_cmd() { echo "${@}" "${@}" } alias gitlog="git log --since=yesterday --name-only" alias gitlog1="git log -p -1" alias gitfp1="git format-patch --stdout -1" alias gitvimdiff="git difftool --tool=vimdiff" alias gitgvimdiff="git difftool --tool=gvimdiff" # useful after commit, before push alias gitdevdiff="git diff origin/develop" alias gitmasterdiff="git diff origin/master" alias hadd='run_cmd $(history -p ^diff^add)' alias dogs='run_cmd docker ps; run_cmd docker logs -f $(docker ps|sed 1d|awk '"'"'{print $1;}'"'"')' alias undock='sudo umount `mount|grep -o "/var/lib/docker/aufs/mnt/[a-z0-9]*"`' #alias gp="chdir ${VIEW_DIR} ; run_cmd git pull --rebase --stat ; chdir" #alias gs="chdir ${VIEW_DIR} ; run_cmd git stash ; chdir" #alias gsp="chdir ${VIEW_DIR} ; run_cmd git stash pop ; chdir" #alias gstat="chdir ${VIEW_DIR} ; run_cmd git -c color.status=always status | less -RXF ; chdir" function esvapi() { ref=${@// /%20} #wget --quiet -O- "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=$ref"|lynx -dump -stdin|sed -n 's/\[[0-9]\+\] \?//g;/^Footnotes\|References/q;p' wget --quiet -O- "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=$ref"|lynx -dump -stdin|gsed -n '/^\s*$/d;s/\[[0-9]\+\] \?//g;p;/(ESV)$/q' } function bgw() { bv=${1} shift ref=${@// /%20} wget --quiet -O- "http://www.biblegateway.com/passage/?search=${ref}&version=${bv}"|lynx -dump -stdin|gsed -n "/^$@.*${bv}/,/^Footnotes/p"|grep -v "^Footnotes" } function dl() { DAILY_LIGHT_URL="http://www.gnpcb.org/esv/mobile/devotions/daily.light/" #wget --quiet -O- "${DAILY_LIGHT_URL}"|lynx -dump -stdin|sed -n '/Morning/,/^\s*\[[0-9]/p'|sed -n '/^\s*\[[0-9]/q;p'|less if [ `date +%P` == "am" ] then wget --quiet -O- "${DAILY_LIGHT_URL}"|lynx -dump -stdin|sed -n '/^Morning$/,/^Evening$/p'|sed -n '/^\s*\[[0-9]/q;p'|head -n -2|less elif [ `date +%P` == "pm" ] then wget --quiet -O- "${DAILY_LIGHT_URL}"|lynx -dump -stdin|sed -n '/^Evening$/,/^\s*\[[0-9]/p'|sed -n '/^\s*\[[0-9]/q;p'|head -n -1|less else echo "Neither AM nor PM!" fi } function pmp() { #sed -n "/`date +'%B %-d.%p'|sed 's,AM,Morning,;s,PM,Evening,'`/,/`date --date=tomorrow +'%B %-d'`/p" rh_pmp.txt | head -n -1 | less if [ `date +%P` == "am" ] then #sed -n "/`date +'%B %-d.Morning'`/,/`date +'%B %-d.Evening'`/p" rh_pmp.txt | head -n -1 | tr -d '\f' | less xzcat rh_pmp.txt.xz | sed -n "/`date +'%B %-d.Morning'`/,/`date +'%B %-d.Evening'`/p" | head -n -1 | tr -d '\f' | less elif [ `date +%P` == "pm" ] then #sed -n "/`date +'%B %-d.Evening'`/,/`date --date=tomorrow +'%B %-d.Morning'`/p" rh_pmp.txt | head -n -1 | tr -d '\f' | less xzcat rh_pmp.txt.xz | sed -n "/`date +'%B %-d.Evening'`/,/`date --date=tomorrow +'%B %-d.Morning'`/p" | head -n -1 | tr -d '\f' | less else echo "Neither AM nor PM!" fi } function wsc() { grep ^[QA]$1: wsc.txt | fold -s | col -b } function wscq() { grep ^Q$1: wsc.txt | fold -s | col -b } function wsca() { grep ^A$1: wsc.txt | fold -s | col -b } function wlc() { grep ^[QA]$1: wlc.txt | fold -s | col -b } function wlcq() { grep ^Q$1: wlc.txt | fold -s | col -b } function wlca() { grep ^A$1: wlc.txt | fold -s | col -b } bible() { opt="" if [ "x$1" == "x-m" ] then opt="-o m" shift elif [ "x$1" == "x-a" ] then opt="-o a" shift elif [ "x$1" == "x-am" -o "x$1" == "x-ma" ] then opt="-o am" shift fi book=$1 shift case $book in esv|niv|tniv|nasb|kjv|nkjv|nlt|hcsb|ylt|asv|lxx) book=${book^^*} ;; amp) book=${book^*} ;; net) book=NETfree ;; esac diatheke -b "${book}" $opt -k "${*}"|grep -v '^$'|sed -e :a -e '/[0-9]: $/N;s/\([0-9][0-9]*\): \n/\1: /;ta' } pll() { bible esv $@ bible niv $@ bible tniv $@ bible kjv $@ bible nkjv $@ bible nasb $@ bible net $@ bible hcsb $@ } # cricinfo functions (check, replace_urls, add_urls, remove_urls count_urls) function check() { while read i ; do #wget --quiet -O- "${i}" | sed -n 's/<title>\([^|]*\).*/\1/p' wget --quiet -O- "${i}" | sed -n 's/ *<title>\([^|<]*\).*/\1/p'|col done < ${HOME}/urls.txt } function replace_urls() { if [ $# -eq 0 ]; then cat >| ${HOME}/urls.txt else : >| ${HOME}/urls.txt for url in "$@"; do echo $url >> ${HOME}/urls.txt done fi } function add_urls() { if [ $# -eq 0 ]; then cat >> ${HOME}/urls.txt else for url in "$@"; do echo $url >> ${HOME}/urls.txt done fi } function remove_urls() { gsed -i ${1}d ${HOME}/urls.txt } function count_urls() { wc -l ${HOME}/urls.txt } #pgrep -f raven || screen -S rav -d -m ssh -X -R 6728:localhost:22221 wadh2045@raven.linux.ox.ac.uk #pgrep -f ecs || screen -S ecs -d -m ssh -X -R 6728:localhost:22221 m04dm@booth1.ecs.ox.ac.uk #pgrep -f crow || screen -S crow -d -m ssh -X -D 8080 wadh2045@crow.linux.ox.ac.uk # cygwin if [[ "x$OS" == "xWindows_NT" ]]; then export nodosfilewarning=1 export C=/cygdrive/c export WIN_HOME=$C/Users/davidmo # eclipse :( [[ -d $WIN_HOME/workspaces ]] && export WORKSPACES=$WIN_HOME/workspaces fi if [ -f ~/.fzf.bash ]; then . ~/.fzf.bash export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules}/*" 2> /dev/null' export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" bind -x '"\C-p": vim $(fzf -m);' #export FZF_ALT_C_COMMAND="cd ~/; bfs -type d -nohidden | sed s/^\./~/" export FZF_ALT_C_COMMAND="rg --hidden --files --sort-files --null | xargs -0 dirname | sort -u" #else # [ -f /usr/share/fzf/completion.bash ] && . /usr/share/fzf/completion.bash # [ -f /usr/share/fzf/key-bindings.bash ] && . /usr/share/fzf/key-bindings.bash fi if [ -f /usr/local/bin/tmuxp.bash ]; then . /usr/local/bin/tmuxp.bash fi true # vim: set et ts=4 tw=120 :