# # .bashrc for use on my OS X systems at home # # forked and adapted from this version used on W3C systems: # Id: .bashrc,v 1.49 2001/01/18 05:15:00 gerald Exp # # $Id: bashrc,v 1.40 2022/10/04 20:56:33 gerald Exp $ # if [ -f /etc/bashrc ]; then . /etc/bashrc fi if [ -f $HOME/.ssh/creds ]; then . $HOME/.ssh/creds fi if [ -z $OS ]; then OS=unknown; export OS if [ -x /bin/uname ]; then OS=`uname -s`; export OS fi fi export EDITOR=vi export VISUAL=vi if [ $OS != "Linux" ]; then # this should be set like the other paths. : else alias vi='vim -X' alias ls="ls --color=auto" export EDITOR=vim export VISUAL=vim fi # leave first element empty instead of "." to avoid printing path when cd'ing CDPATH=:$HOME # /opt/local/libexec/gnubin added to path to avoid having to create aliases # for all the macports-installed gnu utils with g prefixes, e.g. gdate, gls # this stuff should be spun off into a sh function, maybe, then reused PATH="" for dir in \ /home/gerald/bin \ /opt/local/libexec/gnubin \ /opt/local/sbin \ /usr/local/sbin \ /usr/local/bin \ /Users/gerald/bin \ /Users/conky/home/gerald/bin \ /opt/local/bin \ /usr/local/jdk/bin \ /usr/share/fslint/fslint \ /usr/ucb \ /home/lists/.bin \ /usr/local/bin/X11 \ /usr/sbin \ /sbin \ /usr/lib \ /usr/sue/bin \ /usr/demos/bin \ /usr/games \ /opt/SUNWspro/bin \ /opt/ecp/bin \ /opt/bin \ /usr/local/etc \ /usr/Cadmin/bin \ /usr/ccs/bin \ /bin \ /etc \ /usr/etc \ /usr/bin \ /usr/bin/mh \ ; \ do if [ -d $dir ]; then PATH="${PATH}:${dir}" fi done PATH=${PATH#:} # make sure "" is not an element in the final path export PATH if [ -z $MANPATH ]; then MANPATH="/usr/local/man" fi for dir in \ /opt/local/share/man \ /opt/local/share/perl5.28/man \ /opt/local/share/perl5.26/man \ /usr/man \ /usr/share/man \ /usr/X11/man \ /usr/lib/perl5/man \ /usr/X11R6/man \ /usr/local/X11/man \ /usr/openwin/man \ ; \ do if [ -d $dir ]; then MANPATH="${MANPATH}:${dir}" fi done export MANPATH LANG=C CC=gcc OPENWINHOME=/usr/openwin INPUTRC=$HOME/.inputrc export INPUTRC MAIL="$HOME/mail/inbox" unset MAILCHECK # CVSROOT="cvs.w3.org:/w3ccvs"; export CVSROOT # CVSROOT="cvs.impressive.net:/cvsroot"; export CVSROOT # CVSROOT="/wd4/cvsroot"; export CVSROOT CVSROOT="/ds9/data/cvsroot"; export CVSROOT CVS_RSH="ssh"; export CVS_RSH # temporary to get around sympatico not allowing port 22 through # CVS_RSH="ssh-port-2222"; export CVS_RSH IRCSERVER="irc:6667"; export IRCSERVER PAGER="less"; export PAGER if [ -d /usr/local/bin/gnu ]; then RCSBIN=/usr/local/bin/gnu else RCSBIN=/usr/local/bin fi if [ -z $PRINTER ]; then PRINTER=paperhaus fi if [ -z $XAPPLRESDIR ]; then XAPPLRESDIR=$HOME/lib/X11/app-defaults fi if [ -z $HOST ]; then HOST=`scutil --get LocalHostName` HOST=${HOST%.w3.org} fi export HOST if [ -z $NNTPSERVER ]; then NNTPSERVER=news.mit.edu; export NNTPSERVER fi WWW_HOME="http://www.w3.org/People/Gerald/start" ignoreeof=0 # makes ^D logout immediately shopt -s histappend shopt -s cmdhist HISTSIZE=5000; export HISTSIZE HISTFILESIZE=5000; export HISTFILESIZE HISTTIMEFORMAT="%F %T "; export HISTTIMEFORMAT HISTIGNORE="&:[ ]*:exit:ls:bg:fg:history"; export HISTIGNORE case $TERM in dec-vt220|vt220) export TERM=vt220;; linux) colorPrompt=1;; color-xterm|xterm-color|xterm-256color|xterm|rxvt|screen) colorPrompt=1; titleControl=1;; esac if [ $colorPrompt ]; then # vary hostname color in prompt based on hash of hostname HASH=`echo "$HOST" | md5sum` FG=$(($((0x${HASH:0:1}))%8+30)) BG=$(($((0x${HASH:1:1}))%8+40)) export PS1="\[\e[0;0m\]\u\[\e[0m\]@\[\e[1;${FG}m\e[0;${BG}m\]\h\[\e[0m\]:\w$ " # current version on lahey as of 2016-11-11: # export PS1="\[\e[0;0m\]\u\[\e[0m\]@\[\e[0;${FG}m\e[1;${BG}m\]\h\[\e[0m\]:\w$ " unset HASH FG BG fi umask 022 set -o vi bind "set completion-ignore-case on" bind "set completion-map-case on" bind "set show-all-if-ambiguous on" bind "set mark-symlinked-directories on" bind "set skip-completed-text on" shopt -s autocd shopt -s dirspell shopt -s cdspell shopt -s cdable_vars shopt -s direxpand # try to avoid $VAR getting escaped during tab completion alias ll="ls -laFN --color=auto" alias l="ls -lFN --color=auto" alias LL="ls -LlaFN --color=auto" alias L="ls -LlFN --color=auto" # remove annoying bold face from dir colors eval `dircolors | sed 's/01;//g'` # use red for executables; default green is unreadable on white bg LS_COLORS=$LS_COLORS:"ex=31"; export LS_COLORS # use blue for symlinks; default is bold red on black with bad wrapping LS_COLORS=$LS_COLORS:"or=00;34"; export LS_COLORS alias md="mkdir" alias rd="rmdir" alias c=clear alias Grep=grep alias Tar=tar alias zcat="gunzip -c" alias TI="tail -2000 $HOME/.irclog | irc2txt | less" alias psg="ps aux | grep $*" alias corntab=crontab alias weather="ssh voodoo weather" alias SU="ssh localhost -l root" alias w3ccvs="CVS_RSH=ssh cvs -d cvs.w3.org:/w3ccvs" alias mtr="mtr -t" alias cu="cvs update" alias count="sort | uniq -c | sort -n" alias r="ssh ricky.impressive.net" alias h="vi $HOME/misc/2022/hours" alias gvim="gvim -rv" alias qiv="qiv -mne" alias xv="\qiv -en" # XLIB_SKIP_ARGB_VISUALS is to fix qiv weirdness after upgrade to edgy eft # see http://ubuntuforums.org/showthread.php?t=11346 export XLIB_SKIP_ARGB_VISUALS=1 alias mp="ssh mr-plow.shmop.net" # alias v="vlc -f" alias v="mpv -fs --framedrop=decoder" alias dto="epinfo -T DateTimeOriginal" alias grep="grep --color" # from http://www.commandlinefu.com/commands/view/3573/search-for-a-string-inside-all-files-in-the-current-directory alias rgrep="grep -RnisI" alias res="jdresolve -r -a -n -" alias HEAd="HEAD" alias hogs='du -cks * .??* | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done' alias info="info --vi-keys" alias top=htop # http://www.commandlinefu.com/commands/view/5312/alias-head-for-automatic-smart-output alias head='head -n $(($LINES-2))' WWW=$HOME/WWW; export WWW Y=$HOME/Dropbox/misc/archive/`date +%Y`; export Y DA=$HOME/Dropbox/misc/archive; export DA DM=/Volumes/media; export DM DD=/Volumes/data; export DD W=$DD/www/people/gerald; export W SD=$HOME/SynoDrive; export SD SG=$HOME/SynoGer; export SG N=$SD/House/Notes; export N L="??-??-??.jpg"; export L P="$HOME/p/master"; export P D="$P/modules/w3cnameserver/files/zones"; export D E="$P/modules/w3cmailhub/files/etc"; export E # need to do the following because stoopid dropbox doesn't preserve symlinks alias addhrs="$HOME/impressive.net/people/gerald/2002/03/21/addhrs" alias cal="$HOME/impressive.net/people/gerald/2003/01/cal" alias dedundify="$HOME/impressive.net/people/gerald/2010/11/dedundify" alias eta="$HOME/impressive.net/people/gerald/2009/07/eta" alias magnet2seedbox="$HOME/impressive.net/people/gerald/2012/05/magnet2seedbox" alias vix="$HOME/impressive.net/people/gerald/2013/04/vix" alias m="$HOME/impressive.net/people/gerald/2001/04/fetch_mail" alias w3c-browse-message="$HOME/impressive.net/people/gerald/2011/04/w3c-browse-message" alias w3c-copy-archive-uri="$HOME/impressive.net/people/gerald/2011/04/w3c-copy-archive-uri" alias addinv="$HOME/impressive.net/people/gerald/2002/07/19/addinv" alias ymdify="$HOME/impressive.net/people/gerald/1999/10/ymdify" alias H="lwp-request -m HEAD" alias G="lwp-request -m GET" alias n="ls -glartN | tail -n 40" alias git="TZ=UTC git" alias glog="git log --graph --abbrev-commit --decorate --date=relative" alias noop="cat>/dev/null" alias globaltimes=dt alias mmrefs='find mm/ -type f | sed "s,^mm/,~/$(readlink mm)/,"' LESS="-aiMnR -b20"; export LESS BAT_THEME="Monokai Extended Light"; export BAT_THEME # keep track of various dirs that contain code, for easier grepping # when I am trying to find similar code I wrote in the past # (e.g. find $CODEDIRS -type f | xargs grep localtime) for dir in \ $HOME/bin \ $HOME/p \ $HOME/WWW/Systems/Mail/smartlist/etc \ $HOME/WWW/Systems/Mail/smartlist/bin \ $HOME/WWW/Systems/Mirroring/bin/cvs \ $HOME/WWW/Web/stats-bin \ $HOME/www/software/hurl/source \ ; \ do if [ -d $dir ]; then CODEDIRS="${CODEDIRS} ${dir}" fi done export CODEDIRS grepcode () { find $CODEDIRS -type f | xargs grep -l "$1" | sort -u | xargs grep "$1" } if [ "${-#hi}" != "${-}" ] # this is for interactive shells only then # this stuff stolen from Eric Prud'hommeaux if [ `echo "${TERM}"|grep xterm` ]; then title () { echo -n ']0;'$1''; } icon_title () { echo -n ']1;'$1''; } window_title () { echo -n ']2;'$1''; } retitle () { window_title "$HOST" icon_title "$HOST" } ssh () { sshUser=$USER for arg in $* do if [ x$nextIsSshUser != x ]; then sshUser=$arg nextIsSshUser= elif [ x$nextIsSshParm != x ]; then sshParm="$sshParam $arg" nextIsSshParm= else case $arg in -l) nextIsSshUser=1 continue;; -f) sshStatus='starting ' continue;; -a|-f|-k|-n|-q|-P|-t|-v|-V|-g|-x|-C) continue;; -c|-e|-i|-o|-p|-L|-R) nextIsSshParm=1 continue esac if [ x$sshHost != x ]; then sshCmd="$sshCmd $arg" continue else sshHost=$arg fi fi done; # title "$sshStatus$sshUser@$sshHost $sshCmd"; title "$sshHost" `\\which ssh` $*; retitle; sshUser= sshHost= sshCmd= sshStatus= nextIsSshUser= # in case of bad arguments to last ssh call nextIsSshParm= } retitle fi fi LC_CTYPE=en_US.UTF-8; export LC_CTYPE LC_ALL=en_US.UTF-8; export LC_ALL PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH # enable autocomplete for aws commands, per # https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-completion.html complete -C '/usr/local/bin/aws_completer' aws AWS_PROFILE="gerald-w3c"; export AWS_PROFILE scd() { cd `search-for $@` } # CVS fetch and edit the specified URL edit() { url=${1%%#*} # strip fragment if present url=${url/%\///Overview.html} # add Overview.html if needed url=${url/#http:/https:} # convert http to https for next rule path=WWW${url#https://www.w3.org} fed $path dir=${path%/*} cd $dir } muttenv="personal"; export muttenv w3cmutt() { muttenv="w3c" mutt "$@" } # log in to root at the specified host via jump host R() { ssh -t root@$* 'bash --rcfile .bashrc.gerald' } if [ -e /etc/bash_completion ]; then . /etc/bash_completion fi # ruler: a shell function to print a ruler the width of the terminal window. # from http://www.commandlinefu.com/commands/view/4719/a-shell-function-to-print-a-ruler-the-width-of-the-terminal-window. ruler() { for s in '....^....|' '1234567890'; do w=${#s} str=$( for (( i=1; $i<=$(( ($COLUMNS + $w) / $w )) ; i=$i+1 )); do echo -n $s done ) str=$(echo $str | cut -c -$COLUMNS) echo $str done } f () { awk "{print \$$1}" } fq () { awk -F\" "{print \$$1}" } add() { awk '{ sum += $1; } END { print sum; }' } average() { awk '{ sum += $1; } END { print sum / NR; }' } # copied from https://stackoverflow.com/a/49263254 # see also: datamash (used in report-slowest-uris) median() { sort -n | awk '{arr[NR]=$1} END {if (NR%2==1) print arr[(NR+1)/2]; else print (arr[NR/2]+arr[NR/2+1])/2}' } # smart cd: if file specified, cd to its parent dir # http://www.commandlinefu.com/commands/view/5452/smart-cd..-cd-to-the-file-directory-if-you-try-to-cd-to-a-file cd() { [ -z "$1" ] && set -- ~ [ -f "$1" ] && set -- "${1%/*}" builtin cd "$1" } # lf: less file foo (useful for peeking at a script with a distinct name) lf() { DIRS="$P $HOME/WWW/Systems/Http/cgi-bin $HOME/WWW/Systems/Mail/smartlist" find $DIRS -type f -name "*$1*" -print0 | xargs -0 less } # calc: like expr, but handles floating point numbers calc() { ( echo scale=4; echo $@ ) | bc } # print our current public IP address # copied from https://github.com/jessfraz/dotfiles/blob/master/.aliases myip() { dig +short myip.opendns.com @resolver1.opendns.com } # Get colors in manual pages # copied from https://github.com/jessfraz/dotfiles/blob/master/.functions man() { env \ LESS_TERMCAP_mb="$(printf '\e[1;31m')" \ LESS_TERMCAP_md="$(printf '\e[1;31m')" \ LESS_TERMCAP_me="$(printf '\e[0m')" \ LESS_TERMCAP_se="$(printf '\e[0m')" \ LESS_TERMCAP_so="$(printf '\e[1;44;33m')" \ LESS_TERMCAP_ue="$(printf '\e[0m')" \ LESS_TERMCAP_us="$(printf '\e[1;32m')" \ man "$@" } # rgi: interactive rg # copied and adapted from https://news.ycombinator.com/item?id=31010090 rgi () { rg --line-number --no-heading --color=always --smart-case "$@" | fzf -d ':' -n 2.. --ansi --no-sort --preview-window 'down:20:+{2}-9' --preview 'bat --style=numbers --color=always --highlight-line {2} {1}' }