# $Id: abbreviations,v 1.105 2026/08/18 05:02:55 grog Exp $
# Default definitions sucked in by all bashes.
#
# This is the cruft of ages, originally started as a .bashrc on
# Inactive System V/386 in about May 1990.
#
# Stuff that differs between OSs.
# uname implementations differ in the way that they report the OS.
# FreeBSD uses time(1) -s, Linux uses -o
if [ `uname` = "Linux" ]; then
  # For Linux with these *horrible* colour ls functions
  unset COLORS LS_COLORS
  # And get man pages in correct width.
  export MANWIDTH=80
  TIMECMD='/usr/bin/time -v'
  LESSCMD='less -X'
# Get rid of these horrible Linux aliases.
  unalias -a
# For some reason, I have lots of trouble with this macro under Linux.
  mailme ()
  {
    cmd=$1
    shift
    xtset mailme $cmd
    date
    me=`who am i|awk '{print $1}'`
  # Why can't we deliver mail locally?
    echo $cmd $*' 2>&1 | tee /dev/tty | mail -s "mailme: $cmd $*" grog@lemis.com'
    $cmd $* 2>&1 | tee /dev/tty | mail -s "mailme: $cmd $*" grog@lemis.com
    cd .
    date
  }
else  # Some BSD
  TIMECMD='/usr/bin/time -l'
  LESSCMD=less
  mailme()
    {
    cmd=$1
    shift
    xtset mailme $cmd
    date
    $cmd $* 2>&1 | tee /dev/tty | mail -s "mailme: $cmd $*" `who am i|awk '{print $1}'`
    cd .
    date
  }
fi
# Bite the bullet (20231116)
export LC_ALL=en_AU.UTF-8
# Environment variables
export B=/home/Book
export BLOCKSIZE=1048576  # for df
if [ `hostname -s` = "eureka" ]; then
  export BY=12   # concurrency for by(1).
else        	 # don't kill the poor little CPU
  export BY=2   # concurrency for by(1).
fi
# export CC=distcc
# export DISTCC_HOSTS="wantadilla echunga zaphod adelaide sydney monorchid beeble"
export CVSROOT=/home/ncvs
export DIFFS=-c
export EDITOR=emacsclient
export F=/home/Book/FreeBSD-4
export L=/home/lemis
export LESS='-a -F -i -j5 -M -R -s -X'
export LESSCHARSET=latin1
export LD_32_LIBRARY_PATH=/dereel/usr/local/lib/gcc44:/dereel/usr/lib:/dereel/usr/local/lib:/dereel/usr/local/lib/hugin:/dereel/usr/lib/compat
export MANPATH=/home/local/man:/usr/local/man:/usr/local/share/man:/usr/share/man:/usr/X11R6/man:/usr/local/lib/perl5/site_perl/man
export PAGER=$LESSCMD
export PYTHONSTARTUP=~/.pythonrc.py
export RSYNC_RSH=ssh
export SHELL=/usr/local/bin/bash
export TAPE=/dev/nsa0
export USA_RESIDENT=NO
export V=/src/vinum
export W=/usr/local/www/data
export _CVS_REMOTE_HOST=freefall.freebsd.org
export _LOCAL_CVS=/home/ncvs
export _REMOTE_CVS=${_CVS_REMOTE_HOST}:/home/ncvs
# Silence some pkg issues
export IGNORE_OSVERSION=yes

