|
Warning: this is an htmlized version!
The original is across this link, and the conversion rules are here. |
#!/usr/bin/env zsh
# (find-es "zsh" "zshrc-hash-bang-eval")
# Edrx's .zshrc - 2007dec21
# (But don't trust the date above,
# it's not updated automatically)
# (find-es "zsh" "zsh-files")
# «.prompt» (to "prompt")
# «.less» (to "less")
# «.underline_as_green» (to "underline_as_green")
# «.ee» (to "ee")
# «.eev» (to "eev")
# «.eev_rcfiles_zshrc» (to "eev_rcfiles_zshrc")
# «.eegcc» (to "eegcc")
# «.eet» (to "eet")
# «.eeg» (to "eeg")
# «.demo» (to "demo")
# «.path» (to "path")
# «.Snarf» (to "Snarf")
# «.psne» (to "psne")
# «.psne-rfc» (to "psne-rfc")
# «.setmirrordir» (to "setmirrordir")
# «.BSD» (to "BSD")
# «.bsd_manpages» (to "bsd_manpages")
# «.netselect» (to "netselect")
# «.pdsc» (to "pdsc")
# «.apt» (to "apt")
# «.debbasename» (to "debbasename")
# «.installeddebs» (to "installeddebs")
# «.availabledebs» (to "availabledebs")
# «.pfilenames» (to "pfilenames")
# «.dmissing» (to "dmissing")
# «.Pgrep» (to "Pgrep")
# «..debs» (to ".debs")
# «.glimpse» (to "glimpse")
# «.agrep» (to "agrep")
# «.console» (to "console")
# «.quickkeys» (to "quickkeys")
# «.charsets» (to "charsets")
# «.setbell» (to "setbell")
# «.keys» (to "keys")
# «.run-help» (to "run-help")
# «.completion» (to "completion")
# «.TeX» (to "TeX")
# «.dvifonts» (to "dvifonts")
# «.savetmptex» (to "savetmptex")
# «.printing» (to "printing")
# «.gsdj» (to "gsdj")
# «.ps2pdj» (to "ps2pdj")
# «.a2ps» (to "a2ps")
# «.pstotext» (to "pstotext")
# «.ps2up-letter» (to "ps2up-letter")
# «.psmyflip» (to "psmyflip")
# «.zxdvi» (to "zxdvi")
# «.rexdvi» (to "rexdvi")
# «.regv» (to "regv")
# «.xydemo» (to "xydemo")
# «.diagxydemo» (to "diagxydemo")
# «.pstdemo» (to "pstdemo")
# «.testfontcmds» (to "testfontcmds")
# «.tdiags» (to "tdiags")
# «.mytoctoeevlinks» (to "mytoctoeevlinks")
# «.makebbl» (to "makebbl")
# «.Icon» (to "Icon")
# «.stop-restart-services» (to "stop-restart-services")
# «.restart_inetd» (to "restart_inetd")
# «.gpm» (to "gpm")
# «.unsetall» (to "unsetall")
# «.chroot-redhat-zsh» (to "chroot-redhat-zsh")
# «.loop_device» (to "loop_device")
# «.filters» (to "filters")
# «.man2t» (to "man2t")
# «.filter» (to "filter")
# «.zcatinfo» (to "zcatinfo")
# «.find-ess» (to "find-ess")
# «.spl» (to "spl")
# «.split_transfer» (to "split_transfer")
# «.perlsendfile» (to "perlsendfile")
# «.modem_interact» (to "modem_interact")
# «.expect_isp» (to "expect_isp")
# «.inx-up» (to "inx-up")
# «.ppp-up» (to "ppp-up")
# «.inx-upe» (to "inx-upe")
# «.ig-up» (to "ig-up")
# «.makeL» (to "makeL")
# «.makepage» (to "makepage")
# «.makepagefromtar» (to "makepagefromtar")
# «.makeindexhtmls» (to "makeindexhtmls")
# «.lstoindexhtml_lua_maybe» (to "lstoindexhtml_lua_maybe")
# «.bigmakepage» (to "bigmakepage")
# «.uploadtoanggtmp» (to "uploadtoanggtmp")
# «.X» (to "X")
# «.xset_MATH» (to "xset_MATH")
# «.inix» (to "inix")
# «.inix-lea» (to "inix-lea")
# «.emacs-unibyte» (to "emacs-unibyte")
# «.strace» (to "strace")
# «.modules» (to "modules")
# «.cdrom» (to "cdrom")
# «.vt» (to "vt")
# «.lua» (to "lua")
# «.swig» (to "swig")
# «.makelua50» (to "makelua50")
# «.make» (to "make")
# «.scp» (to "scp")
# «.remote-accounts» (to "remote-accounts")
# «.save-input» (to "save-input")
# «.mydiff» (to "mydiff")
# «.makeapacheindex» (to "makeapacheindex")
# «.X1» (to "X1")
# «.showperms» (to "showperms")
# «.emacs-cvs» (to "emacs-cvs")
# «.dout» (to "dout")
# «.gunzip-nd» (to "gunzip-nd")
# «.partitionids» (to "partitionids")
# «.filedevice» (to "filedevice")
# «.ln-sf-safe» (to "ln-sf-safe")
# «.netbotanic» (to "netbotanic")
# «.fvwm» (to "fvwm")
# «.fvwm-replace» (to "fvwm-replace")
# «.prep-home-cdd» (to "prep-home-cdd")
# «.prep-vt» (to "prep-vt")
# «.prep-X» (to "prep-X")
# «.a» (to "a")
# «.ae» (to "ae")
# «.setxtermtitle» (to "setxtermtitle")
# «.makecdrdaotoc» (to "makecdrdaotoc")
# «.showcdrdaotoc» (to "showcdrdaotoc")
# «.myplay» (to "myplay")
# «.p» (to "p")
# «.plog» (to "plog")
# «.silentwav» (to "silentwav")
# «.ptowav» (to "ptowav")
# «.chroot-sarge» (to "chroot-sarge")
# «.mywhoami» (to "mywhoami")
# «.testmail» (to "testmail")
# «.dotxpm» (to "dotxpm")
# «.autopasswd» (to "autopasswd")
# «.pucmailget» (to "pucmailget")
# «.umlkill» (to "umlkill")
# «.cddbtrackname» (to "cddbtrackname")
# «.eev-current» (to "eev-current")
# «.eev-current-upload» (to "eev-current-upload")
# «.upload» (to "upload")
# «.prep-apti» (to "prep-apti")
# «.prep-apti-builddeps-emacs» (to "prep-apti-builddeps-emacs")
# «.prep-X-reconfigure» (to "prep-X-reconfigure")
# «.prep-X-nodm» (to "prep-X-nodm")
# «.prep-guest-mount» (to "prep-guest-mount")
# «.aa» (to "aa")
# «.ASROOT» (to "ASROOT")
# «.intermail» (to "intermail")
# «.mymkdircd» (to "mymkdircd")
# «.myincr» (to "myincr")
# «.ncget» (to "ncget")
# «.ncsend» (to "ncsend")
# «.myip-ppp0» (to "myip-ppp0")
# «.fvwm-bw» (to "fvwm-bw")
# «.hh» (to "hh")
# «.prep-Contents» (to "prep-Contents")
# «.regv-beamer» (to "regv-beamer")
# «.Xfontslists» (to "Xfontslists")
# «.router-config-jan2006» (to "router-config-jan2006")
# «.wrap» (to "wrap")
# «.cddb2rentracks» (to "cddb2rentracks")
# «.wavsandtracks» (to "wavsandtracks")
# «.ruby» (to "ruby")
# «.mplayer» (to "mplayer")
# «.mysqueak» (to "mysqueak")
# «.eth_multicast_diagnose» (to "eth_multicast_diagnose")
# «.asgraftpoints» (to "asgraftpoints")
# «.music_dirs» (to "music_dirs")
# «.psne-over» (to "psne-over")
# «.MAKEDEV_create» (to "MAKEDEV_create")
# «.eeh» (to "eeh")
# «.mesk-up» (to "mesk-up")
# «.mesk-ip» (to "mesk-ip")
# «.pers-up» (to "pers-up")
# «.dek-up» (to "dek-up")
# «.muttfetchmail» (to "muttfetchmail")
# «.tcl-tk» (to "tcl-tk")
# «.tarcp» (to "tarcp")
# «.fvwm-netbsd» (to "fvwm-netbsd")
# «prompt» (to ".prompt")
# (find-es "zsh" "prompt")
# In machines in which I can chroot to other distro I usually put
# something like
# export _CHROOTSTR=":d"
# or export _CHROOTSTR=":rh"
# in /etc/zshenv:
# (find-fline "/etc/zshenv" "_CHROOTSTR")
# (find-fline "/debian/etc/zshenv" "_CHROOTSTR")
export machine=$(uname -n)
if [[ $machine = angg ]]; then
PS1="%d(%n$_CHROOTSTR)# "
else
PS1="%d(%n:$machine[1,2]$_CHROOTSTR)# "
fi
PS2='> '
# «less» (to ".less")
# (find-es "console" "less")
export LESSCHARDEF=8bcccbcc18b95.b27.b99.b
export LESS='-MM -C'
export PAGER=less
# «underline_as_green» (to ".underline_as_green")
# (find-angg ".emacs" "underline_as_green")
# (find-k2file "drivers/char/console.c")
# (find-k2tag "setterm_command")
# (find-k22tag "setterm_command")
# (find-man "4 console_codes" "Set color n as the underline color")
# (find-man "1 less" "-u or --underline-special")
function myreset () {
if [[ $TERM = linux ]] echo -n '\e(K\e[1;2]'
}
# (find-node "(sh-utils)tty invocation")
tty -s && myreset
# (find-fline "/etc/zshenv")
# (find-zshnode "Shell Builtin Commands" "core")
limit coredumpsize 0
alias l='less'
alias laf='ls -laF'
alias ls='ls -aF'
[[ -x dircolors ]] && eval `dircolors`
alias w='which'
alias Pwd=/bin/pwd
alias rezshrc='. ~/.zshrc'
# "rezshrc" lets me reload my .zshrc after changing it, but I need
# some tricks to avoid making $PATH get longer at each time...
# «path» (to ".path")
[[ "$ORIGPATH" == "" ]] && export ORIGPATH=$PATH
export EDRXPATH=$ORIGPATH:.:$HOME/bin:$HOME/EXPECT:$HOME/TCL
export EDRXPATH=$ORIGPATH:.:$HOME/bin:$HOME/EXPECT:$HOME/TCL:$HOME/pkg/bin
# ^ 2008, for NetBSD and pkgsrc
if [[ -f /etc/debian_version ]]; then
export DISTR=debian
export PATH=$EDRXPATH:/usr/games
else
# export DISTR=redhat
# alias emacs=/usr/bin/emacs-nox
# Depois eu cuido do caso RedHat, agora eu tou usando so' Debian e BSD
export PATH=$EDRXPATH:/sbin:/usr/sbin:
fi
# «ee» (to ".ee")
# «eev» (to ".eev")
# «eev_rcfiles_zshrc» (to ".eev_rcfiles_zshrc")
# Beginning of the eev block:
# See: (find-eev "eev-rctool" "new_block_zshrc")
# (find-eev-update-links)
#
export EEVTMPDIR ;: ${EEVTMPDIR:=~/.eev}
export EE ;: ${EE:=$EEVTMPDIR/ee.sh}
function ee () { set -v; . $EE$*; set +v; }
#
export EEVDIR ;: ${EEVDIR:=~/eev-current}
export EEVRCDIR ;: ${EEVRCDIR:=$EEVDIR/rcfiles}
export EEG ;: ${EEG:=$EEVTMPDIR/ee.eeg}
export EEGDB ;: ${EEGDB:=$EEVTMPDIR/ee.gdb}
export EETEX ;: ${EETEX:=$EEVTMPDIR/ee.tex}
#
export EEC ;: ${EEC:=$EEVTMPDIR/ee.c}
export EETMPC ;: ${EETMPC:=$EEVTMPDIR/tmp.c}
export EEAOUT ;: ${EEAOUT:=$EEVTMPDIR/ee.aout}
function eegcc () {
cat $EETMPC - > $EEC
gcc $* -o $EEAOUT $EEC
}
alias eec=$EEAOUT
#
# To define $S and psne uncomment the line below (or copy it,
# uncommented, to outside of the eev block):
# if [ -e $EEVTMPDIR/psne.sh ]; then . $EEVTMPDIR/psne.sh; fi
# (find-eevtmpfile "psne.sh")
#
# End of the eev block.
if [ -e $EEVTMPDIR/psne.sh ]; then . $EEVTMPDIR/psne.sh; fi
# (find-node "(zsh)Parameter Expansion" "${NAME:=WORD}")
# (find-node "(zsh)Shell Builtin Commands" ": [ ARG ... ]")
export EEV=$EEVDIR
export EEVT=$EEVTMPDIR
export EEVR=$EEVRCDIR
export EEVT=$EEVTMPDIR
export EEVE=$EEVDIR/examples
export EEVA=$EEVDIR/article
# «eegcc» (to ".eegcc")
# (find-eevtmpfile "tmp.c")
# 2004oct02; to do: use #include, CFILE, W, CFLAGS.
# EETMPC=$EEVTMPDIR/tmp.c
# EEC=$EEVTMPDIR/ee.c
# EEAOUT=$EEVTMPDIR/ee.aout
# function eegcc () {
# cat $EETMPC - > $EEC
# gcc $* -o $EEAOUT $EEC
# }
alias eec=$EEAOUT
#
# A test:
# eegcc <<<'int main(){ printf("%d\n", isatty(0)); exit(0); }'; eec; echo | eec
export PATH=$EDRXPATH
export ES=~/e
export EET=~/TK/emacs.eew
#alias eet=$EET
# «eet» (to ".eet")
# (find-angg ".emacs" "eet")
export EETMP=/tmp/ee.sh
alias eet='set -v;. $EETMP;set +v'
# (find-eev "eev-util" "install_dotfiles")
# «eeg» (to ".eeg")
# «demo» (to ".demo")
# (find-angg "EXPECT/eeg")
# (find-angg "EXPECT/eeg2")
# (find-angg "EXPECT/eeg3")
# (find-angg "EEG/gdbk.eeg")
# (find-angg "EEG/gdbk.eeg3")
# (find-angg "EEG/emacs1.eeg3")
function demo () {
mkdir -p ~/tmp/
case $1 in
gdbk) cp ~/EEG/gdbk.eeg3 $EEG
eeg3 screen emacs -nw $ES/anatocc.e;;
emacs1) cp ~/EEG/emacs1.eeg3 $EEG
rm -v ~/tmp/foo ~/tmp/otherfoo
eeg3 screen emacs -nw ~/tmp/foo;;
gdbk-xemacs) cp ~/EEG/gdbk.eeg3 $EEG
echo "Warning: this one is a bit broken..."
eeg3 screen xemacs -nw $ES/anatocc.e;;
*) w demo;;
esac
}
# Functions for consulting code-c-ds from outside Emacs
# Oops, substitute-in-file-name does not expand "~"s
# (find-node "(zsh)Filename Expansion")
# (find-node "(zsh)Shell Builtin Commands" "eval [ ARG ... ]")
# function eev-dir () { gnudoit "(substitute-in-file-name ee-$1dir)" }
function eev-dir () { eval echo $(gnudoit ee-$1dir) }
function eev-file () { echo $(eev-dir $1)$2 }
function eev-cd () { cd $(eev-file $1 $2) }
export TERM
export EDITOR=gnuclient
export ignoreeof=10
setopt autocd interactivecomments
umask 022
#####
#
# /snarf, $S, psne and friends
#
#####
# «Snarf» (to ".Snarf")
# (find-fline "~/PERL/urlchop")
# (find-fline "~/.psne.log")
if [[ -e /snarf ]]; then
export S=/snarf
else
export S=$HOME/snarf
fi
function perlurl () {
perl -e '
$_ = $url = $ARGV[0];
(($url, $prot, $usrpasswd, $site, $port, $path, $fname, $query) =
m%^((ftp|https?|file)://([^/@]*@)?([^@/:]*)(:[0-9]*)?/([^?]*/|)([^/?]*)(\?.*)?)$%)
|| die "\"$ARGV[0]\": not an url\n";
'$1 $*[2,-1]
}
function urldir () { perlurl 'print "$ENV{S}/$prot/$site/$path\n";' $1 }
function urlprot () { perlurl 'print "$prot\n";' $1 }
function urlfile () { perlurl 'print "$fname$query\n";' $1 }
# Tests:
# urldir http://www.cl.cam.ac.uk/users/gmb/index.html
# urlfile http://www.cl.cam.ac.uk/users/gmb/index.html
# «psne» (to ".psne")
# (find-angg "bin/_psne")
function psne-pl () {
ud=$(urldir $1) && {
mkdir -p $ud && cd $ud && {
echo $1 >> ~/.psne.log
wget $1 $*[2,-1]
} } }
alias psne=psne-pl
function psner () {
echo - $* >> ~/.psne.log
cd $S/http/ &&
wget -r $*
}
function psner-ftp () {
echo - $* >> ~/.psne.log
cd $S/ftp/ &&
wget -r $*
}
function psnedebfrom () {
for i in $(awk '{print $NF}'); do
psne $1/$i
done
}
alias psnedeb='psnedebfrom $FDEBIAN'
function psnecd () { cd $(urldir $1) }
function psnec () { urldir $1 && cd $(urldir $1) && wget -c $1 }
# For several different kinds of desperate cases.
# (find-es "http" "disguise-user-agent")
export AGENT_LYNX='Lynx/2.8.3rel.1 libwww-FM/2.14'
function lsne () {
ud=$(urldir $1) && {
mkdir -p $ud && cd $ud && {
echo $1 >> ~/.psne.log
lynx -source $1 $*[2,-1]
} } }
# znse is a rather minimalistic ancestor of psne.
# Use it like this:
# zsne ftp linux.if.usp.br/debian ls-lR.gz
function zsne () {
cd $S/$1 &&
mkdir -p $2 &&
cd $2 &&
# lynx -source $1://$2/$3 > $3
wget $1://$2/$3
}
# «psne-rfc» (to ".psne-rfc")
# (find-rfcfile "")
function psne-rfc () {
for i in $*; do psne http://www.ietf.org/rfc/rfc$i.txt; done
}
# «setmirrordir» (to ".setmirrordir")
# (find-es "snarf" "setmirrordir")
# Example:
# setmirrordir /snarf/ftp/ftp.debian.org/debian/ ftp://foobar.org/pub/debian/
function setmirrordir() { (
DEST=$(echo $1 | sed 's_/*$__')
MIRROR=$(echo $2 \
| sed 's_^\(ftp\|http\)://_/snarf/\1/_' \
| sed 's_/*$__')
mkdir -p $(dirname $MIRROR)
rm -f $MIRROR
if [[ -e $MIRROR ]]; then
echo $MIRROR exists!
else
ln -s $DEST $MIRROR
fi
laf $MIRROR
#laf $MIRROR/
) }
# debian/tex/perl/etc mirrors and local repositories
# (find-es "debian-net" "debian_mirrors")
export FLH=file://localhost
# w3m $FLH/usr/doc/w3m/MANUAL.html#Key:orig
#export FDEBIAN_BR=ftp://ftp.br.debian.org/debian
#export FDEBIAN_US=ftp://ftp.us.debian.org/debian
#export FDEBIAN_US_H=http://ftp.us.debian.org/debian
#export FDEBIAN=$FDEBIAN_US
export SDEBIAN=$S/ftp/ftp.debian.org/debian
#export FSECDEBIAN=ftp://security.debian.org/debian-security
#export FSECDEBIAN_H=http://security.debian.org/debian-security
#export SSECDEBIAN=$S/ftp/security.debian.org/debian-security
#
#export FNUDEBIAN_MAINZ=ftp://ftp.uni-mainz.de/pub/Linux/debian-non-US
#export FNUDEBIAN=$FNUDEBIAN_MAINZ
#export SNUDEBIAN=$S/ftp/ftp.debian.org/debian-non-US
#
#export FIDEBIAN=ftp://ftp.jp.debian.org/debian-incoming
#export SIDEBIAN=$S/ftp/ftp.jp.debian.org/debian-incoming
#
#export FCTAN_CDROM=ftp://ftp.cdrom.com/pub/tex/ctan
#export FCTAN_RIKEN=ftp://ftp.riken.go.jp/pub/tex-archive
#export FCTAN_TUG=ftp://ctan.tug.org/tex-archive
#export FCTAN=$FCTAN_TUG
#export SCTAN=$S/ftp/ftp.rge.com/pub/tex
#
#export FCPAN=ftp://ftp.cdrom.com/pub/perl/CPAN
#export SCPAN=$S/ftp/ftp.cdrom.com/pub/perl/CPAN
#
#export ALCATCL=ftp://ftp.neosoft.com/languages/tcl
#export SALCATCL=$S/ftp/ftp.neosoft.com/languages/tcl
#
#export FPGUT=ftp://sunsite.unc.edu/pub/docs/books/gutenberg
#export FSUNSITE=http://sunsite.unc.edu/pub/Linux
#export LCD=$S/ftp/gatekeeper.dec.com/pub/GNU/elisp-archive
#export SPGUT=$S/ftp/sunsite.unc.edu/pub/docs/books/gutenberg
#export SSUNSITE=$S/ftp/sunsite.unc.edu/pub/Linux
# «BSD» (to ".BSD")
# (find-angg ".zshrc.local.bsd")
#export FNBSD=ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-1.4.2/i386
#export SNBSD=$S/ftp/ftp.netbsd.org/pub/NetBSD/NetBSD-1.4.2/i386
#export BSDBOOKS=/freebsd/usr/share/doc/en_US.ISO_8859-1/books
#export FNETBSD152=ftp://archive.progeny.com/NetBSD/NetBSD-1.5.2
#export SNETBSD152=$S/ftp/archive.progeny.com/NetBSD/NetBSD-1.5.2
#export FNETBSD=ftp://archive.progeny.com/NetBSD
#export SNETBSD=$S/ftp/archive.progeny.com/NetBSD
# «bsd_manpages» (to ".bsd_manpages")
# (find-es "man" "bsd_manpages")
# (find-es "netbsd" "netbsd-manpages")
# (find-angg "bin/netbsdman")
#export NETBSDMANPATH=/var/_netbsdman/usr/share/man:/var/_netbsdman/usr/share/perl/man:/var/_netbsdman/usr/pkg/man
alias man-freebsd='MANPATH=/var/_freebsdman/usr/share/man:/var/_freebsdman/usr/share/perl/man man'
# «netselect» (to ".netselect")
# (find-es "debian-net" "debian_mirrors")
function mynetselect () {
netselect -vvv $* |& tee ~/o
agrep ' ok ' < ~/o \
| awk '{printf "%s %s %s\n", substr($0, 73), substr($0, 39, 33),
substr($0, 1, 37)
}' \
| sort -r \
| tee ~/o2
}
#####
#
# Debian: pdsc, apt, dmissingp, Pgrepp
#
#####
# «pdsc» (to ".pdsc")
# (find-angg ".zshrc" "pdsc")
function perldsc () {
perl -e '
$_ = $dsc = $ARGV[0];
(($path, $name, $ver, $build) =
m%^(.*/)?(.*?)_(.*?)(-[0-9.a-z]+)?\.dsc$% )
|| die "\"$ARGV[0]\": not a dsc\n";
'$1 $*[2,-1]
}
function dscdir () { perldsc 'print "/usr/src/$name-$ver\n"' $1 }
function pdsc () { pdsc_ $1 -sn -x }
function pdsc_ () {
D=$(dscdir $1) && {
rm -Rv $D
cd /usr/src/
dpkg-source $*[2,-1] $1
cd $D
}
}
# Example:
# pdsc /debian/dists/slink/main/source/sound/workbone_2.40-1.dsc
# (find-fline "/usr/bin/dpkg-source")
function dscdir_usrc () { perldsc 'print "'$usr_src'/$name-$ver\n"' $1 }
function pdsc_usrc () { pdsc_usrc_ $1 -sn -x }
function pdsc_usrc_ () {
D=$(dscdir_usrc $1) && {
rm -Rv $D
cd $usr_src/
dpkg-source $*[2,-1] $1
cd $D
}
}
# (find-es "dpkg" "all-installed-.debs")
# «apt» (to ".apt")
SUDO=sudo
function apti () { $SUDO apt-get install $* }
function aptii () { $SUDO aptitude install $* }
function aptrm () { $SUDO apt-get remove $* }
# alias apti='$SUDO apt-get install'
# alias aptrm='$SUDO apt-get remove'
#
# (find-es "dpkg" "local_apt_repository")
function dpkg-scan_p () {
dpkg-scanpackages $1/binary-i386 /dev/null '' \
| tee $1/binary-i386/Packages \
| gzip -c6 > $1/binary-i386/Packages.gz
}
function dpkg-scan_s () {
dpkg-scansources $1 \
| tee $1/source/Sources \
| gzip -c9 > $1/source/Sources.gz
}
function dpkg-scan_p+s () {
dpkg-scan_p $1
dpkg-scan_s $1
}
function aptu-local-i386 () {
cd /usr/src/.debs/
# Argh:
rm -R dists/
( D=dists/potato/local
DB=$D/binary-i386
mkdir -p $DB
cp -li *.deb $DB
DS=$D/source
mkdir -p $DS
cp -li /usr/src/.dscs/*.dsc $DS
cp -li /usr/src/.dscs/*.gz $DS
cp -li /usr/src/.dscs/*.changes $DS
dpkg-scan_p+s $D
)}
# «dmissing» (to ".dmissing")
# (to "prep-Contents")
# (find-apthowtofile "apt-howto.en.txt.gz" "apt-file search")
#
CONTENTSI386S=(
$S/http/ftp.br.debian.org/debian/dists/sarge/Contents-i386
)
CONTENTSI386SZ=(
$S/http/ftp.br.debian.org/debian/dists/sarge/Contents-i386.gz
)
# function dmissing () { agrep -h $* $CONTENTSI386S }
function dmissing () { zgrep -h $* $CONTENTSI386SZ }
function dmissingp () {
agrep -h $* $SDEBIAN/dists/potato/Contents-i386 \
$SNUDEBIAN/dists/potato/non-US/Contents-i386
}
# «Pgrep» (to ".Pgrep")
#function slinksgrep () { cd /big/; find slinks* | grep $* }
function Pgrep_ () {
perl -e '$/="\n\n"; while (<>) { '$1' && print $_ }'
}
function Pgrepp () {
for i in \
/hdd6/debian/dists/potato/{main,contrib}/binary-i386/Packages \
$SDEBIAN/dists/potato/non-free/binary-i386/Packages \
$SNUDEBIAN/dists/potato/non-US/main/binary-i386/Packages; do
echo "\n\n----> $i\n"
Pgrep_ $1 < $i
done
}
# «debbasename» (to ".debbasename")
function debbasenames () {
perl -nle ' s/[0-9](:|%3a)//; s:^.*/([^/]*)$:\1:;
s/_(i386|all)\.deb$/.deb/; print "$_";
'
}
function debbasename () {
print -l $* | debbasenames
}
export LOCALDEBDIR=/usr/src/.debs/binary-i386/web
function movelocaldeb () {
for i in $*; do
j=$(debbasename $i)
mv -v $i $LOCALDEBDIR/$j
done
}
#####
#
# Debian: high-level functions based on grep-dctrl
#
#####
# «installeddebs» (to ".installeddebs")
# «availabledebs» (to ".availabledebs")
# (find-es "dpkg" "installeddebs")
# (find-zsh "installeddebs | sort")
# (find-zsh "installeddebs | sort | tee ~/oinstalleddebs")
# (find-fline "~/oinstalleddebs")
function dctrldebnames () {
perl -nle '
m/Package: (.*)/ and $s = $1;
m/Version: ([0-9]+:)?(.*)/ and print "$s", "_$2.deb";
'
}
function installeddebs_ () {
grep-dctrl --show-field=Package,Version --field=Status ' installed' \
| dctrldebnames
}
alias installeddebs='cat /var/lib/dpkg/status | installeddebs_'
alias availabledebs='cat /var/lib/dpkg/available | dctrldebnames'
# «pfilenames» (to ".pfilenames")
# (find-es "dpkg" "pfilenames")
function pfilenames () {
grep-dctrl . -s Filename | awk '{print PREFIX $2}' PREFIX=$1
}
# «.debs» (to "..debs")
function getdatatargz () { ar p $1 data.tar.gz }
function debtarxvzf () { getdatatargz $1 | tar -xvzf - $*[2,-1] }
function debtartvzf () { getdatatargz $1 | tar -tvzf - $*[2,-1] }
function debtartzf () { getdatatargz $1 | tar -tzf - $*[2,-1] }
export POTATO=/big/potato/dists/potato
export SPOTATO=$SDEBIAN/dists/potato
export MI386=main/binary-i386
export CI386=contrib/binary-i386
export NFI386=non-free/binary-i386
#####
#
# glimpse and agrep
#
#####
# «glimpse» (to ".glimpse")
alias gglimpse='cd /usr/src/gimp-1.0.0/; glimpse -y -H .'
alias kglimpse='cd /usr/src/linux-2.0/; glimpse -y -H .'
alias k22glimpse='cd /usr/src/linux-2.2/; glimpse -y -H .'
alias glglimpse='cd /usr/src/glibs-2.0.7t/; glimpse -y -H .'
alias pglimpse='cd /usr/lib/perl5/; glimpse -y -H .'
alias iglimpse='cd /usr/src/icon/; glimpse -y -H .'
alias eglimpse='cd /usr/share/emacs/19.34/lisp/; glimpse -y -H .'
alias e20glimpse='cd /usr/share/emacs/20.7/lisp/; glimpse -y -H .'
alias e20sglimpse='cd /usr/src/emacs20-20.3/; glimpse -y -H .'
alias e21glimpse='cd /usr/src/emacs21-21.1/lisp/; glimpse -y -H .'
alias e21sglimpse='cd /usr/src/emacs21-21.1/; glimpse -y -H .'
alias holglimpse='cd /usr/src/hol90.10/; glimpse -y -H .'
alias smlglimpse='cd /usr/src/sml-nj-110/; glimpse -y -H .'
alias bfglimpse='cd /usr/src/boot-floppies-2.1.8/; glimpse -y -H .'
alias gdbglimpse='cd /usr/src/gdb-4.17/; glimpse -y -H .'
alias manglimpse='cd /tmp/man/; glimpse -y -H .'
alias lysrcglimpse='cd /usr/src/lynx-2.8.3/; glimpse -y -H .'
alias glibcglimpse='cd /usr/src/glibc-2.1.3/glibc-2.1.3/; glimpse -y -H .'
#
# «agrep» (to ".agrep")
function dtxagrep () { cd /usr/share/texmf/; agrep $* $(<.files.dtx) }
function lsrcagrep () { cd /usr/share/texmf/source/latex; agrep $* $(<.files-)}
function fsagrep () { cd /usr/src/gforth-0.4.0/; agrep $* $(<.files.fs) }
function cbagrep () { cd ~/CB/; agrep $* 2*.i }
function bfagrep () { cd /usr/src/bigforth/; agrep $* *.str *.scrz }
function potsrcgrep () { cd ~/tmp/; grep $* potsrc* }
function nhagrep () { cd /usr/doc/nethack/spoilers/
for i in *.gz; do echo $i; zcat $i | agrep $* ; done
}
#####
#
# VT fonts and keyboard tables
#
#####
# «console» (to ".console")
# (find-angg ".zshrc.local.bsd" "80x50")
# (find-fline "~/MTA/Makefile")
alias 850='(cd ~/vtutil4/; make 850)'
alias 437='(cd ~/vtutil4/; make 437)'
alias iso='(cd ~/vtutil4/; make iso)'
alias iso='(cd ~/vtutil4/; make isomath.8.setfont)'
alias iso-orig='(cd ~/vtutil4/; make iso-orig)'
alias 16='(cd ~/vtutil4/; make 16)'
#alias 850='setfont ~/replace/ega1.8; loadkeys ~/replace/defkeymap850b.map'
#alias math850='(cd ~/vtutil/; make math850; quickkeys)'
#alias math='(cd ~/vtutil/; make math; quickkeys)'
#alias math16='(cd ~/vtutil/; make math16)'
#alias 512='math; cd ~/vtutil; make newtest'
#alias 850='(cd ~/vtutil/; make 850)'
#alias 437='(cd ~/vtutil/; make 437)'
#alias iso='setfont iso01.f08; loadkeys ~/replace/defkeymap-iso.map'
#alias iso='~/MTA/vtutil quicksetfont ~/replace/iso01.f08
# loadkeys ~/replace/defkeymap-iso.map'
alias mystm='SVGATextMode -t ~/replace/TextConfig.angg'
alias 80x50=mystm
alias 132='mystm 132x60x9'
alias 1='iso'
alias 2='math'
alias 4='loadkeys dvorak'
# «quickkeys» (to ".quickkeys")
# (find-node "(coreutils)Changing Special Permissions")
# (eev "laf /sbin/kbdrate; sudo chmod u+s /sbin/kbdrate; laf /sbin/kbdrate")
# alias quickkeys='(cd ~/MTA/; ./vtutilsh vtutil setkbdrepeat 0 100)'
alias quickkeys='/sbin/kbdrate -r 30.0 -d 250'
alias quickkeys-X='xset r rate 250 30'
# «charsets» (to ".charsets")
# (find-es "charsets" "tcs")
#alias 850toiso='tcs -f ps2 -t latin1'
#alias isoto850='tcs -f latin1 -t ps2'
# (find-es "print" "tcs_patch")
#alias 850toiso='tcs -f ps2 -t latin1-850'
#alias isoto850='tcs -f latin1-850 -t ps2'
# (find-angg "vtutil/Makefile")
alias isoto850='tr $(<~/vtutil/table_latin) $(<~/vtutil/table_850)'
alias 850toiso='tr $(<~/vtutil/table_850) $(<~/vtutil/table_latin)'
# (find-angg "MTA/Makefile")
#alias math='setfont ~/MTA/math1.8; loadkeys ~/MTA/math850.map'
#alias iso='setfont ~/MTA/latinmath.8; loadkeys ~/MTA/latinmath.map'
#alias math='(cd ~/vtutil/; make 850)'
#alias iso='(cd ~/vtutil/; make iso)'
#alias 16='(cd ~/vtutil/; make 16)'
#alias lmath='iso'
#alias math='(cd ~/vtutil/; make math850.setall)'
#alias iso='(cd ~/vtutil/; make mathlatin.setall)'
#alias 16='(cd ~/vtutil/; make 16)'
# «setbell» (to ".setbell")
# (find-es "console" "setbell")
function setbell () {
echo -ne "\033[10;$1]\033[11;$2]"
}
function softbell () { setbell 80 22 }
function defaultbell () { setbell 750 125 }
#####
#
# magical zsh keys
#
#####
# «keys» (to ".keys")
# Note: "bindkey" used to break tab completion in zsh-3.1.6.
# Solution: switch cowardly to 3.0.7 and prepare to hunt the bug.
# (find-es "zsh" "bindkey_bug")
# bindkey "^W" kill-region
# bindkey "^[[1~" beginning-of-line
# bindkey "^[[3~" delete-char
# bindkey "^[[4~" end-of-line
# bindkey "^[m" menu-complete
# bindkey "^[M" reverse-menu-complete
# (find-node "(zsh)Description of Options" "AUTO_LIST")
# (find-node "(zsh)Completion Widgets")
setopt autolist
# «run-help» (to ".run-help")
# (find-es "zsh" "zsh_help")
export ZSHHELPDIR=~/ZSHHELP
function run-help() {
[[ $1 = . ]] && 1=dot
[[ $1 = : ]] && 1=colon
if [[ $1 = compctl ]]; then
man zshcompctl
elif [[ -f $ZSHHELPDIR/$1 ]]; then
less $ZSHHELPDIR/$1
else
man $1 || w $1
fi
}
# «completion» (to ".completion")
# zsh3.0 has these as defaults, but for 3.1.6 I have to set them
# explicitly (and I learned how by comparing the defaults):
# (find-es "zsh" "compctl_defaults")
compctl -b bindkey
compctl -v export
compctl -o setopt
compctl -v unset
compctl -o unsetopt
compctl -v vared
compctl -c which
# compctl -c sudo
compctl -c man
## function comp_emails () { reply=($(<~/.addrs)) }
## compctl -K comp_emails email email850 emailfile
#####
#
# TeX and printing
#
#####
# «TeX» (to ".TeX")
#
alias checkfonts='dvips -o /dev/null'
alias checkfonts300='dvips -D 300 -o /dev/null'
alias wtex='kpsewhich -n tex tex'
alias wlatex='kpsewhich -n latex tex'
# «dvifonts» (to ".dvifonts")
# (find-angg ".emacs" "find-dvifonts")
function dvifonts-l () { dvitype -output-level=1 $1 | grep fntdef }
function dvifonts () { dvifonts-l $* | cut -d' ' -f 4- }
function dvieps-l () { dvitype -output-level=1 $1 | grep PSfile }
#function dvieps () { dvieps-l $1 | perl -nle 'm/"(.*)"/ && print "foo", $1'}
function dvieps () { dvieps-l $1 | perl -nle 'print m/"(.*)"/'}
function dvi+eps () { echo $1; dvieps $1 }
# (find-angg ".emacs" "date")
alias hoje='date +%Y%b%d | tr A-Z a-z'
#export HOJE=$(date +%Y%b%d)
#export HOJEDVITGZ=${HOJE}-dvi.tgz
#export HOJESRCTGZ=${HOJE}-src.tgz
# «savetmptex» (to ".savetmptex")
# (find-es "tex" "edrxnotes")
function savetmptex () {
i=$(perl -nle 'm/^\\edrxnotes{([!-~]+)}/ && print $1' < tmp.tex)
if [[ -n $i ]]; then
echo $i.tex
sed -e "s/^\\\\input tmp.dnt/\\\\input $i.auto.dnt/" < tmp.tex > $i.tex
fi
}
# «printing» (to ".printing")
# (find-node "(zsh)Filename Generation" "<[X]-[Y]>")
# (find-angg "LATEX/Makefile" ".p01")
# Examples:
# backprint /tmp/tmp.p??
# fwdprint /tmp/tmp.p<14-17>
#
# «gsdj» (to ".gsdj")
# (find-angg ".emacs" "find-cat-to-lp0-script")
# (find-angg "bin/lpdj-tmp")
alias gsdj='gs -sDEVICE=djet500 -r300 -dNOPAUSE -dBATCH'
alias gscdj='gs -sDEVICE=cdj550 -r300 -dNOPAUSE -dBATCH'
function gsdj-tmp () { rm -v /tmp/o.p<1->; gsdj -sOutputFile=/tmp/o.p%03d $* }
function gscdj-tmp () { rm -v /tmp/o.p<1->; gscdj -sOutputFile=/tmp/o.p%03d $*}
# gsdj -sOutputFile=foo.p%02d foo.ps
function backprint () {
for i in $(print -l $* | tac); do echo $i; cat $i > /dev/lp1; done
}
function fwdprint () {
for i in $*; do echo $i; cat $i > /dev/lp1; done
}
function oddprint () {
backprint $(print -l $* | grep '[13579]$')
}
function evenprint () {
fwdprint $(print -l $* | grep '[02468]$')
}
#function lmake () {cd ~/LATEX; rm $1.dvi; make $1.dvi }
#function lmakep () {cd ~/LATEX; rm $1.dvi;rm $1.p<0-999>; make $1.dvi $1.p01 }
#function lmakeP () {cd ~/LATEX; rm $1.dvi;rm $1.p<0-999>; make $1.dvi $1.p001}
#function moveps () { pstops $(~/TCL/pstopsargs $*) }
# (find-fline "~/TCL/pstopsargs")
#
# «ps2pdj» (to ".ps2pdj")
# (find-angg "LATEX/Makefile" ".p01")
# (find-angg "bin/gs-640c-bw")
function ps2pdj () {
pstops -q '1:0(0,-1in)' $1 \
| ~/bin/gs-640c-bw -dNOPAUSE -dBATCH -sOutputFile=/tmp/o.pdj -
}
# «a2ps» (to ".a2ps")
# (find-node "(a2ps)Pretty Print Options" "-E")
# (find-node "(a2ps)Sheet Options")
# (find-node "(a2ps)Some Encodings")
# (find-fline "~/.a2ps/a2psrc")
function a2ps850dj () {
if [[ $1 = -o ]] then
a2ps -o $2 -X ibmpc \
--columns=2 --rows=1 --major=columns --portrait --medium=A4dj $*[3,-1]
else echo "Usage: $0 -o xxx.ps [options] xxx.txt"
echo " usually: -o <psfile> $0 -Eplain <txtfile>"
fi
}
# «pstotext» (to ".pstotext")
function mypstotext () {
pstotext $* | perl -nle 's/¡/-/g; print'
}
# «ps2up-letter» (to ".ps2up-letter")
# (eev "cd $usr_src/psutils-1.17.orig/; man2t psnup.1 | l")
alias ps2up-letter='psnup -2 -p letter'
alias ps2up-letter-laser6='psnup -2 -p letter | lpr -P laser6'
# «psmyflip» (to ".psmyflip")
# (find-node "(dvips)Config file paper sizes" "A4size 210mm 297mm")
# (find-fline "~/LATEX/tmp.ps" "BoundingBox:")
# (* (/ 596 72.0) 25.4)
# (* (/ 842 72.0) 25.4)
alias psmyflip="pstops '2:0,1U(596pt,842pt)'"
# «zxdvi» (to ".zxdvi")
# (find-es "tex" "xdvi-gz")
# (find-fline "/usr/bin/X11/xdvi" "*.gz")
# (find-man "1 tempfile")
# (find-node "(zsh)Shell Builtin Commands" "\ntrap")
# (find-node "(bash)Bourne Shell Builtins" "`trap'")
function zxdvi () {(
dviname=$(basename $(basename $1 .gz) .Z)
tempdir=$(tempfile -p zxdvi)
rm $tempdir
mkdir $tempdir
zcat $1 > $tempdir/$dviname
xdvi $tempdir/$dviname $*[2,-1]
# rm -Rv $tempdir
rm -R $tempdir
)}
# «rexdvi» (to ".rexdvi")
# (find-zshnode "Shell Builtin Commands" "return [ N ]")
# (find-zshnode "Complex Commands")
# (find-es "tex" "xdvi-pid")
# Note that our detection of a running xdvi is very simple-minded.
# (find-fline "/usr/bin/xdvi")
function ispidfile () { [[ -e $1 && -d /proc/$(<$1)/ ]] }
function rexdvi () {(
PIDFILE=/tmp/xdvi-$(basename $1)-pid
if ispidfile $PIDFILE; then
kill -USR1 $(< $PIDFILE)
else
# xdvi $*[2,-1] $1 &
xdvi.bin -name xdvi $*[2,-1] $1 &
echo $! > $PIDFILE
fi
)}
# «regv» (to ".regv")
# (find-man "1 gv" "-watch")
# (find-man "1 kill" "HUP ")
# (find-angg "bin/regv")
function regv () {(
PIDFILE=/tmp/gv-$(basename $1)-pid
if [[ -e $PIDFILE && -e /proc/$(< $PIDFILE) ]]; then
kill -HUP $(< $PIDFILE)
else
gv $*[2,-1] $1 &
echo $! > $PIDFILE
fi
)}
# «xydemo» (to ".xydemo")
function xydemo () {
( echo -E '\documentclass{book} \usepackage'$1'{xy} \begin{document}'
echo -E '$$ \begin{xy}'
cat
echo -E '\end{xy} $$ \end{document}'
) > /tmp/xydemo.tex
(cd /tmp/; latex xydemo.tex && rexdvi xydemo.dvi)
}
# «diagxydemo» (to ".diagxydemo")
# (find-es "xypic" "diagxydemo0")
function diagxydemo0 () {
( echo -E '\documentclass{book}'
echo -E '\input diagxy'
echo -E '\xyoption{curve}'
echo -E '\begin{document}'
# (find-diagxyfile "diagxy.tex" "\\def\\to{")
echo -E '\def\diagxyto{\ifnextchar/{\toop}{\toop/>/}}'
echo -E '\def\mon{\diagxyto/ >->/}'
echo -E '\def\epi{\diagxyto/->>/}'
echo -E '\def\toleft{\diagxyto/<-/}'
echo -E '\def\monleft{\diagxyto/<-< /}'
echo -E '\def\epileft{\diagxyto/<<-/}'
echo -E '\def\to{\rightarrow}'
echo -E $1
cat
echo -E '\end{document}'
) > ~/LATEX/diagxydemo.tex
(cd ~/LATEX/; latex diagxydemo.tex && rexdvi diagxydemo.dvi)
}
function find-diagxydemo () {
( echo -E '$\bfig'
cat
echo -E '\efig$'
) | diagxydemo0 $1
}
# «pstdemo» (to ".pstdemo")
function pstdemo () {
( echo -E '\documentclass{book}'
echo -E '\input pstricks'
echo -E '\input pst-node'
echo -E '\begin{document}'
cat
echo -E '\end{document}'
) > ~/LATEX/pstdemo.tex
( cd ~/LATEX/
latex pstdemo.tex && dvips -o pstdemo.ps pstdemo.dvi & regv pstdemo.ps
)
}
# «testfontcmds» (to ".testfontcmds")
# (find-es "tex" "testfontcmds")
# (eev "testfont bbold10")
function testfontcmds () {
echo -nE '\let\noinit! \input testfont.tex'
for i in $*; do
echo -nE '\def\fontname{'$i'}\startfont\table'
done
echo -E '\bye'
}
function testfont () {
cd /tmp/; tex "$(testfontcmds $*)" && rexdvi /tmp/testfont.dvi
}
# «tdiags» (to ".tdiags")
# Tcl code: (find-angg "LATEX/diaglib.014" "diagxy_hacks")
# Last saved tmp diag: (find-fline "~/LATEX/tmpdiag.tex")
# Emacs support: (find-angg ".emacs" "tdiags")
# Awk links: (find-eev "changer.awk")
# Preparing (1st time): (eev "cd ~/LATEX/; ln -sf ../o tmpdiag.tex")
# TeX wrapper for previewing: (find-fline "~/LATEX/testdiag.tex")
# For ". testdiag": (find-fline "~/LATEX/testdiag")
function testdiag () {
cd ~/LATEX/
awk -v fname=$(basename $1) '
$0 == "% tdiagheader=yes" {
printf("%% (find-fline \"%s\" %d)\n", fname, NR);
header = 1; next;
}
$0 == "% tdiagheader=no" {
header = 0;
}
/^% tdiagheader:/ {
printf(" %% (find-fline \"%s\" %d)\n", fname, NR);
sub(/^% tdiagheader:/, "");
print;
}
header { print }
' < $1 > testdiag.tex && latex testdiag.tex && rexdvi testdiag.dvi
}
# «mytoctoeevlinks» (to ".mytoctoeevlinks")
# (find-es "tex" "mytoc")
function mytoctoeevlinks () {
expect -c '
foreach line [split [read stdin] \n] {
set text ??; set colons ::
if [regexp {^(:+) (.*)} $line -> colons text] {
regsub -all {:} $colons { } colons
puts "%$colons«.$text»\t\t(to \"$text\")"
}
}
'
}
# «makebbl» (to ".makebbl")
# (find-es "tex" "makebbl")
function makebbl () {
echo -E '\documentclass{book}' > tmpbib.tex
echo -E '\usepackage[latin1]{inputenc}' >> tmpbib.tex
echo -E '\begin{document}' >> tmpbib.tex
echo -E '\nocite{*}' >> tmpbib.tex
for i in $*[2,-1]; do
echo -E '\bibliography{'$i'}' >> tmpbib.tex
done
echo -E '\bibliographystyle{alpha}' >> tmpbib.tex
echo -E '\end{document}' >> tmpbib.tex
latex tmpbib.tex
bibtex tmpbib
cp -v tmpbib.bbl $1
}
#####
#
# Icon
#
#####
# «Icon» (to ".Icon")
# (find-es "icon" "icone")
# (find-angg "ICON/")
# (find-angg "ICON/zinc.icn")
# (find-angg "ICON/zlib.icn")
# (find-man "1 icont")
# (find-sh "rm -fv ~/ICON/zlib.u{1,2}; cd ~/ICON/ && icont -c zlib.icn")
# (find-fline "~/ICON/")
# (find-status "icon-ipl")
# (find-vldifile "icon-ipl.list")
# (find-udfile "icon-ipl/")
#
export LPATH="$HOME/ICON /usr/lib/icon/ipl/incl /usr/lib/icon/ipl/gincl"
#export IPATH="$HOME/ICON /usr/lib/icon/ipl/ucode"
export IPATH="$HOME/ICON /usr/lib/icon-ipl"
#
function icone () {
print -l '$include "zinc.icn"' $1 'procedure main(args)' $2 'end' \
> ~/tmp/tmp.icn
icont -s -o ~/tmp/tmpicn ~/tmp/tmp.icn -x $*[3,-1]
}
function iconw () {
icone '' "w($1)" $*[2,-1]
}
# Examples:
# icone '' 'w(1+2)'
# icone '' 'every write(function())'
# icone '' 'w(args)' foo bar
# echo "foo\n bar" | icone '' 'w(read()); w(read())'
#
# iconw 'args[2:4]' a b c d e
#####
#
# Things related to rc.d and chroot
#
#####
# «stop-restart-services» (to ".stop-restart-services")
# (find-es "potato" "stop-restart-services")
function stop-services () {
for i in $(print -l /etc/rc2.d/* | tac); do
echo $i; $i stop
done
}
function restart-services () {
for i in /etc/rc2.d/*; do
echo $i; $i start
done
}
# To do: a function that changes (in a safe way) the /etc/inittab and
# then issues a "telinit q".
# (find-man "8 telinit" "Q or q tell init to re-examine the /etc/inittab file")
# «restart_inetd» (to ".restart_inetd")
# Restart the inetd daemon VERY carefully
# (for when we're paranoid)
function restart_inetd () {
ps ax | grep inetd | grep -v grep
/etc/init.d/inetd stop
ps ax | grep inetd | grep -v grep
/etc/init.d/inetd start
ps ax | grep inetd | grep -v grep
cat /var/run/inetd.pid
}
# «gpm» (to ".gpm")
# (find-es "mouse" "gpm")
alias killgpm='kill $(cat /var/run/gpmpid)'
alias regpm='(DISPLAY=; /etc/init.d/gpm restart)'
# «unsetall» (to ".unsetall")
# (find-es "zsh" "unsetall")
function unsetall () {( _unsetall; $* )}
function _unsetall () {
unset $(env | sed 's/=.*$//' \
| egrep -v '^(EE|HOME|PATH|PS.*|PWD|SHELL|TERM|_)$')
}
# «chroot-redhat-zsh» (to ".chroot-redhat-zsh")
# (find-es "redhat" "chroot_to_redhat")
function chroot-redhat-zsh () {
sh -c '
unset $(env | sed "s/=.*\$//" | egrep -v "^(PWD|TERM|HOME|_)\$")
export _CHROOTSTR=.rh
export HOME=/home/root
export SHELL=/bin/zsh
exec /usr/sbin/chroot /redhat /bin/zsh
'
}
#####
#
# loop device
#
#####
# «loop_device» (to ".loop_device")
# (find-zshnode "Shell Builtin Commands" "getopt")
# (find-k22file "Documentation/Configure.help" "Loop device support")
# insmod /boot/angg/loop.o
# There's now a simpler way using "-o loop"...
#
function umountloop0 () {
umount /dev/loop0
losetup -d /dev/loop0
}
function mountloop0L () {
umount /dev/loop0
losetup -d /dev/loop0
losetup /dev/loop0 $1
shift
mount /dev/loop0 /L $*
}
function mountloop1L () {
umount /dev/loop1
losetup -d /dev/loop1
losetup /dev/loop1 $1
shift
mount /dev/loop1 /L1 $*
}
#####
#
# filters
#
#####
# «filters» (to ".filters")
function mycat () {
for i in $*
do echo "\n\n\n------> $i\n"
cat $i
done
}
function mycatp () {
echo "\n\n\n--> $*\n"
$*
}
function getlinks () {
perl -ne 'while ( m/"((ftp|http):\/\/.*?)"/gc ) { print $1, "\n"; }'
}
function gethrefs () {
perl -ne 'while ( m/href="([^"]*)"/gc ) { print $1, "\n"; }'
}
function getanames () {
perl -ne 'while ( m/a name="([^"]*)"/gc ) { print $1, "\n"; }'
}
function getforms () {
perl -ne 'while ( m:(\</?(input|form|select|option).*?\>):gic )
{ print $1, "\n"; }'
}
function getstrings () {
perl -ne 'while ( m/"(.*?)"/gc ) { print $1, "\n"; }'
}
function getanchors () {
perl -ne 'while ( m/«([^«»\n]+)»/gc ) { print $1, "\n"; }'
}
# «man2t» (to ".man2t")
alias man2t='groff -Tascii -man'
# (find-es "expect" "body_of_manpage")
function man2t2 () { man2t $* | m2t2 }
function m2t2 () {
expect -c 'for {set n 0} {![eof stdin]} {incr n} {
gets stdin li; set pn [expr $n%66]
if {!($pn<=5 || $pn >= 60)} {puts $li}
}'
}
function pod2t () {
pod2man $* | groff -Tascii -man
}
function nolinks () {
grep -v ' -> '
}
function crlf () {
perl -nle 's/\r//; print "$_\r";'
}
function crlfff () {
crlf; echo -ne '\f'
}
# «filter» (to ".filter")
# (find-es "perl" "filter")
function filter () { WHICH=$1 \
perl -nle '
if (m/;;-> (.*)/) {
$doprint = 0;
for $p (split(/ /, $1)) {
for $w (split(/,/, $ENV{"WHICH"})) {
if ($p eq $w) { $doprint = 1 }
}
}
} else {
if ($doprint) { print; }
}
'
}
# «zcatinfo» (to ".zcatinfo")
# (find-es "zsh" "zcatinfo")
function zcatinfo () {
echo " # Expect exactly one 'No such file or directory' error." >/dev/stderr
(setopt NULL_GLOB; zcat $1{,.info}{,-?,-??}.gz)
}
# «find-ess» (to ".find-ess")
function find-ess () {(
STEM=$(basename $1 .e)
perl -nle 'm/«(.*)»/ && print "# (find-es \"'$STEM'\" \"$1\")"' < $1
)}
#####
#
# splitting files in small chunks
#
#####
# «spl» (to ".spl")
# Example:
# spl $SDEBIAN/ls-lR 2000 00 01 02
# produces ls-lR00.gz, ls-lR01.gz and ls-lR02.gz in the current diretory.
# If these are all the pieces, then by ungzipping and then cating them we
# get back the original file.
#
function spl () {
FILE=$1
BLOCKS=$2
shift 2
for PARTN in $*; do
dd if=$FILE skip=$[$BLOCKS * $PARTN] count=$BLOCKS \
| gzip -c9 > $(basename $FILE)$PARTN.gz
done
}
function splzip () {
FILE=$1
BLOCKS=$2
shift 2
for PARTN in $*; do
dd if=$FILE skip=$[$BLOCKS * $PARTN] count=$BLOCKS > $PARTN
zip $PARTN.zip $PARTN
done
echo "copy /b ${(j:+:)*} $(basename $FILE)\r" > gruda.bat
}
# «split_transfer» (to ".split_transfer")
alias packS='cd $S; cp ~/.psne.log .; tar -cvzf ~/public_html/S.tgz .* *; laf ~/public_html/S.tgz'
alias getS='cd /tmp; wget $HBOTO/S.tgz'
alias getS='cd /tmp; wget $FBOTOPH/S.tgz'
alias unpackS='cd $S; tar -xvzf /tmp/S.tgz'
function splitS () { cd ~/public_html/; spl S.tgz $* }
function getSparts () {
cd /tmp
for i in $*; do
/usr/bin/wget -c $FBOTOPH/S.tgz$i.gz
done
}
# splitS 1000 00 01 02 03 04 05
# getSparts 00 01 02 03 04 05
#
# ou com: export FBOTOPH=http://www.mat.puc-rio.br/~edrx
#####
#
# mail
#
#####
# «email»
function mailas () { su -s /usr/bin/mail $1 -- $*[2,-1] }
function email () { su -s /usr/bin/mail edrx -- $* }
# (find-es "slink" "mime_lite")
# (find-es "perl" "mimelite_zsh2")
# Note that I'm using "su -s /usr/sbin/sendmail edrx --" instead of
# simply "/usr/sbin/sendmail"; you may want to change that. Also, I'm
# using "usr lib "$ENV{HOME}/PERL/" to allow Lite.pm to be in
# ~/PERL/MIME/Lite.pm.
function email_mimelite () {
perl -e 'use lib "$ENV{HOME}/PERL/"; use MIME::Lite;
'$1'
if (open SENDMAIL, "|su -s /usr/sbin/sendmail edrx -- -t -oi -oem") {
$msg->print(\*SENDMAIL); close SENDMAIL;
} else { print "Erro interno no sendmail: !=$!, ?=$?.\n";
}'
}
function email850 () {
850toiso | TO=$1 SUBJ=$2 email_mimelite '
undef $/;
$msg = new MIME::Lite
To => $ENV{"TO"},
Subject => $ENV{"SUBJ"},
Encoding => "quoted-printable",
Data => <>;'
}
# «emailfile»
function emailfile () {
TO=$1 FILE=$2 email_mimelite '
$msg = new MIME::Lite
To => $ENV{"TO"},
Subject => $ENV{"FILE"},
Data => "";
attach $msg
Encoding => "base64",
Type => "BINARY",
Path => $ENV{"FILE"},
Filename => $ENV{"FILE"};'
}
alias email850pmv='email850 pmveloso@bridge.com.br'
# (find-fline "~/bin/sendemail")
# My "sendemail" script broke after a partial upgrade to woody, but it
# seems that this works:
alias sendemail='sudo -u edrx mail'
# «perlsendfile» (to ".perlsendfile")
# (find-es "mail" "libmime-perl")
# (eev "TO=beth FILETYPE=image/png FILE=~/DANIEL/daniel.png perlsendfile")
#
function perlsendfile () {
perl -- =(<<'%%%'
use MIME::Entity;
$top = MIME::Entity->build(
To => $ENV{TO},
Subject => $ENV{SUBJECT},
Type => "multipart/mixed",
#From => $ENV{FROM},
#'Return-Path:' => $ENV{FROM},
);
$top->attach(
Path => $ENV{FILE},
Type => $ENV{FILETYPE},
Encoding => "base64",
);
open MAIL, "| /usr/lib/sendmail $ENV{TO}" or die "open: $!";
$top->print(\*MAIL);
close MAIL;
%%%
)
}
#####
#
# modem and ppp
#
#####
# «modem_interact» (to ".modem_interact")
# (find-es "modem" "modem_interact")
# modem_interact /dev/ttyS2 5 echo
# modem_interact '' '' echo
function modem_interact () {
$3 expect -c '
spawn -noecho -open [open '${1:-/dev/modem}' r+]
stty speed 115200 < '${1:-/dev/modem}'
stty -icanon
interact ~ return timeout '${2:--1}' return
'
}
# «expect_isp» (to ".expect_isp")
# «inx-up» (to ".inx-up")
# (find-es "modem" "ppp-inx-feb2003")
function inx-up () {
expect -c '
spawn minicom
interact "~r" {send atx3l0\r} "~d00" {send atdt//15000450\r} \
"~\r" {send \001q\r}
'
rm /etc/resolv.conf
/usr/sbin/pppd -detach usepeerdns defaultroute /dev/modem 115200 \
name edrx@inx.com.br remotename inx &
}
# «ppp-up» (to ".ppp-up")
# (find-es "modem" "expect_isp_2")
# This pair of functions (ppp-up/ppp-up_) supersedes both inx-upe and
# ig-up, below; if you just want to understand in rough terms how this
# works then it's better to check ig-up: (to "ig-up")
function inx-up_ () {
/usr/sbin/pppd -detach usepeerdns defaultroute /dev/modem 115200 &
}
function ig-up_ () {
# /usr/sbin/pppd user ig remotename ig \
/usr/sbin/pppd user palmeida32 remotename 22440031 \
-detach usepeerdns defaultroute /dev/modem 115200 &
}
function ppp-up () {
ppp-up_
case $(</tmp/ppp-up-status) in
inx) rm /etc/resolv.conf; inx-up_ ;;
ig) rm /etc/resolv.conf; ig-up_ ;;
*) echo Not trying to run pppd.
esac
}
function ppp-up_ () {
expect -c '
source $env(HOME)/.passwds.tcl
# Create a proc for each telephone number
foreach n {00 01 02 03 04 05 06 08 09 10 11 12 13 14 15 16} \
phone {34619400 25126880 25126881 25126882 25126883 25126884 25126889
25126890 25126891 25126892 25126896 25126897 25126898 25126899
25126904 25126905 25126906} {
proc d$n {} " global USER PWD passwd ISP
set USER edrx; set PWD $passwd(inx); set ISP inx;
send atdt//$phone\\r
"
}
proc ig {} { global USER PWD ISP
set USER ig; set PWD ig; set ISP ig; send atdt//15002000\r
}
set ok 0; spawn minicom; stty raw
interact {
~d00 d00 ~d01 d01 ~d02 d02 ~d03 d03 ~d04 d04 ~d05 d05 ~d06 d06
~d07 d07 ~d08 d08 ~d09 d09 ~d10 d10 ~d11 d11 ~d12 d12 ~d13 d13
~d14 d14 ~d15 d15 ~d16 d16 ~i ig
~r {send atx3l0\r}
~u {send $USER\r}
~p {send $PWD\r}
"~\r" {send \001q\r}
-o rname: {send $USER\r}
ogin: {send $USER\r}
ssword: {send $PWD\r; set ok $ISP}
eof return
}
exec echo $ok > /tmp/ppp-up-status
puts "minicom done"
'
}
# «inx-upe» (to ".inx-upe")
# (find-es "modem" "expect_isp")
# Obsolete.
function inx-upe () {
echo "search ." > /etc/resolv.conf
echo "nameserver 200.240.18.1" >> /etc/resolv.conf
echo "nameserver 200.240.18.5" >> /etc/resolv.conf
expect -c '
source $env(HOME)/.passwds.tcl
set phones {34619400 25126880 25126881 25126882 25126883 25126884 25126889
25126890 25126891 25126892 25126896 25126897 25126898 25126899 25126904
25126905 25126906}
spawn minicom; stty raw
interact {
-re {~d([0-1][0-9])} {
scan $interact_out(1,string) %d index
send atdt//[lindex $phones $index]\r
}
"~\r" {send \001q\r}
"~t" {send ats6?s7?s8?s9?s10?s12?s18?s25?\r}
-o
-re (ogin|rname): {send edrx\r}
ssword: {send $passwd(inx)\r}
eof {return}
}
puts "inx-upe: minicom done"
'
#/usr/sbin/pppd -d -detach defaultroute /dev/modem 115200 &
rm /etc/resolv.conf
/usr/sbin/pppd -detach usepeerdns defaultroute /dev/modem 115200 &
}
# «ig-up» (to ".ig-up")
# This used to work for connecting with IG, a free ISP in Rio de Janeiro.
# It should be very easy to adapt for other ISPs and other modems.
function ig-up () {
expect -c '
spawn minicom
interact {
"~r" {send atx3\r}
"~d00" {send atdt//15002000\r}
"~\r" {send \001q\r}
}
puts "ig-up: minicom done"
'
rm /etc/resolv.conf
/usr/sbin/pppd user ig remotename ig \
debug -detach usepeerdns defaultroute /dev/ttyS2 115200 &
}
function ppp-down () {
echo cat /var/run/ppp0.pid
cat /var/run/ppp0.pid && \
kill $(cat /var/run/ppp0.pid)
rm -v /var/lock/LCK..modem
}
function untilwvdial () { until wvdial $*; do; done }
#####
#
# my page
#
#####
# «makeL» (to ".makeL")
# (find-angg "TH/Makefile")
#export TH=~/TH
alias makeL='mkdir ~/TH/L/; cd ~/TH/L/ &&
DOLOCAL=1 make -f ~/TH/Makefile COPYING=1'
alias makeR='mkdir ~/TH/R/; cd ~/TH/R/ &&
make -f ~/TH/Makefile COPYING=1'
alias makeL-anew='rm -Rv ~/TH/L; makeL'
alias makeR-anew='rm -Rv ~/TH/R; makeR'
alias makeLedrxtgz='makeL page edrx.tgz'
alias makeRedrxtgz='makeR page edrx.tgz'
alias makeLhomeedrxtgz='makeL page ~/edrx.tgz'
# makeP is almost the same as makeR, but uses ~/public_html/
#
alias makeP='mkdir -p ~/public_html/; cd ~/public_html/ &&
make -f ~/TH/Makefile COPYING=1'
alias makeP-anew='rm -Rv ~/public_html; makeP'
alias makePedrxtgz='makeP page edrx.tgz'
# Make a "remote" version:
# «makepage» (to ".makepage")
# Full version,
function makepage () {
# rm -fRv ~/public_html/
rm -Rf ~/public_html/
mkdir ~/public_html/
cd ~/public_html/
tar -xvzf ~/edrx.tgz
# touch $(find .* * -type f)
#
make -f TH/Makefile page edrx.tgz |& tee ~/om
}
function cp_slow_html_to_public () {
# twu's cp loops here, I don't know why... trying with a "head"
# (cd ~/slow_html/; cp -dPpvRl * ~/public_html/) |& head -n 2000
echo "cd ~/slow_html/ && cp -dPpvRl * ~/public_html/ | wc"
cd ~/slow_html/ && cp -dPpvRl * ~/public_html/ | wc
}
# «makepagefromtar» (to ".makepagefromtar")
# (find-es "page" "upload-rsync")
function makepagefromtar () {
cd
gzip -c9 < ~/edrx.tar > ~/edrx.tgz
laf edrx.tar edrx.tgz
makepage
cp_slow_html_to_public
}
function makepageindexhtmls () {
for i in $(cd ~/public_html && find .* * -type d); do
cd ~/public_html/$i && LC_COLLATE=C lstoindexhtml_lua_maybe $i .favicon.png
done
}
# «makeindexhtmls» (to ".makeindexhtmls")
# For mat.puc-rio.br.
# (find-angg "TCL/lstoindexhtml")
function makeindexhtmls () {
for i in $(find ~/public_html -type d | sort); do
if [[ ! -e $i/index.html ]]; then
cd $i; pwd; tclsh ~/TCL/lstoindexhtml > index.html
fi
done
}
# function lstoindexhtml_lua () {
# ls -laF | col -x | lua50 ~/LUA/lstoindexhtml.lua
# }
# (find-angg "LUA/lstoindexhtml.lua")
# (find-blogme3 "lstoindexhtml.lua")
# «lstoindexhtml_lua_maybe» (to ".lstoindexhtml_lua_maybe")
function lstoindexhtml_lua_maybe () {
if [[ -e index.html ]]; then
head -n 5 index.html \
| egrep -q 'Generated by' \
&& rm index.html
# && echo "Deleting: $1"
fi
if [[ ! -e index.html ]]; then
echo "Creating: $1"
ls -laF | col -x \
| lua51 ~/LUA/lstoindexhtml.lua $1 $(test -e "$2" && echo $2)\
| lua51 -e 'writefile("index.html", io.read("*a"))'
fi
}
function lstoindexhtml_lua_dirs () {
for i in $*; do
(cd $i && LC_COLLATE=C lstoindexhtml_lua_maybe $i .favicon.png)
done
}
# (eev "cd ~/TH/L/; lstoindexhtml_lua_dirs . $(find .* * -type d)")
# «bigmakepage» (to ".bigmakepage")
# Download edrx.tgz from twu and then do a makepage.
# For mat.puc-rio.br.
alias bigmakepage='cd && wget http://angg.twu.net/edrx.tgz &&
mv -fv edrx.tgz.1 edrx.tgz && makepage'
# «unglyph»
# The first parameter is the name of the temp file to use.
function unglyph () {
if [[ -e $1 ]]; then echo "Can't use $1 as temp file!"; return 1; else
for i in $*[2,-1]; do
echo unglyphing $i
sed -e 's/*/-/' -e 's/«/<</' -e 's/»/>>/' < $i > $1
touch -r $i $1
mv $1 $i
done; fi
}
# rm -Rv /tmp/e; mkdir /tmp/e; cp -av $ES/*.e /tmp/e; cd /tmp/e; unglyph _ *.e
# «uploadtoanggtmp» (to ".uploadtoanggtmp")
function uploadtoanggtmp () {
anonftp angg.twu.net \
"put $1 public_html/tmp/$(basename $1)" \
quit
echo http://angg.twu.net/tmp/$(basename $1)
}
function uploadtoanggtmp+ () {
anonftp angg.twu.net \
"put $1 public_html/tmp/$(basename $1)" \
"put $1 slow_html/tmp/$(basename $1)" \
quit
echo http://angg.twu.net/tmp/$(basename $1)
}
function uploadtoanggtmp () {
Scp $1 edrx@angg.twu.net:public_html/tmp/$(basename $1)
echo http://angg.twu.net/tmp/$(basename $1)
}
function uploadtoanggtmp+ () {
Scp $1 edrx@angg.twu.net:public_html/tmp/$(basename $1)
Scp $1 edrx@angg.twu.net:slow_html/tmp/$(basename $1)
echo http://angg.twu.net/tmp/$(basename $1)
}
#####
#
# wikis
# 2000jun??
#
#####
# «wikis»
# (find-es "wiki" "wikit_cgi")
#
export WIKI=http://angg:8080/wiki
export RWIKIT=http://mini.net/cgi-bin/wikit
export TCLKIT=$(cd ~/bin/; pwd)/tclkit
[[ -e ~/WIKIS ]] && \
export WIKIDIR=$(cd ~/WIKIS/; pwd)
#
# A function to create the two cgis for a wiki in the current dir.
# Use like: cd /usr/lib/cgi-bin/; create_wiki_cgis metakit
#
function create_wiki_cgis () {
echo '#!/bin/sh' > $1
echo exec $TCLKIT $WIKIDIR/$1 wikit >> $1
chmod 755 $1
#
echo '#!/bin/sh' > $1.gz
echo 'echo Content-type: text/plain' >> $1.gz
echo 'echo' >> $1.gz
echo 'exec gzip -c6 <' $WIKIDIR/$1 >> $1.gz
chmod 755 $1.gz
}
# For wiki hacking:
# «ewiki_do»
alias ewiki_do='tclkit ~/WIKIS/ewiki do'
# «ewiki_dof»
function ewiki_dof () {
ewiki_do "package require format; namespace import WiKit::Format::*; $1"
}
# «ewiki_s2h»
alias ewiki_s2h2='ewiki_dof "puts [StreamToHTML [TextToStream [exec cat]]]"'
function ewiki_s2h () {
ewiki_dof ' puts "<html>\n<body>
[lindex [StreamToHTML [TextToStream [exec cat]]] 0]
</body>\n</html>"'
}
#####
#
# cgis
#
#####
# For basic cgi tests:
# «runtmpcgi»
#
# (find-es "http" "runtmpcgi")
export EECGIFILE=/usr/lib/cgi-bin/tmp.cgi
export EECGIURL=http://127.0.0.1/cgi-bin/tmp.cgi
function tmpcgi () {
wget -q -O - $EECGIURL$1 $*[2,-1]
}
function runtmpcgi () {
cat > $EECGIFILE
chmod 755 $EECGIFILE
tmpcgi $*
}
function runperltcgi () {
{ echo '#!/usr/bin/perl'
echo -E 'print "Content-type: text/plain\n\n";'
cat } | runtmpcgi $*
}
function runbashcgi () {
{ echo '#!/bin/bash'
echo -E 'echo -e "Content-type: text/plain\n"'
cat } | runtmpcgi $*
}
function runluacgi () {
{ echo "#!$(which lua50)"
echo -E 'print("Content-type: text/plain\n")'
cat } | runtmpcgi $*
}
# For heavier stuff:
function settmpcgi () {
cat > $EECGIFILE <<'---'
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
use Data::Dumper; sub pdump{print"\n $_[0] =\n",Dumper($_[1]);}
use CGI; my $query = new CGI;
---
cat >> $EECGIFILE
chmod 755 $EECGIFILE
}
# Other way of testing:
# /usr/lib/cgi-bin/tmp.cgi foo=bar
# «perl_http_request»
# (find-es "http" "file_upload")
# Even heavier stuff, but now on the client side...
# I use this to test for example file uploading via http.
function perl_http_request () {
echo 'use LWP::UserAgent; use HTTP::Request::Common;
print LWP::UserAgent -> new
-> request(' > /tmp/p
cat >> /tmp/p
echo ') -> content();' >> /tmp/p
perl /tmp/p
}
#####
#
# sound
#
#####
# function mp () {
# if [[ $# == 0 ]]; then cd /mp3s/MINE/; \ls -x
# else nice -n -40 /hdc6/usr/bin/freeamp $*
# fi
# }
# function vol () {
# if [[ $# == 0 ]]; then aumix -v query
# else aumix -v $*
# fi
# }
#########
## ##
## etc ##
## ##
#########
# «plip»
# Isso é pro angg. Pro tosh, veja (find-esfile "mini.e" "/L/sbin/plip+nfs")
function plip-up () {
insmod /boot/angg/plip.o
ifconfig plip1 10.0.1.1 up pointopoint 10.0.1.2
ifconfig
route add 10.0.1.2 dev plip1
}
function plip-down () {
ifconfig plip1 down
rmmod plip
}
function google () {
lynx 'http://www.google.com/search?q='${(j:+:)*}
}
function rhugs () {
cat > ${TMPHUGSFILE:-/tmp/h}
runhugs ${TMPHUGSFILE:-/tmp/h}
}
# «heredoc»
# (find-es "zsh" "heredoc")
function heredoc () {
cat > $1
OPTIND=0
while getopts o:m: opt $*[2,-1]; do
case $opt in
o) chown -v $OPTARG $1 ;;
m) chmod -v $OPTARG $1 ;;
esac
done
}
function write+chmod () { cat > $1; chmod -v $2 $1 }
# «.zshrc.local»
# Load specific local stuff.
# (find-fline "~/.zshrc.local")
# (find-fline "~/.zshrc.private")
# (find-fline "~/.zshrc.root")
if [[ -e ~/.zshrc.local ]]; then . ~/.zshrc.local; fi
if [[ -e ~/.zshrc.private ]]; then . ~/.zshrc.private; fi
if [[ $UID == 0 ]]; then . ~/.zshrc.root; fi
#
# X11
#
# «X» (to ".X")
# I set DISPLAY because I often want to invoke X programs from VTs:
[[ -n $DISPLAY ]] || export DISPLAY=:0.0
alias xmulti='xmodmap -e "keysym Alt_R = Alt_R Multi_key"'
alias xwname="xwininfo | grep 'Window id:'"
alias edrxnetscape='su -s /usr/bin/X11/netscape edrx'
alias edrxxchat='su -s /usr/bin/xchat edrx'
function killnetscape () {
kill -9 $(ps ax | grep netscape | grep -v grep | awk '{print $1}')
rm -v ~edrx/.netscape/lock
}
# «xset_MATH» (to ".xset_MATH")
# (find-fline "~/.xinitrc")
# (find-angg "eev-extras.el" "xmath")
alias xset_MATH='xset fp default; xset fp+ ~/MTA/; xset fp rehash'
# «inix» (to ".inix")
function inix () {
iso
inslp
cd ~/LATEX/
startx -- -bpp 16 &
inscd
}
alias inix8='xinit -- :1.0 -bpp 8 &'
# «inix-lea» (to ".inix-lea")
function inix-lea () {
iso
inslp
cd ~/LEA/
# (find-es "x" "second-X-server")
# (find-angg ".xinitrc" "guest_users")
# (find-angg "LEA/XF86Config-800x600")
# (find-angg "LEA/.xinitrc")
# xinit ~/LEA/.xinitrc \
# DISPLAY=:1.0 \
# XINITRC=~/LEA/.xinitrc \
GUEST_USER=lea \
startx -- /usr/bin/X11/XF86_SVGA :1.0 \
-xf86config ~/LEA/XF86Config-800x600 vt14 -bpp 16 &
}
export FS=angg:7100
alias fsls='fslsfonts -server angg:7100'
alias getbdf='fstobdf -s angg:7100 -fn'
# «icq»
function icq () {
echo Edrx: 32055141
echo Bruno: 70121435
echo use gnomeicu ou licq. Bruno: use icqbruno
}
alias icqbruno='su - bruno -- gnomeicu -q 70121435'
alias tuba=/usr/src/tuba-2.5.b1/tuba
alias tubak='tuba -i wish'
alias offer-kibitz='~/EXPECT/mykibitz -noescape -silent root'
alias accept-kibitz='~/EXPECT/mykibitz -noescape -silent -$(</tmp/mykibitz.pid)'
alias tkibitz='tuba -i expect ~/EXPECT/mykibitz'
function ftpboto () {
~/EXPECT/anonftp $BOTO $*
}
function ftpmyftp () {
~/EXPECT/anonftp $MATINTA 'cd /export/home/ftp/pub/users/edrx' $*
}
function ftpmyhttp () {
~/EXPECT/anonftp $BOTO 'cd public_html' $*
}
# «mame»
alias scramble='smame scramble -videomode 2 -frameskip 0 -nomouse'
alias robotron='smame robotron -videomode 2 -frameskip 0 -nomouse'
alias smame2='cd /usr/lib/games/xmame/roms/; smame -videomode 2 -frameskip 0 -nomouse'
alias smame2s='smame2 -sound'
MAMEROMS=/usr/lib/games/xmame/roms
function mamegames () {(cd $MAMEROMS; print -l *.zip | sed s/.zip//)}
#export MTOOLS_SKIP_CHECK=1
export MINICOM="-c on"
export MAPLE=/usr/local/maple
# «emacs-unibyte» (to ".emacs-unibyte")
# (find-e20node "Initial Options" "EMACS_UNIBYTE")
# (find-enode "Initial Options" "EMACS_UNIBYTE")
#export EMACS_UNIBYTE=yes
function mbemacs () {( unset EMACS_UNIBYTE; emacs $* )}
alias 00crim20='emacs20 -nw -unibyte ~/CRIM/016ideas'
alias 00crim21='emacs21 -nw -unibyte ~/CRIM/016ideas'
# «strace» (to ".strace")
# (find-es "anatocc" "libvforkwrap")
alias vfwstrace='LD_PRELOAD="/usr/src/libvforkwrap-0.1/libvforkwrap.so.0 $LD_PRELOAD" strace'
alias strace-to='strace -f -etrace=open,stat,fork,_exit,execve,wait4,chdir -o'
alias vfwstrace-to='vfwstrace -f -etrace=open,stat,fork,_exit,execve,wait4,chdir -o'
# «modules» (to ".modules")
#export boot_image=$(cat /proc/cmdline | sed 's/^.*BOOT_IMAGE=//; s/ .*//')
function modules () {
cat /proc/modules | perl -nle 'print m/^(.*?) /'
}
function modules () {
cat /proc/modules | awk '{print $1}'
}
function rmmodules () {
for i in $(modules); do echo $i; rmmod $i; done
}
# «cdrom» (to ".cdrom")
#function inscdx () {
# rm /dev/cdrom
# ln -s mcdx /dev/cdrom
# rmmod mcd
# insmod mcdx
#}
function inscd-ide () {
ln -sf hdb /dev/cdrom
insmod cdrom
insmod ide-cd
insmod isofs
}
function inscd () {
rmmod ide-cd
insmod cdrom
insmod scsi_mod
insmod ide-scsi
insmod sr_mod
insmod sg
insmod isofs
ln -sf scd0 /dev/cdrom
}
function rmcd () {
rmmod ide-cd
rmmod sg
rmmod sr_mod
rmmod ide-scsi
rmmod scsi_mod
rmmod cdrom
}
function inslp () {
insmod parport
insmod parport_pc io=0x3bc,0x378,0x278 irq=none,7,none
insmod lp parport=0,1,2
}
# (find-es "kernel" "scanner")
function insscanner () {
inslp
insmod scsi_mod
insmod sg
insmod ppscsi
insmod epst
}
alias fv='unzip -l'
alias ip2name='gethost -a -t addr'
alias name2ip='gethost -a -t name'
#export INX=200.240.18
#export MATINTA=139.82.27.1
#export SACI=139.82.27.51
#export SACI=$MATINTA
#export BOTO=139.82.27.42
#export MULA=139.82.27.44
#export TARDIS=139.82.27.31
#export NAUTILUS=200.224.100.240
#export NNTPSERVER=news.inx.com.br
#export FBOTO='ftp://edrx@'$SACI
#export FBOTO_H='ftp://edrx@'$SACI
#export FBOTO='ftp://boto.mat.puc-rio.br'
#export FBOTOPH='ftp://boto.mat.puc-rio.br/public_html'
#export AFBOTO="/edrx@$SACI:"
#export AFBOTO_H="/edrx@$SACI:/home/yara/edrx"
#export HBOTO='http://www.mat.puc-rio.br/~edrx'
#export AFUNIX1='/eduardoo@unix1:'
#export AFUNIX1_H='/eduardoo@unix1:/home/eduardoo'
alias mylpr='lpr -h -Psafo'
# (find-fline "$AFBOTO")
export PAGE=~/TCL/PAGE
export PAGE2=~/TCL/PAGE2
export USRC=/usr/src
export LH=http://localhost
#export HAA=/big/deb20/debian/main/binary-all
#export HAI=/big/deb20/debian/main/binary-i386
#export HAMM=/big/deb20/debian
#export SLINKB1=/big/slinkb1
#export SLINKB2=/big/slinkb2
export ELISP=/usr/share/emacs/19.34/lisp
export PL5=/usr/lib/perl5
# «vt» (to ".vt")
# (find-angg "vtutil/vtutil.lua" "vcsatounix")
# (find-angg "vtutil/vtutil.lua" "e_scripts" "vcsatounix")
function vt () {
cat /dev/vcs$1 | expect -c '
set vtstr [read stdin 20000]
for {set nline 0; set offset 0} {$nline<50} {incr nline; incr offset 80} {
puts [string trimright [string range $vtstr $offset [expr $offset+79]]]
}'
}
# «hurd»
#export FSIDMB=ftp://ftp.debian.org/debian/dists/sid/main/binary-hurd-i386
#export SSIDMB=$S/ftp/ftp.debian.org/debian/dists/sid/main/binary-hurd-i386
#export FALPHASIDMB=ftp://alpha.gnu.org/pub/gnu/hurd/debian/dists/unstable/main/binary-hurd-i386
#export SALPHASIDMB=$S/ftp/alpha.gnu.org/pub/gnu/hurd/debian/dists/unstable/main/binary-hurd-i386
#
function realpaths () { for i in $*; do realpath $i; done }
# function dpkgihurd () {(
# A=($(realpaths $*))
# cd /gnu/
# for i ($A) ./dpkg-hurd -i $i
# )}
# # Install with one call to dpkg-hurd:
# function dpkgihurd1 () {(
# A=($(realpaths $*))
# cd /gnu/
# ./dpkg-hurd -i $A
# )}
function dpkgihurd () {(
A=($(realpaths $*))
cd /gnu/
for i ($A) \
./dpkg-hurd --unpack $i --force-depends --force-overwrite
)}
# These are lua-4.0-isms, I think
# (find-es "lua" "loadtklua")
# (find-es "lua" "luasocket")
#alias mylua='lua ~/LUA/inc.lua'
#which dllua >& /dev/null && {
# alias mylua='dllua ~/LUA/inc.lua'
#}
#alias luae='mylua -e'
#alias mytklua='mylua -e "loadtklua()"'
#alias myluasock='mylua -e "loadluasocket()"'
# «lua» (to ".lua")
# (find-angg "LUA/lua50init.lua")
# (find-es "lua5" "install-5.1.2")
#
export LUA_INIT=@$HOME/LUA/lua50init.lua
# export LUASRC=$HOME/usrc/lua-5.0.2
export LUA50SRC=$HOME/usrc/lua-5.0.2
export LUA51SRC=$HOME/usrc/lua-5.1.2
# «swig» (to ".swig")
# (find-es "swig" "myswiglua")
# (find-es "swig" "swig-upstream")
# Usage: myswiglua C foo.so foo_wrap.so foo.c
export SWIGSRC=$HOME/usrc/swig-1.3.29
function myswiglua () {
rm -fv $2 $3
$SWIGSRC/preinst-swig -module $1 -lua $4 &&
gcc -L $LUA50SRC/lib -llua -llualib \
-isystem $LUA50SRC/include \
-g -shared -o $2 $3 $4
}
# (find-anggfile "vtutil4/Makefile")
# (find-vldifile "liblua50-dev.list")
if [[ "$LUAINC" == "" && -d /usr/include/lua50 ]]; then
export LUAINC=/usr/include/lua50
fi
export LFORTH=$HOME/LFORTH
# alias lua50=$HOME/tmp/lua-5.0-beta/bin/lua
# ln -sf ../tmp/lua-5.0-beta/bin/lua ~/bin/lua50
# (find-fline "~/bin/" " lua")
function lua50e () { lua50 -e $1 /dev/null $*[2,-1] }
function lua51e () { lua51 -e $1 /dev/null $*[2,-1] }
# lua50e 'P(arg[1])' foo bar
# «makelua50» (to ".makelua50")
# (find-es "lua5" "build-simple")
# «make» (to ".make")
# (find-es "make" "makefile_toposort")
# (find-es "make" "makefile_addtrace")
function makefile_toposort () { makefile_getdeps | lua ~/LUA/toposort.lua }
function makefile_getdeps () {
perl -e 'undef $/; $_ = <>; s/\\\n//g; print' \
| grep -v '^[ ]*#' \
| perl -nle 'if (m/^[^\t][^#:=]*:([^=]|$)/) { print }'
}
function makefile_addtrace () {
perl -e 'undef $/; $_ = <>; s/\\\n//g; print' | \
perl -nle '
print;
if (m/^[^\t][^#:=]*:([^=]|$)/) {
$n++; printf "\t# Dbg %d/%d \$\@: \$^\n", $n, $n+$.
};
'
}
# «remote-accounts» (to ".remote-accounts")
export SUCURI=sucuri.mat.puc-rio.br
#export DVALOIS=dvalois.no-ip.org
export ANGG=angg.twu.net
alias eegpasswd='eeg4 -c "source $HOME/.passwds.tcl"'
# echo 'l $passwd(puc)' > $EEG; eegpasswd scp 2002h.tex edrx@$SUCURI/LATEX/
# «scp» (to ".scp")
function scpsucuri () {
expect -c "
source $HOME/.passwds.tcl
spawn scp $*
interact -o -nobuffer {sword: } {send \$passwd(puc)\\\r}
"
}
# «save-input» (to ".save-input")
# (find-es "expect" "splitting_output_0")
function save-input () {
expect -c '
spawn -open [set out_file [open '$1' w]]
set out_spid $spawn_id
spawn '"$*[2,-1]"'
interact -output "$spawn_id $out_spid"
close $out_file
'
}
# (find-es "perl" "eval_in_regsub")
function expandctrls () {
perl -nle '
s/[\000-\037]/"^".chr(ord($&)+64)/eg; print
'
}
# «mydiff» (to ".mydiff")
# (find-node "(zsh)Alternate Forms For Complex Commands")
# (eev "cd /tmp/; echo '1\n2a\n3' > txt; echo '1\n2old\n3' > txt~; mydiff txt")
function mydiff () {
(echo patch -p0 $1 "<<'%%%'"
if [[ -e $1.orig ]] { diff $1.orig $1 } else { diff $1~ $1 }
echo %%%
) | tee ~/o
}
# «makeapacheindex» (to ".makeapacheindex")
# (find-es "page" "makeapacheindex")
# (eev "cd /tmp/; ls -laF | makeapacheindex | tee test.html")
function makeapacheindex () {
col -bx | perl -e '
printf "<!DOCTYPE html PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n";
printf "<html><head><title></title></head><body>\n";
printf "<!-- (find-angg \".zshrc\" \"makeapacheindex\")\n -->\n";
printf "<pre>\n";
while (<STDIN>) {
if (m/^(.{56})(.+?)([\*\=\@\|]| -> .*)?\n/) {
# printf "%s[%s]%s\n", $1, $2, $3
printf "%s<a href=\"%s\">%s</a>%s\n", $1, $2, $2, $3
} # else {
# printf "??: %s", $_
# }
}
printf "</pre></body></html>\n";
'
}
# «X1» (to ".X1")
# For running a second X server on panda, chrooting to Debian
function X1init () {
xinit -- $(w XFree86) :1.0 &
}
function X1mkauth () {
xauth -v generate :1.0 .
xauth -v nextract /tmp/auth :1.0
cat /tmp/auth
chmod 666 /tmp/auth
}
function X1auth () {
export DISPLAY=:1.0
xauth -v nmerge /tmp/auth
}
# «showperms» (to ".showperms")
# (find-man "1 chmod" "rwxXstugo")
# (find-man "2 chmod")
# (find-man "2 stat")
function showperms () {
echo chmod -v $1 --reference=$1
chmod -v $1 --reference=$1
}
alias desliga='shutdown -h now'
alias desligar='shutdown -h now'
# «emacs-cvs» (to ".emacs-cvs")
# (find-angg ".emacs" "emacs-cvs")
# (find-es "emacs" "emacs-from-cvs")
alias emacs-cvs="~/bigsrc/emacs/src/emacs"
# «dout» (to ".dout")
# (find-angg ".emacs" "dout")
# (find-angg "LATEX/dout/Makefile" "doutfont")
# (find-angg "LATEX/dout/doutfont.lua")
alias dout='cd ~/LATEX/dout/; make doutfont.8.setfont'
# «gunzip-nd» (to ".gunzip-nd")
function gunzip-nd () {(
F=$(basename $1 .gz)
if [[ -e $F ]]; then
echo "Not overwriting $F"
else
zcat $1 > $F
touch -r $1 $F
fi
)}
# «partitionids» (to ".partitionids")
function partitionids_ () {
for i in $*; do
printf "%-6s %s\n" $i "$(<$i/.id)"
done
}
PARTITIONS=(/ /hdd2 /hdd3 /hdd5 /hdd6 /hdd7 /hdb1 /hdb2)
alias partitionids='partitionids_ $PARTITIONS'
# «filedevice» (to ".filedevice")
# (find-node "(coreutils)stat invocation" "%d - Device number in decimal")
# (find-node "(zsh)Shell Builtin Commands" "printf FORMAT [ ARG ... ]")
# (find-node "(coreutils)Sorting the output")
# (find-zsh0 "filedevice $S/http/")
# (eev "filedevice ~; filedevice /; filedevice /hdb2")
#
function filedevice () {(
D=$(stat -c %d $1)
DHI=$[($D&-256)/256]
DLO=$[$D&255]
'ls' -lU /dev/* | grep ^b | awk '$5=="'$DHI,'"&&$6=="'$DLO'" {print}'
)}
# «ln-sf-safe» (to ".ln-sf-safe")
# (find-man "ln")
# (find-node "(zsh)Conditional Expressions")
# ln-sf-safe target (<-) source
# (find-es "float" "ln-sf-safe")
function ln-sf-safe () {
if [[ -h $2 ]]; then rm -v $2; fi
if [[ ! -a $2 ]]; then
ln -s $1 $2
else
echo "Not a symlink: $2"; false
fi
}
# (find-fline "/usr/share/doc/zsh/ChangeLog-3.1.gz" "whence/where/which -w")
if [[ $ZSH_VERSION > 3.1.5 ]]; then
function whence-type () { whence -w $1 | cut '-d ' -f 2 }
function unfunction-safe () {
if [[ $(whence-type $1) == function ]]; then
unfunction $1
fi
}
unfunction-safe agrep
if [[ $(whence-type agrep) != command ]]; then
function agrep () { grep $* }
fi
fi
alias edrxmozilla='sudo -u edrx mozilla'
# «netbotanic» (to ".netbotanic")
# (find-fline "/etc/hosts")
# (find-fline "/etc/network/interfaces")
# (find-fline "/etc/resolv.conf")
#
function netbotanic-up () {
insmod mii
insmod 8139too
ifconfig eth0 10.127.56.1 netmask 255.255.255.0
route add default gw 10.127.56.254
cat > /etc/resolv.conf <<'%%%'
nameserver 200.184.42.69
nameserver 200.184.42.67
%%%
}
function netbotanic-down () {
ifconfig eth0 down
rmmod 8139too
rmmod mii
}
# Tests:
# «to-netbotanic-test» (find-angg ".emacs" "to-netbotanic-test")
# (eev "netbotanic-down; ifconfig; route -n")
# (eev "netbotanic-up; ifconfig; route -n")
# (eev "ifconfig; route -n; ping 10.127.56.1")
# (eev "ifconfig; route -n; ping -c 6 10.127.56.254")
# (eev "ifconfig; route -n; ping -c 6 200.184.42.69")
# (eev "ifconfig; route -n; ping -c 6 200.184.42.67")
#
# (eev "ifconfig; route -n; ping 10.127.56.254")
# (eev "ifconfig; route -n; ping 200.184.42.69")
# (eev "ifconfig; route -n; ping 200.184.42.67")
#
# Netbotanic/Moebius 2540-5170 -> 2294-3772
# (find-progoutput "ifconfig; route -n")
# For linux-2.4
function crystal-up () {
insmod soundcore
insmod sound
insmod v_midi
insmod mpu401
insmod ac97_codec
insmod cs46xx
}
function prep-persephone () {(
set -v
iso
loadkeys emacs2
netbotanic-up
crystal-up
)}
# «prep-home-cdd» (to ".prep-home-cdd")
function prep-home-cdd () {(
set -v
mkdir ~/tmp ~/lib ~/usrc ~/bigsrc ~/info/
ln -s .zshrc.local.cdd .zshrc.local
ln -s .xinitrc.cdd .xinitrc
)
rezshrc
}
# «prep-vt» (to ".prep-vt")
# «