315 lines
9.3 KiB
Bash
315 lines
9.3 KiB
Bash
|
|
# -*- sh -*-
|
||
|
|
# Copyright © 1991-2026, Bradley M. Kühn
|
||
|
|
# License: AGPLv3.0-or-later
|
||
|
|
|
||
|
|
HISTSIZE=33554432
|
||
|
|
HISTFILESIZE=33554432
|
||
|
|
set histappend=true
|
||
|
|
|
||
|
|
umask 077
|
||
|
|
export LANG="en_US.UTF-8"
|
||
|
|
export LANGUAGE="en_US.UTF-8"
|
||
|
|
export LC_TIME="en_GB.UTF-8"
|
||
|
|
export PERL_BADLANG=0
|
||
|
|
|
||
|
|
linksopts=""
|
||
|
|
|
||
|
|
GPG_TTY=$(tty)
|
||
|
|
export GPG_TTY
|
||
|
|
|
||
|
|
if [ ! -z "$http_proxy" ]; then
|
||
|
|
export HTTP_PROXY="$http_proxy"
|
||
|
|
fi
|
||
|
|
if [ ! -z "$ftp_proxy" ]; then
|
||
|
|
export FTP_PROXY="$ftp_proxy"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# I will need $HOST later
|
||
|
|
if [ -z "$HOST" ]; then
|
||
|
|
HOST=`/bin/hostname`
|
||
|
|
fi
|
||
|
|
|
||
|
|
MY_UID=`id -u`
|
||
|
|
|
||
|
|
# Enviornmemnt variables, which really shouldn't be living here but are
|
||
|
|
|
||
|
|
# tells cp, mv etc. to do VERSION_CONTROL (if you use the -b option)
|
||
|
|
export VERSION_CONTROL="numbered"
|
||
|
|
|
||
|
|
export CVS_RSH="/usr/bin/ssh"
|
||
|
|
|
||
|
|
export EDITOR="/usr/bin/vi"
|
||
|
|
export VISUAL="/usr/bin/vi"
|
||
|
|
|
||
|
|
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
|
||
|
|
alias urldecode='python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])"'
|
||
|
|
|
||
|
|
export PAGER="/usr/bin/less"
|
||
|
|
export LESS="-FXRe"
|
||
|
|
|
||
|
|
export MAILER="/usr/bin/mutt"
|
||
|
|
|
||
|
|
export TEX4HTINPUTS=/etc/tex4ht
|
||
|
|
export T4HTINPUTS=/etc/tex4ht
|
||
|
|
|
||
|
|
export RT_SUMMARY_FORMAT="%id7%queue7%subject40%requestor16"
|
||
|
|
|
||
|
|
if [ -f "/THIS_IS_SID" ]; then
|
||
|
|
export __THIS_IS_SID=1
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ `id -u` -eq 0 ]; then
|
||
|
|
PROMPT_CHAR='#'
|
||
|
|
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
||
|
|
else
|
||
|
|
if [ ! -z "$__THIS_IS_SID" ]; then
|
||
|
|
if [ -z "$UNMODIFIED_PATH" ]; then
|
||
|
|
UNMODIFIED_PATH=$PATH
|
||
|
|
fi
|
||
|
|
export PATH=$HOME/bin:/usr/lib/ccache:${UNMODIFIED_PATH}:~/.local/bin
|
||
|
|
export PATH=$HOME/bin:/usr/lib/ccache:${UNMODIFIED_PATH}:~/.local/bin
|
||
|
|
else
|
||
|
|
export UNMODIFIED_PATH=$PATH
|
||
|
|
export PATH=HOME/bin:/usr/lib/ccache:${PATH}:~/.local/bin
|
||
|
|
fi
|
||
|
|
PROMPT_CHAR='$'
|
||
|
|
fi
|
||
|
|
|
||
|
|
# If running interactively, then:
|
||
|
|
if [ "$PS1" ]; then
|
||
|
|
# FIXME: I should patch bash to make this a function
|
||
|
|
|
||
|
|
export HISTTIMEFORMAT="%R on %a (%F) "
|
||
|
|
export HISTCONTROL=ignoreboth
|
||
|
|
# This is often in /etc/bash.bashrc already, BTW...
|
||
|
|
if [ -z "$BASH_COMPLETION_VERSINFO" -a -f /etc/bash_completion ]; then
|
||
|
|
. /etc/bash_completion
|
||
|
|
fi
|
||
|
|
INPUTRC="~/.inputrc"
|
||
|
|
bind -f $INPUTRC
|
||
|
|
# stty crtscts
|
||
|
|
# stty -ixon
|
||
|
|
stty werase undef kill undef stop undef start undef quit undef
|
||
|
|
FIGNORE=".o:~:#"
|
||
|
|
|
||
|
|
# set up special bash variables
|
||
|
|
set bell-style=visible
|
||
|
|
|
||
|
|
# enable color support of ls
|
||
|
|
|
||
|
|
eval `dircolors -b ${HOME}/.dircolors`
|
||
|
|
|
||
|
|
function dategrok {
|
||
|
|
if [ ! -z "$2" ]; then
|
||
|
|
timezone=$2
|
||
|
|
else
|
||
|
|
if [ -z "$TZ" ]; then
|
||
|
|
timezone="US/Pacific"
|
||
|
|
else
|
||
|
|
timezone=$TZ
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
/usr/bin/perl -e 'use Date::Manip; Date_Init("TZ=$ARGV[0]"); $x = ParseDate($ARGV[1]); Date_Init("TZ=$ARGV[3]") if (defined $ARGV[3] and $ARGV[3] !~ /^\s*$/); print UnixDate($x, $ARGV[2]), "\n";' -- "$timezone" "$1" "%a %Y-%m-%d %H:%M:%S %Z%z" "$3"
|
||
|
|
}
|
||
|
|
function epoch {
|
||
|
|
dategrok "epoch $1"
|
||
|
|
}
|
||
|
|
alias gco="git checkout"
|
||
|
|
function ev {
|
||
|
|
evince "$@" 2>/dev/null
|
||
|
|
}
|
||
|
|
alias ls='/bin/ls -Bh --color=auto '
|
||
|
|
alias ll='/bin/ls -lBh --color=auto '
|
||
|
|
alias dir="ls -lFhp --color=auto"
|
||
|
|
alias dirp="dir \!*| less"
|
||
|
|
|
||
|
|
function scanletter {
|
||
|
|
if [ ! -z "$1" ]; then
|
||
|
|
startOpt="--batch-start=$1"
|
||
|
|
shift
|
||
|
|
fi
|
||
|
|
scanimage $startOpt -d 'hp5590' -x 215.889 -y 279.4 -v -p --batch="page%3.3d.tiff" --wait-for-button=yes --resolution 300 --source 'ADF' --mode Color --format tiff
|
||
|
|
}
|
||
|
|
function scanletternofeed {
|
||
|
|
if [ ! -z "$1" ]; then
|
||
|
|
startOpt="--batch-start=$1"
|
||
|
|
shift
|
||
|
|
fi
|
||
|
|
scanimage $startOpt -d 'hp5590' -x 215.889 -y 279.4 -v -p --batch="page%3.3d.tiff" --wait-for-button=yes --resolution 300 --source 'Flatbed' --mode Color --format tiff
|
||
|
|
}
|
||
|
|
function scanreceiptnofeed {
|
||
|
|
if [ ! -z "$1" ]; then
|
||
|
|
startOpt="--batch-start=$1"
|
||
|
|
shift
|
||
|
|
fi
|
||
|
|
scanimage $startOpt -d 'hp5590' -x 215.889 -y 226 -v -p --batch="page%3.3d.tiff" --wait-for-button=yes --resolution 300 --source 'Flatbed' --mode Color --format tiff
|
||
|
|
}
|
||
|
|
function scana4 {
|
||
|
|
if [ ! -z "$1" ]; then
|
||
|
|
startOpt="--batch-start=$1"
|
||
|
|
shift
|
||
|
|
fi
|
||
|
|
scanimage $startOpt -d 'hp5590' -x 210 -y 297 -v -p --batch="page%3.3d.tiff" --wait-for-button=yes --resolution 300 --source 'ADF' --mode Color --format tiff
|
||
|
|
}
|
||
|
|
function scana4nofeeder {
|
||
|
|
if [ ! -z "$1" ]; then
|
||
|
|
startOpt="--batch-start=$1"
|
||
|
|
shift
|
||
|
|
fi
|
||
|
|
scanimage $startOpt -d 'hp5590' -x 210 -y 297 -v -p --batch="page%3.3d.tiff" --wait-for-button=yes --resolution 300 --source 'Flatbed' --mode Color --format tiff
|
||
|
|
}
|
||
|
|
function colortiffstopdf {
|
||
|
|
if [ -z "$1" ]; then
|
||
|
|
output=final.pdf
|
||
|
|
else
|
||
|
|
output=$1
|
||
|
|
fi
|
||
|
|
for ii in page*.tiff; do
|
||
|
|
num=`echo $ii | /usr/bin/perl -pe 's/^page(\d+)\.tiff/$1/;'`
|
||
|
|
tiff2pdf -f -p letter -j $ii -o page${num}.pdf
|
||
|
|
done
|
||
|
|
set -x
|
||
|
|
pdftk page*pdf output $output
|
||
|
|
set +x
|
||
|
|
rm page*pdf
|
||
|
|
}
|
||
|
|
alias f=finger
|
||
|
|
alias j=jobs
|
||
|
|
alias h=history
|
||
|
|
alias pd=pushd
|
||
|
|
|
||
|
|
# force backups
|
||
|
|
|
||
|
|
alias cp="cp -b"
|
||
|
|
alias mv="mv -b"
|
||
|
|
alias rmtex="rm -f *.log *.dvi *.aux x.ps *.bak *.blg *.bbl *.idx *.ing *.ilg *.ind *.toc"
|
||
|
|
alias sq="ssh localhost -p 2222"
|
||
|
|
function supernice {
|
||
|
|
set -x
|
||
|
|
for i in $*; do
|
||
|
|
renice 19 $i
|
||
|
|
ionice -c3 -p $i
|
||
|
|
done
|
||
|
|
set +x
|
||
|
|
}
|
||
|
|
|
||
|
|
function xtermSetTitleBar {
|
||
|
|
if [ -z "$OVERRIDE_XTERM_TITLE" ]; then
|
||
|
|
$BKUHN_HOME/bin/xtermChangeName -t "${PROMPT_LEAD}:$abbrevPWD" -i $HOST
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
function overrideTitleBar {
|
||
|
|
export OVERRIDE_XTERM_TITLE="$*"
|
||
|
|
$BKUHN_HOME/bin/xtermChangeName -t $* -i $HOST
|
||
|
|
}
|
||
|
|
function restoreTitleBar {
|
||
|
|
export OVERRIDE_XTERM_TITLE=
|
||
|
|
}
|
||
|
|
LAST_HISTORY_WRITE=$SECONDS
|
||
|
|
DEFAULT_PROMPT_PWD_LENGTH=35
|
||
|
|
function prompt_command {
|
||
|
|
if [ $(($SECONDS - $LAST_HISTORY_WRITE)) -gt 300 ]; then
|
||
|
|
history -a
|
||
|
|
LAST_HISTORY_WRITE=$SECONDS
|
||
|
|
fi
|
||
|
|
# quick check to see if we need compute abbrevPWD again
|
||
|
|
if [ "$LAST_CACHE_PWD" == "$PWD" ]; then
|
||
|
|
return
|
||
|
|
fi
|
||
|
|
local resizableTerm
|
||
|
|
if [ $TERM == "xterm" -o $TERM == "xterm-color" ]; then
|
||
|
|
resizableTerm=$TERM
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ -z "$resizableTerm" -o ! -x /bin/stty ]; then
|
||
|
|
PROMPT_PWD_LENGTH=$DEFAULT_PROMPT_PWD_LENGTH
|
||
|
|
else
|
||
|
|
local cols
|
||
|
|
cols=`/bin/stty -a | /usr/bin/perl -ne 'print if s/^.*;\s+columns\s+(\d+)\s*;.*$/$1/';`
|
||
|
|
PROMPT_PWD_LENGTH=$[$cols/3]
|
||
|
|
fi
|
||
|
|
|
||
|
|
LAST_CACHE_PWD=$PWD
|
||
|
|
echo $LAST_CACHE_PWD | /bin/grep "^$HOME" >> /dev/null
|
||
|
|
|
||
|
|
if [ $? -eq 0 ]; then
|
||
|
|
PROMPT_PWD_LENGTH=$(($PROMPT_PWD_LENGTH - 2))
|
||
|
|
|
||
|
|
abbrevPWD=`echo $LAST_CACHE_PWD | awk -F$HOME '{print $2}'`
|
||
|
|
if [ $(echo -n $abbrevPWD | wc -c | tr -d " ") -gt $PROMPT_PWD_LENGTH ]; then
|
||
|
|
abbrevPWD="@@$(echo -n $abbrevPWD | sed -e "s/.*\(.\{$PROMPT_PWD_LENGTH\}\)/\1/")"
|
||
|
|
abbrevPWD="~/...$(echo -n $abbrevPWD | sed -e "s/@@[^\/]*\(.*\)/\1/")"
|
||
|
|
else
|
||
|
|
abbrevPWD="~$abbrevPWD"
|
||
|
|
fi
|
||
|
|
elif [ "$LAST_CACHE_PWD" == "$HOME" ]; then
|
||
|
|
abbrevPWD="~"
|
||
|
|
elif [ $(echo -n $PWD | wc -c | tr -d " ") -gt $PROMPT_PWD_LENGTH ]; then
|
||
|
|
abbrevPWD="@@$(echo -n $PWD | sed -e "s/.*\(.\{$PROMPT_PWD_LENGTH\}\)/\1/")"
|
||
|
|
abbrevPWD="...$(echo -n $abbrevPWD | sed -e "s/@@[^\/]*\(.*\)/\1/")"
|
||
|
|
else
|
||
|
|
abbrevPWD="$(echo -n $PWD)"
|
||
|
|
fi
|
||
|
|
# Next if handles case where last dir is longer than PROMPT_PWD_LENGTH, just use the
|
||
|
|
# last dir.
|
||
|
|
if [ $abbrevPWD == "~/..." -o $abbrevPWD == "..." ]; then
|
||
|
|
abbrevPWD="$(echo -n $LAST_CACHE_PWD | /usr/bin/perl -pe 's%^.*/([^/]+)%.../$1%;')"
|
||
|
|
fi
|
||
|
|
if [ ! -z "$resizableTerm" ]; then
|
||
|
|
xtermSetTitleBar
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
PROMPT_COMMAND=prompt_command
|
||
|
|
|
||
|
|
function wh {
|
||
|
|
ps auxww | /bin/grep -F $*
|
||
|
|
}
|
||
|
|
|
||
|
|
function latexps {
|
||
|
|
local fileBase sourceFile psFile dvipsOpts
|
||
|
|
|
||
|
|
# Find the file base from $1 -- it could be a latex or tex file
|
||
|
|
|
||
|
|
fileBase=`basename "$1" .latex`
|
||
|
|
if [ "$fileBase" == "$1" ]; then
|
||
|
|
fileBase=`basename "$fileBase" .tex`
|
||
|
|
if [ "$fileBase" == "$1" ]; then
|
||
|
|
fileBase=`basename "$fileBase" .`
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
# $2 will be the name of the Postscript file, otherwise it's x.ps
|
||
|
|
|
||
|
|
if [ -z "$2" ]; then
|
||
|
|
psFile="x.ps"
|
||
|
|
else
|
||
|
|
psFile="$2"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# $3 is options to dvips if it is there, otherwise, -t letter is used
|
||
|
|
|
||
|
|
if [ -z "$2" ]; then
|
||
|
|
dvipsOpts="-t letter"
|
||
|
|
else
|
||
|
|
dvipsOpts="$3"
|
||
|
|
fi
|
||
|
|
|
||
|
|
|
||
|
|
if [ -f "${fileBase}.latex" ]; then
|
||
|
|
sourceFile="${fileBase}.latex"
|
||
|
|
elif [ -f "${fileBase}.tex" ]; then
|
||
|
|
sourceFile="${fileBase}.tex"
|
||
|
|
else
|
||
|
|
echo "latexps: no LaTeX file matching your input: \"$1\""
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
latex $sourceFile
|
||
|
|
makeindex $fileBase
|
||
|
|
dvips $dvipsOpts "${fileBase}.dvi" -o $psFile
|
||
|
|
}
|
||
|
|
|
||
|
|
fi
|
||
|
|
|
||
|
|
trap - INT TERM EXIT
|