# Initialization
case `tty` in
  /dev/ttyp*)
    TERM=xterm-color ;;
  /dev/pts/*)
    TERM=xterm-color ;;
  /dev/ttyq*)
    TERM=xterm-color ;;
  /dev/ttyv*)
    TERM=cons25 ;;
  *)
    TERM="" ;;
esac
export TERM
# Functions
case `uname` in
Linux)
  # No , operator
  alias l="ls -lbL"
  ;;

FreeBSD)
  alias l="ls -lbL,"
  alias df="/bin/df -,"
  ;;
esac
alias lc="ls -CF"
# Remove a target file, then make it.
remake ()
{
  rm $1
  make $*
}

# Run 'make' and log the results to the file ./Make.log.
Make()
{
  xtset `uname -n|sed 's:\..*$::'`:`pwd`: Make "$* "`date`
  HOST=`hostname`
  (
   echo '=====' `date` on $HOST: Make $*; $TIMECMD make 2>&1 $*) | tee -a Make.log.`hostname -s`
    pwd=`pwd`
    if [ `echo $pwd | grep /ports/` ]; then
      mkdir -p /home/Sysconfig/Makelogs
      echo `date` `pwd` make $* >> /home/Sysconfig/installed-ports
      cat Make.log.`hostname -s` >> /home/Sysconfig/Makelogs/`basename $pwd`
    fi
  cd .
  date
  }
# Run 'gmake' and log the results to the file ./Make.log.
Gmake ()
{
  xtset `uname -n | sed 's:\..*$::'`:`pwd`: Gmake "$* "`date`
  (echo '=====' `date` on `hostname`: Gmake $*; $TIMECMD gmake 2>&1 $*) | tee -a Make.log
  cd .
  }
# Run a command and log it to a file Log.log.
Log ()
{
  xtset `uname -n | sed 's:\..*$::'`:`pwd`: $* `date`
  (echo '=====' `date` on `hostname`: $*; $TIMECMD  2>&1 $*; echo $1 finished at `date`) | tee -a Log.log.`hostname -s`
  cd .
  }
# Change directory and set the xterm heading to match.
cd ()
{
  command cd "$@"
  if [ $? = 0 ]; then
    xtset -t "%u (%T) %h:%D ($DISPLAY)"
    xtset -i "%u@%h:%D"
    true
  else
    false
  fi
}
# Push directory (shell 'pushd' builtin) and set the xterm heading to
# match.  This breaks badly with brain-dead directories containing
# spaces.  Use pushd to bypass it in this case.
pd ()
{
  builtin pushd $*
  xtset -t "%u (%T) %h:%D"
  xtset -i "%u@%h:%D"
}
# Pop directory (shell 'popd' builtin) and set the xterm heading to
# match.  This breaks badly with brain-dead directories containing
# spaces.  Use 'command popd' to bypass it in this case.
popd ()
{
  builtin popd $*
  xtset -t "%u (%T) %h:%D"
  xtset -i "%u@%h:%D"
}
# rlogin and set the xterm heading to match.
rlogin ()
{
  xtset -t $*
  xtset -i "%u@%h:%D"
  command rlogin $*
  xtset -t "%u (%T) %h:%D"
  xtset -i "%u@%h:%D"
}
neti ()
{
if [ "$1" = "" ]; then
  delay=5
else
  delay=$1
fi
netstat -s >/tmp/netstat1
sleep $delay
netstat -s >/tmp/netstat2
diff /tmp/netstat1 /tmp/netstat2
}
nfss ()
{
if [ "$1" = "" ]; then
  delay=5
else
  delay=$1
fi
nfsstat >/tmp/netstat1
sleep $delay
nfsstat >/tmp/netstat2
diff /tmp/netstat1 /tmp/netstat2
}
cpqic ()
{
  (while [ -d / ]; do
    dd if=/dev/rst0 obs=20b
    echo -n >/dev/tty Next tape:
    read reply
    if [ "$reply" = 'q' ]; then
       exit
    fi
   done) | rsh allegro dd ibs=20b obs=128b of=/dev/nrst0
  }
# search for a string in all man pages. Unformatted man pages stay unformatted.
findman ()
{
  (for i in `echo $MANPATH|sed 's*:* *g'`; do
   find $i -type f -name "*.gz" -or -name "*.Z" -print|xargs zcatgrep $1 2>/dev/null
   find $i -type f ! \( -name "*.gz" -or -name "*.Z" \) -print|xargs grep $1
   done) | $LESSCMD
  }
function setenv {
        _SYM=$1; shift; export $_SYM="$*"
}


# CVS related functions.
function do-local-cvs {
        setenv CVSROOT ${_LOCAL_CVS}
        setenv CVS_IGNORE_REMOTE_ROOT yes
        [ -f CVS/Root ] && echo ${CVSROOT} > CVS/Root
}

function do-remote-cvs {
        setenv CVSROOT ${_REMOTE_CVS}
        setenv CVS_IGNORE_REMOTE_ROOT yes
        [ -f CVS/Root ] && echo ${CVSROOT} > CVS/Root
}

function cvscommit {
        do-remote-cvs
        cvs commit $*
        do-local-cvs
}
remake ()
{
  rm $1
  make $*
}
burn()
{
# defaults for my setup
  SPEED=8
  if [ "$DEV" = "" ]; then
    if [ `hostname -s` = "eureka" ]; then
      DEV=6,0,0
    else
      DEV=0,0,0
    fi
  fi
  DUMMY=
  if [ "$1" = "" ]; then
    echo Usage: burncd filename [dummy flag]
  else
    if [ "$2" != "" ]; then  # dummy burn
      DUMMY=-dummy
    fi
    cdrecord  $DUMMY -v dev=$DEV -speed=$SPEED $1
  fi
}

# Variant of which(1) that shows all potential commands in the order
# found in PATH.  Shows an ls -l listing for each of them.
wh ()
{
  tmpfile=/tmp/`basename $0`.$$
  (for j in $*; do
    for i in `echo $PATH|sed 's/:/ /g'`; do
      if [ -f $i/$j ]; then
        echo $i/$j
      fi
    done
  done) >$tmpfile
  if [ -s $tmpfile ]; then
  # GNU ls treats -lf and -fl differently
    xargs <$tmpfile ls -fli
  else
    echo No files found
  fi
  rm $tmpfile
}
# Make a corresponding RCS directory in /home/Sysconfig/MasterRCS and
# symlink to it.
mkRCS ()
{
  sysconfig=/home/Sysconfig/MasterRCS
  cwd=`pwd`
  if [ -d RCS ]; then
    if [ -e RCS.old ]; then
      echo RCS.old already exists.  Please check and repeat if necessary.
      ls -lL RCS RCS.old
      return
    fi
    mkdir -p $sysconfig$cwd
    echo Copying control files:
    tar cf - RCS| (cd $sysconfig$cwd; tar xvf - )
    mv RCS RCS.old
    ln -s  $sysconfig$cwd/RCS RCS
    echo '*** Check' $cwd/RCS.old and remove when OK '***'
    ls -lL RCS RCS.old
  elif [ -e RCS ]; then
      echo $cwd/RCS exists and is not a directory.  Please check
      return
  else
    mkdir -p $sysconfig$cwd/RCS
    ln -s  $sysconfig$cwd/RCS RCS
   fi
  }
installport ()
{
  cwd=`pwd`
  cd $1
  if [ $? -ne 0 ]; then
    return 1
  fi
   export BATCH=dammit A4=yes
   make clean; Make install
  (echo '=====' `date` on `hostname`: Make install;
   $TIMECMD make 2>&1 install
   if [ $? -eq 0 ]; then
    pwd >> /home/Sysconfig/installed-ports
  fi) | tee -a Make.log
  cd $cwd
  }
# Describe MPEG files in directory.
# We base this on the existence of files with the ending ".description".
desc ()
{
  if [ "$1" = "-s" ]; then
    STARTEDONLY=yes
    shift
  else
    STARTEDONLY=
  fi
  for i in `ls -rt ./*.description ./*.txt`; do
    mpeg=`basename $i .description`
    if [ -e $mpeg.fpos ]; then
      echo '==*' $mpeg
    elif [ "$STARTEDONLY" = "yes" ]; then
      continue
    else
      echo === $mpeg
    fi
    echo -n "=== "
    ls -hl $mpeg | awk '{printf ("%s %s, %s, %s\n", $7, $6, $8, $5)};'
    echo
    fmt $i
    echo
  done
}

# Lock and check in a list of files
lci ()
{
  for i in $*; do
    rcs -l $i
    ci -d -u $i
  done
}

# Set the xterm headers
xtset -t "%u (%T) %h:%D"
xtset -i "%u@%h:%D"
# Sync down to ScanFast-7020-saved, copy to ScanFast-7020-current
# and sync up from there.
syncGPS ()
{
  rsync -va --delete-after /GPS/ /src/GPS/ScanFast-7020-saved
}
updateGPS ()
{
  rsync -va --delete-after /src/GPS/ScanFast-7020-current/ /GPS
}
copydvd ()
{
  if [ $# -lt 2 ]; then
    echo Usage: copydvd DVD-track filename [dvd-device]
  elif [ $# -eq 3 ]; then
    mplayer dvd://$1 -dumpstream -dumpfile $2 -dvd-device $3
  else
    mplayer dvd://$1 -dumpstream -dumpfile $2
  fi
}
rrm ()
{
  for i in "$@"; do
    find . -name $i | xargs rm
  done
}
joinmpeg ()
  {
  RESULT=$1
  TMP=/tmp/clip$$
  shift
  cat $* > $TMP
  mencoder -forceidx -oac copy -ovc copy $TMP -o $RESULT
# Audio gets out of sync
#  LOADS="--load $1 "
#  shift
#  for i in $*; do
#    echo $i
#    LOADS="$LOADS --append $i"
#  done
#  echo LOADS $LOADS
#  avidemux2_cli --audio-map --rebuild-index $LOADS --save avi$RESULT
  }
# Rename all files starting with $1 to the same extension starting with $2
mvall ()
{
  if [ $# -ne 2 ]; then
    echo Usage: mvall src dst
  else
    for i in ${1}*; do
      mv $i ${i/$1/$2}
    done
  fi
}
Rsync ()
{
  rsync --progress --partial -av $*
}
Smerge ()
{
  if [ "$*" = "" ]; then
    svn propget svn:mergeinfo -R .
  else
    svn merge  XXX
  fi
}
mdirs ()
{
  for f in a b c d e f g h i; do mdir $f:; done
}
# Install a package and note the fact
Pinstall ()
{
  for p in $*; do
      pkg install -y $p
      PKGLIST=/home/db/pkglist
      if [ $? -eq 0 ]; then	# installed
	  touch $PKGLIST	# make sure it exists
	  grep -v $p $PKGLIST > ${PKGLIST}.tmp
	  echo `date +%s` $p >> ${PKGLIST}.tmp
	  mv ${PKGLIST}.tmp $PKGLIST
      fi
  done
}
# Get videos via ffm proxy.  This doesn't display the video.
yp ()
{
  if [ $1 = "-l" ]; then
    PROXY=http://lax:3128
    shift
  else
    PROXY=http://fra:3128
  fi
  yt -P $PROXY $*
}
# Get screen shots from hirse
getss ()
{
    if [ "$PHONE" = "" ]; then
      PHONE=hirse
    fi
    DATE=$1
    # This will fail badly unless the directory name is a date.
    if [ "$DATE" = "" ]; then
      DATE=`pwd`
    fi
    DATE=`basename $DATE`
    DATE=`echo $DATE | sed 's:\(....\)\(..\)\(..\):\1-\2-\3:'`
  cd orig
echo mget \'*$DATE*\' \| ftp -i ftp://android:hidden@$PHONE:2121/DCIM/Screenshots/
  echo mget *$DATE* | ftp -i ftp://android:hidden@$PHONE:2121/DCIM/Screenshots/
# set the modification timestamp to time of shot
  datescreenshot
#  mkdir -p JPEG
#  mv Screen*jpg JPEG
  cd ..
}
alias rz='eval `resize`'
lsl ()
{
# Use UTF-8 and fix any broken file names
  LC_ALL=de_DE.UTF-8 ls -lRT, $* | less
}
# Rename video files starting in Folge.1 etc
# usage: defolge prefix
defolge()
{
  prepend -s Folge- $1- Folge-??_*
  prepend -s Folge- ${1}-0 Folge-?_*
}
# Grep for a pattern in /spool/stats/seenlist
seen ()
{
# Locale change needed to stop grep crapping out
  LC_ALL=de_DE.UTF-8
  SEENLIST=/spool/stats/seenlist
  if [ "$1" = "-l" ]; then
    SEENLIST=/spool/stats/lastseen
    shift
  elif [ "$1" = "-r" ]; then
    SEENLIST=/spool/stats/seenrecently
    shift
  fi
  if [ "$*" = "" ]; then
    cat $SEENLIST
  else
    grep --binary-files=text $* $SEENLIST
  fi
}
alias sr="seen -r"
# Tidy up subtitle files with empty lines.
fixsrt()
{
    FILES=$*
    if [ "$FILES" = "" ]; then
      FILES=*.srt
    fi
    for i in $FILES; do
	mv $i foo;
	sed < foo > $i 's: *$::; /^$/d'
	diff -wu foo $i
    done
    rm foo
}
# Add a prefix to specified files, separated by -.
# -s removes specfied old prefix.
prepend ()
{
  if [ "$1" = "-s" ]; then       # replace old start
    shift
    STRIP=$1
    shift
  fi
  PREFIX=$1
  shift
  for i in $*; do
    b=`basename $i`
    if [ "$STRIP" != "" ]; then
      new=$PREFIX${b/$STRIP/}
    else
      new=$PREFIX$b
    fi
    mv $i $new
  done
}
lg ()
{
    links -html-user-font-size 32 -G $*
}
# Use a2ps to print to printer with my preferences
A2ps ()
{
a2ps -1  -r -M A4 -f 8 | lpr
}
# Rename files with spaces in their names
# Supplied by Peter Jeremy.
despace ()
 {
   for i in "$@"; do
      mv "$i" $(echo "$i" |sed "s:[ ()]:-:g; s:&:and:g; s:':-:g; s/：//")
    done
 }
