Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#!/usr/bin/env zsh
# (find-es "zsh" "zshrc-hash-bang-eval")
# Edrx's .zshrc - 2022jan06
# Don't trust the date above, it's not updated automatically!
# Most things here are from the 90s.
# (find-es "zsh" "zsh-files")

# «.a»			(to "a")
# «.a_vt5»		(to "a_vt5")
# «.a_X_1_0»		(to "a_X_1_0")
# «.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")
# «.gnudoit»		(to "gnudoit")
# «.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")
# «.dmissingu»		(to "dmissingu")
# «.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")
#   «.makebblcites»	(to "makebblcites")
#   «.pdfpages-tex»	(to "pdfpages-tex")

# «.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")
# «.makepageindexhtmls»	(to "makepageindexhtmls")
# «.makeindexhtmls»	(to "makeindexhtmls")
# «.lstoindexhtml_lua_maybe»	(to "lstoindexhtml_lua_maybe")
# «.lstoindexhtml_lua_dirs»	(to "lstoindexhtml_lua_dirs")
# «.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")
# «.show2»		(to "show2")
# «.swig»		(to "swig")
# «.lua51e»		(to "lua51e")
# «.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")
# «.git-show-my»	(to "git-show-my")
# «.emacs28_»		(to "emacs28_")
# «.ae»			(to "ae")
# «.aeg»		(to "aeg")
# «.emacs-default»	(to "emacs-default")
# «.a_old»		(to "a_old")
# «.aegit»		(to "aegit")
# «.ax»			(to "ax")
# «.ax0»		(to "ax0")
# «.x00»		(to "x00")
# «.setxtermtitle»	(to "setxtermtitle")
# «.makecdrdaotoc»	(to "makecdrdaotoc")
# «.showcdrdaotoc»	(to "showcdrdaotoc")
# «.vlca»		(to "vlca")
# «.myaplay1»		(to "myaplay1")
# «.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")
# «.autopasswdz»	(to "autopasswdz")
# «.pucmailget»		(to "pucmailget")
# «.R»			(to "R")
# «.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")
# «.mypharo»		(to "mypharo")
# «.cuis»		(to "cuis")
# «.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")
# «.unpackimgzips»	(to "unpackimgzips")
# «.pppp»		(to "pppp")
# «.BMPtodjvu»		(to "BMPtodjvu")
# «.djvu-unpack»	(to "djvu-unpack")
# «.eev2-files»		(to "eev2-files")
# «.Scp-np»		(to "Scp-np")
# «.p8»			(to "p8")
# «.tt»			(to "tt")
# «.Twus-and-Twup»	(to "Twus-and-Twup")
# «.TWUS-and-TWUP»	(to "TWUS-and-TWUP")
# «.Lins-and-Linp»	(to "Lins-and-Linp")
# «.LINS-and-LINP»	(to "LINS-and-LINP")
# «.git-test»		(to "git-test")
# «.flac2mp3»		(to "flac2mp3")
# «.m4a2mp3»		(to "m4a2mp3")
# «.mp32mp3256»		(to "mp32mp3256")
# «.rot0»		(to "rot0")
# «.python»		(to "python")
# «.linkdasruas»	(to "linkdasruas")
# «.flsfiles»		(to "flsfiles")
# «.print-quadro-sexps»	(to "print-quadro-sexps")
# «.texlive-2016»	(to "texlive-2016")
# «.texlive-2017»	(to "texlive-2017")
# «.texlive-2018»	(to "texlive-2018")
# «.texlive-2019»	(to "texlive-2019")
# «.texlive-2020»	(to "texlive-2020")
# «.cabal»		(to "cabal")
# «.opam»		(to "opam")
# «.pip-path»		(to "pip-path")
# «.plan9»		(to "plan9")
# «.luarocks»		(to "luarocks")
# «.my-cmp-tkdiff»	(to "my-cmp-tkdiff")
# «.locale»		(to "locale")
# «.bracketed-paste»	(to "bracketed-paste")
# «.nim»		(to "nim")
# «.movedotemacs»	(to "movedotemacs")
# «.screenkey»		(to "screenkey")
# «.sk»			(to "sk")
# «.basename_tgz»	(to "basename_tgz")
# «.termux»		(to "termux")
# «.video-duration»	(to "video-duration")




# «a»  (to ".a")
# Old version: (to "a_old")
function a () {
  if [[ $TERM == "linux" ]]; then
    if   [[ $TTY == "/dev/tty1" ]]; then a_vt1;
    elif [[ $TTY == "/dev/tty5" ]]; then a_vt5;
    else echo "a: TERM=$TERM and TTY=$TTY, don't know what to do"
    fi
  elif [[ $TERM == "xterm" ]]; then
    if   [[  $DISPLAY == ":1.0" ]]; then a_X_1_0;
    else echo "a: TERM=$TERM and DISPLAY=$DISPLAY, don't know what to do"
    fi
  else echo   "a: TERM=$TERM, don't know what to do"
  fi
}
# «a_vt5»  (to ".a_vt5")
function a_vt5 () {
  setfont -C /dev/tty5 /usr/share/consolefonts/Lat15-Terminus12x6.psf.gz
  xinit -- :1.0 vt8 |& tee /tmp/ox &
}
# «a_X_1_0»  (to ".a_X_1_0")
# (to "sk")
# (find-fline "/var/log/Xorg.1.0.log")
function a_X_1_0 () { x00; fvwm3 & }

#     prep-vt; ae
#   elif [[ $TERM == "linux" && $TTY == "/dev/tty5" ]]; then
#     xinit -- :1.0 &
#   elif [[ $TERM == "linux" && $TTY == "/dev/tty10" ]]; then
#     prep-vt; xinit &
#   elif [[ $TERM == "linux" && $TTY == "/dev/tty11" ]]; then
#     prep-vt; xinit -- :1.0 &
#   elif [[ $TERM == "xterm" ]]; then
#     # prep-X; echo "# To invoke emacs run \"ae\""
#     fvwm &; google-chrome &; ax00 &
#   else
#     echo "a: TERM=$TERM and TTY=$TTY, don't know what to do"
#   fi
# }



: <<'%%%%%'
* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
. .zshrc
a

%%%%%



# «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")
# (find-man "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")
# See: (find-angg ".zshenv")
[[ "$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

export           EDRXPATH=$ORIGPATH:.:$HOME/EXPECT:$HOME/TCL:$HOME/pkg/bin

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
}


# «gnudoit»  (to ".gnudoit")
# Functions that use gnuclient's gnudoit.
# They were mainly 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
#
#####

# See: (find-psne-intro "7. A historical note")

# «Snarf»  (to ".Snarf")
# (find-fline "~/PERL/urlchop")
# (find-fline "~/.psne.log")
if [[ $S == "" ]]; then
  if [[ -e /snarf ]]; then
    export S=/snarf
  else
    export S=$HOME/snarf
  fi
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 apti0 () { $SUDO apt-get  install $* }
function apti  () { echo $* >> ~/.apti.log; apti0 $* }
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")
# This is VERY old!!!
# Use apt-file instead: (find-es "apt" "apt-file")
#
# (find-es "debian" "prep-Contents")
# (to "prep-Contents")
# (find-apthowtofile "apt-howto.en.txt.gz" "apt-file search")
# http://ftp.debian.org/debian/dists/squeeze/Contents-i386.gz
# http://ftp.debian.org/debian/dists/wheezy/Contents-i386.gz
# http://ftp.debian.org/debian/dists/wheezy/non-free/Contents-i386.gz
#
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 )
CONTENTSI386SZ=( $S/http/br.archive.ubuntu.com/ubuntu/dists/lucid/Contents-i386.gz )
CONTENTSI386SZ=( $S/http/ftp.debian.org/dists/lenny/Contents-i386.gz )
CONTENTSI386SZ=( $S/http/ftp.debian.org/debian/dists/squeeze/Contents-i386.gz )
CONTENTSI386SZ=( $S/http/ftp.debian.org/debian/dists/wheezy/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
}

# «dmissingu»  (to ".dmissingu")
# (find-es "ubuntu" "dmissingu")
# http://archive.ubuntu.com/ubuntu/dists/jaunty/Contents-i386.gz
function dmissingu () {
  zgrep -h $* $S/http/archive.ubuntu.com/ubuntu/dists/jaunty/Contents-i386.gz
}

# «prep-Contents»  (to ".prep-Contents")
# (to "dmissing")
# http://ftp.debian.org/dists/lenny/Contents-i386
# http://ftp.debian.org/dists/lenny/Contents-i386.gz
function prep-Contents () {
  if [[ ! -e $S/http/ftp.debian.org/dists/lenny/Contents-i386.gz ]];
  then   psne http://ftp.debian.org/dists/lenny/Contents-i386.gz
  fi
        zcat $S/http/ftp.debian.org/dists/lenny/Contents-i386.gz \
           > $S/http/ftp.debian.org/dists/lenny/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'

# A temporary, incomplete fix for Squeeze
# (find-man "1 dpkg" "dselect update")
# (find-man "8 apt-cache" "  showpkg pkg")
# (find-man "8 apt-cache" "  dumpavail")
# (find-other-debian-links "inconsolata")
# (find-other-debian-links "gentium")
# (find-zsh "grep-available gentium")
alias availabledebs='apt-cache dumpavail | 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 iso='(cd ~/vtutil4/; make isomath.8.setfont)'

alias 850='(cd ~/vtutil4/; make 850)'
alias 437='(cd ~/vtutil4/; make 437)'
alias iso='(cd ~/vtutil4/; make iso)'
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-es "tex" "xdvi-pid")
# (find-zshnode "Shell Builtin Commands" "return [ N ]")
# (find-zshnode "Complex Commands")
# 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")
# (find-LATEX "catsem.bib" "test")
# Typical usage:
#   (find-zsh "cd ~/LATEX/ && makebbl all.bbl catsem,filters")
#   (find-xpdfpage  "~/LATEX/tmpbib.pdf")
#   (find-pdftotext "~/LATEX/tmpbib.pdf")
# to create a file "all.bbl" with all entries from the .bib files
# "catsem.bib" and "filters.bib", in style "alpha".
# (find-man "1 bibtex")
# (find-man "1 makeindex")
function makebbl0 () {
  echo -E '\documentclass[oneside]{book}'
  echo -E '\usepackage[latin1]{inputenc}'
  echo -E '\usepackage{url}'
  echo -E '\begin{document}'
  echo -E '\nocite{*}'
  for i in $*[2,-1]; do echo -E '\bibliography{'$i'}'; done
  echo -E '\bibliographystyle{alpha}'
  echo -E '\end{document}'
}
function makebbl () {
  makebbl0 $* > tmpbib.tex
  pdflatex      tmpbib.tex
  bibtex tmpbib
  cp  -v tmpbib.bbl $1
}

# «makebblcites»  (to ".makebblcites")
function makebblcites () {
  grep ^@ | tr '{},' '   ' | awk '{printf "\\cite{%s}\n", $2}'
}

# «pdfpages-tex»  (to ".pdfpages-tex")
# (find-es "tex" "pdfpages-tex")
function pdfpages-tex () {
  echo "\
    \\\\documentclass[oneside]{book}
    \\\\usepackage{pdfpages}
    \\\\begin{document}
    \\\\includepdf[$1]{$2}
    \\\\end{document}"
}



#####
#
# 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")
# (find-node "(coreutils)dd invocation")
# (find-node "(coreutils)dd invocation" "`bs=BYTES'")
# (find-node "(coreutils)Block size" "`G'")
# 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 makeL1='mkdir ~/TH/R/; cd ~/TH/R/ &&
             DOLOCAL=1 make -f ~/TH/Makefile NEEDMAKEFILEAUTO=1 COPYING=1'
alias makeR1='mkdir ~/TH/R/; cd ~/TH/R/ &&
                       make -f ~/TH/Makefile NEEDMAKEFILEAUTO=1 COPYING=1'
function makeR1C () {
  makeR1 $1
  Scp ~/TH/R/$1 edrx@angg.twu.net:public_html/$1
  echo file://$HOME/TH/R/$1
  echo http://angg.twu.net/$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
}
# «makepageindexhtmls» (to ".makepageindexhtmls")
# (find-angg "LUA/lstoindexhtml.lua")
function makepageindexhtml () { LC_COLLATE=C lstoindexhtml_lua_maybe $1 .favicon.png }
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
}

# «lstoindexhtml_lua_dirs» (to ".lstoindexhtml_lua_dirs")
# Usage: cd ~/TH/R/ && lstoindexhtml_lua_dirs $(find .* * -type d | sort)
function lstoindexhtml_lua_dirs () {
  for i in $*; do
    (cd $i && LC_COLLATE=C lstoindexhtml_lua_maybe $i .favicon.png)
  done
}

# «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")
# http://jvns.ca/zines/
# http://jvns.ca/strace-zine-portrait.pdf
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
export LUA51SRC=$HOME/usrc/lua-5.1.4

# «show2»  (to ".show2")
# (find-show2-intro "2. Installation (on Debian)")
# (find-show2-intro "2. Installation (on Debian)" "SHOW2LATEXDIR")
export SHOW2LATEXDIR=$HOME/LATEX


# «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

# «lua51e»  (to ".lua51e")
# (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")
# Superseded by:
# (to "makepageindexhtmls")
#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")
# «prep-X»  (to ".prep-X")
# «a»  (to ".a")
function prep-vt () {
  echo iso;             iso
  echo loadkeys emacs2; loadkeys emacs2
}
function prep-X () {
  echo xsetroot -solid black; xsetroot -solid black
  # echo fvwm-replace 1;        fvwm-replace 1
  echo fvwm-replace;          fvwm-replace
  echo quickkeys-X;           quickkeys-X
}


# «git-show-my»  (to ".git-show-my")
# (find-es "git" "git-show-format")
git-show-my () {
  git show -s --date=format:'%Y-%m-%d %k:%M:%S' --format='%h %ad %s' $*
}

# «emacs28_»  (to ".emacs28_")
# (find-es "git" "git-bisect-by-hand")
# (find-fline "~/bigsrc/" "emacs28")
# (find-fline "~/bigsrc/" "emacs28_")
emacs25_0 () {
  ~/bigsrc/emacs27/src/emacs -T emacs25_0 -fg bisque -bg black -fn $EMACSFONT $*
}
emacs26_0 () {
  ~/bigsrc/emacs27/src/emacs -T emacs26_0 -fg bisque -bg black -fn $EMACSFONT $*
}
emacs27_0 () {
  ~/bigsrc/emacs27/src/emacs -T emacs27_0 -fg bisque -bg black -fn $EMACSFONT $*
}
emacs28_0 () {
  ~/bigsrc/emacs28/src/emacs -T emacs28_0 -fg bisque -bg black -fn $EMACSFONT $*
}
emacs28_0 () {
  ~edrx/bigsrc/emacs28/src/emacs -T emacs28_0 -fg bisque -bg black -fn $EMACSFONT $*
}
emacs29_0 () {
  ~edrx/bigsrc/emacs29/src/emacs -T emacs29_0 -fg bisque -bg black -fn $EMACSFONT $*
}
emacs28_ () {
  ~/bigsrc/emacs28_$1/src/emacs \
    -T emacs28_$1 -fg bisque -bg black -fn $EMACSFONT $*[2,-1]
}


# «ae»  (to ".ae")
# (find-es "zsh" "tty-var")
# (find-angg "bin/emacs-default")
# (find-angg "bin/emacs-default-x")
# (find-angg ".fvwm/.fvwm2rc" "style-bare")
# (find-sh "xlsfonts")
# (find-sh "xlsfonts | grep -v ^- | sort")
# (find-angg "bin/emacs-default")
# function emacs-default () {
#   if [[ -e ~/bigsrc/emacs/src/emacs ]]
#   then ~/bigsrc/emacs/src/emacs $*
#   else emacs $*
#   fi
# }
export EMACSFONT=6x13
export EMACSARGSX="-fg bisque -bg black -fn $EMACSFONT"
export EMACSARGSX0="-fg bisque -bg black -fn $EMACSFONT -geometry +0+0"
export EMACSARGSX00="$EMACSARGSX -T emacs_bare -geometry 167x49+0+0"
E0=(-fg bisque -bg black -fn $EMACSFONT  -T emacs_bare -geometry 167x49+0+0)

# «aeg»  (to ".aeg")
# «aegit»  (to ".aegit")
# (find-es "emacs" "several-emacs-versions")
# function ae () { emacs-default1 $* ~/TODO }
# function ae () { emacs-default1 $* ${TODOFILE:-$HOME/TODO} }
#
function ae   () { ae26 $* }
function aed  () { emacs   -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }
function ae24 () { emacs24 -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }
function ae25 () { emacs25 -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }
function ae25 () { ~/bigsrc/emacs25/src/emacs -T emacs25 \
                           -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }
function ae26 () { ~/bigsrc/emacs26/src/emacs -T emacs26 \
                           -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }
function ae27 () { ~/bigsrc/emacs27/src/emacs -T emacs27 \
                           -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }
function ae28 () { ~/bigsrc/emacs28/src/emacs -T emacs28 \
                           -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }
function ae29 () { ~/bigsrc/emacs29/src/emacs -T emacs29 \
                           -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }
function ae30 () { ~/bigsrc/emacs30/src/emacs -T emacs30 \
                           -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }
function aeg  () { ~/bigsrc/emacs/src/emacs   -T emacs-git \
                           -fg bisque -bg black -fn $EMACSFONT $* ~/TODO }

function ae28nw () { ~/bigsrc/emacs28/src/emacs -T emacs28 $* ~/TODO }

# «emacs-default» (to ".emacs-default")
function emacs-default-X () {
  emacs-default -fg bisque -bg black -fn ${EMACSFONT:-fixed} $*
}
function emacs-default-X0 () {
  emacs-default-X -geometry +0+0 $*
}
function emacs-default1 () {
  case $TERM in
    xterm*) emacs-default-X -T emacs_bare -geometry +0+0 $* &;;
            # was         -geometry +120+0 $* &;;
    *)      emacs-default -nw $*
  esac
}

function aet () { emacs-default -nw $* ${TODOFILE:-$HOME/TODO} }
function ae0 () { emacs-default -Q $* ${TODOFILE:-$HOME/TODO} }
# (find-enode  "Initial Options" "`--quick'")

# «a_old»  (to ".a_old")
# New version: (to "a")
# (find-elnode "Multiple Displays" "`HOST:SERVER.SCREEN'")
# function a () {
#   if [[ $TERM == "linux" && $TTY == "/dev/tty1" ]]; then
#     prep-vt; ae
#   elif [[ $TERM == "linux" && $TTY == "/dev/tty5" ]]; then
#     xinit -- :1.0 &
#   elif [[ $TERM == "linux" && $TTY == "/dev/tty10" ]]; then
#     prep-vt; xinit &
#   elif [[ $TERM == "linux" && $TTY == "/dev/tty11" ]]; then
#     prep-vt; xinit -- :1.0 &
#   elif [[ $TERM == "xterm" ]]; then
#     # prep-X; echo "# To invoke emacs run \"ae\""
#     fvwm &; google-chrome &; ax00 &
#   else
#     echo "a: TERM=$TERM and TTY=$TTY, don't know what to do"
#   fi
# }


# «ax»  (to ".ax")
# «ax0»  (to ".ax0")
# «x00»  (to ".x00")
# "ax0" is like "ax", but for lenny with a display manager.
# "ax00" is for offline laptops, where starting firefox does not always make sense.
# "x00" is like "ax00", but without "a".
# (find-es "x" "X-kbdrate")
# (find-es "x" "xsetroot")
# (find-angg ".Xdefaults")
# (find-es "x" "setxkbmap")
function ax () { a; firefox &; ae }
function ax0  () { xrdb -load  ~/.Xdefaults; xset r rate 250 30; xsetroot -solid black; firefox &; ae }
function ax00 () { xrdb -load  ~/.Xdefaults; xset r rate 250 30; xsetroot -solid black; ae }
function  x00 () {
  xrdb -load  ~/.Xdefaults
  xset r rate 250 20
  xsetroot -solid black
  setxkbmap us
}

# «fvwm»  (to ".fvwm")
# (find-man "fvwm" "-f config-file")

# «fvwm-replace»  (to ".fvwm-replace")
# (find-fline "~/.fvwm/.fvwm2rc")
# (find-fline "~/.fvwm/.fvwm2rc0")
# (find-fline "~/.fvwm/.fvwm2rc1")
function fvwm-replace () {
  fvwm -replace -f ~/.fvwm/.fvwm2rc$* &
}

# «setxtermtitle»  (to ".setxtermtitle")
# (find-udfile "xspecs/ctlseqs.txt.gz" "Change Window Title to Pt")
# (find-udfile "xtermcontrol/ctlseqs.txt.gz" "Change Window Title to Pt")
# (find-udfile "xterm/xterm.faq.gz" "read the title" "stty")
function setxtermtitle () {
  echo -ne "\033]2;$*\007"
}
# (eev "setxtermtitle la la la foo; read; setxtermtitle xterm")
# (eev "setxtermtitle la la la foo; read; setxtermtitle login")



# «makecdrdaotoc»  (to ".makecdrdaotoc")
# (find-es "cdrom" "jack")
# (find-angg ".emacs" "date")
function makecdrdaotoc () {
  echo '// (find-man "1 cdrdao" "TOC FILES")'
  echo 'CD_DA'
  echo 'CATALOG "'$1'"'
  shift
  for i in $*; do
    echo 'TRACK AUDIO'
    echo FILE \"$i\" 0
  done
}
# «showcdrdaotoc»  (to ".showcdrdaotoc")
function showcdrdaotracks () {
  (i=1; for NAME in $*; do echo "$i - $NAME"; i=$[$i+1]; done)
}
# Example:
# (find-zsh "A=(track_1 second third); makecdrdaotoc 2003012055555 $A")
# (find-zsh "A=(track_1 second third); showcdrdaotracks $A")

# «vlca»  (to ".vlca")
# (find-es "dvd" "vlc")
function vlca () { vlc --alsadev hw:1,0 $* }

# «myaplay1»  (to ".myaplay1")
function realtime () { sudo nice -n -40 sudo -u $USERNAME $* }
function myaplay1 () { realtime aplay              -d hw:1,0 $* }
function myaplay1 () { realtime aplay              -D hw:1,0 $* }
function myaplay1 () { realtime alsaplayer -i text           $* }
function myaplay1 () { realtime alsaplayer -i text -d hw:1,0 $* }
function mymplay1 () { realtime mplayer -ao alsa:device=hw=1.0 $* }

# function myaplay1 () { realtime aplay              -d hw:1,0 $* }
  function myaplay1 () { realtime aplay              -D hw:1,0 $* }
# function myaplay1 () { realtime alsaplayer -i text -d hw:0,0 $* }
  function myaplay1 () { realtime alsaplayer -i text -d hw:1,0 $* }
  function myaplay1 () { realtime alsaplayer -i text           $* }
alias rt=realtime

# «myplay»  (to ".myplay")
# «p»  (to ".p")
# (find-bashnode "Conditional Constructs" "case $ANIMAL in")
function myplay  () { for i in $*; do myplay1 $i; done }
# (find-es "alsa")
function myplay1 () {
  case $1 in
  # *.[Mm][Pp]3)    realtime mpg123 $*[2,-1] $1;;
  # *.[Mm][Pp]3)    realtime mplayer $*[2,-1] $1;;
  # *.ogg)          realtime ogg123 $*[2,-1] $1;;
  # *.wav) echo $1; realtime bplay $*[2,-1] $1;;
    *.[Mm][Pp]3)    myaplay1 $*[2,-1] $1;;
    *.ogg)          myaplay1 $*[2,-1] $1;;
    *.wav)          myaplay1 $*[2,-1] $1;;
    *.wma)          mymplay1 $*[2,-1] $1;;
    *.m4a)          mymplay1 $*[2,-1] $1;;
    *) echo "not mp3/ogg/wav/wma"
  esac
}
# (find-node "(coreutils)nice invocation")
# function myplaynice () { MYPLAYNICE=(sudo nice -n -19) myplay $* } 
#alias p=myplay
function p () { myplay $* }

# «plog»  (to ".plog")
# (find-efunction 'date)
# (find-efunction 'date-as-string)
# (find-efunction 'date-as-string "(eq arg 2)")
# (date-as-string 2)
# (find-sh0 "date '+%Y%b%d %k:%M'")
# (find-sh0 "date '+%Y%b%d %k:%M:%S'")
# (find-eevfile "eev-rctool" "function absolute ()")
# (find-angg ".zshrc" "p" "function myplay  ")
# (find-angg ".zshrc" "p" "function myplay1 ")
function absolute     () { case $1 in  /*) echo $1;;  *) echo $PWD/$1;;  esac; }
function semiabsolute () { absolute $1 | sed "s,^$HOME,~," }
function pfilename    () { semiabsolute $1 }
function pdate        () { date '+%Y%b%d %k:%M:%S' }               ;# echo date
function p1echo       () { echo "p $(pfilename $1) ;# $(pdate)" }
function p1log        () { p1echo $1 | tee -a ~/.plog }
  function p1         () {           myplay1 $1 }               ;#    just play
# function p1         () { p1log $1; myplay1 $1 }               ;# log and play
function p            () { for i in $*; do p1 $i; done }

function plogtail     () { tail ~/.plog }
function plogfollow   () { tail -f ~/.plog }

# «silentwav»  (to ".silentwav")
# Example of usage:
#   (eev "silentwav 200 /tmp/20s-of-silence.wav")
#   (eev "time bplay    /tmp/20s-of-silence.wav")
# Note that the duration is specified in 1/10s of a second.
#
function silentwav () {
  dd if=/dev/zero bs=$[4410*2*2] count=$1 \
   | sox -t .raw -r 44100 -s -w -c 2 - $2
}

# «ptowav»  (to ".ptowav")
# (find-man "1 mpg321" "-g N, --gain N")
# "Play to .wav" - produce a .wav instead of playing an audio file
function ptowav () {
  case $2 in
    *.wav)       ln -s $2 $1;;
    *.[Mm][Pp]3) mpg321 -w $1 $2;;
    *.m4a)       mplayer -ao pcm $2; mv -iv audiodump.wav $1;;
    *) echo "Usage: ptowav target.wav source.{wav,mp3,m4a}"
  esac
}



export LAB=$HOME/lab

alias acse='apt-cache search'
alias acsh='apt-cache show'


# «chroot-sarge»  (to ".chroot-sarge")
# (find-es "livecd")
#SARGESHROOT=(sudo chroot /sarge-root /bin/sh)
#SARGESHEDRX=(sudo chroot /sarge-root /usr/bin/sudo -u edrx /bin/sh)
#SARGEZSHROOT=(sudo chroot /sarge-root /home/edrx/run-zsh)
#SARGEZSHEDRX=(sudo chroot /sarge-root /usr/bin/sudo -u edrx /home/edrx/run-zsh)

# «mywhoami»  (to ".mywhoami")
# (find-node "(libc)Program Basics")
function mywhoami () {
  echo "UID=$UID EUID=$EUID"
  echo "USERNAME=$USERNAME LOGNAME=$LOGNAME"
  echo "GID=$GID EGID=$EGID"
  echo "groups=$(groups | tr ' ' ',')"
  echo "HOME=$HOME PATH=$PATH"
}

# «testmail»  (to ".testmail")
# (find-es "mail" "testmail")
function testmail () {(
  DATE=$(date +%R:%S)
  USER1=$1
  USER2=$2
  STR="($DATE) $USER1 -> $USER2"
  echo $STR
  echo $STR | sudo -u $USER1 mail $*[3,-1] -s $STR $USER2
)}

# «dotxpm»  (to ".dotxpm")
# (find-es "x" "xpm")
function dotxpm () {
  echo '/* XPM */'
  echo 'static char * myfig1x1[] = {'
  echo '"1 1 1 1",'
  echo '". c '$1'",'
  echo '"."};'
}

# «autopasswd»  (to ".autopasswd")
# «autopasswdz» (to ".autopasswdz")
# 2019mar10: now "autopasswd" is the script in ~/EXPECT/,
#            and "autopasswdz" is the zsh shell function.
# (find-angg "EXPECT/autopasswd")
# (find-es "expect" "passwords")
# (find-expcommand "interact" " -nobuffer ")
# (find-expcommand "interact" " exact ")
# (find-expcommand "interact" " -o ")
# (find-expcommand "interact" " -re ")
# (find-expcommand "expect [[-opts]")
# (find-angg ".passwds.tcl-")
#function autopasswdz () {
#expect =(<<'%%%'
#  source ~/.passwds.tcl
#  proc sendpasswd {passwd} { sleep 0.5; send $passwd\n }
#  set SUCURI sucuri.mat.puc-rio.br
#  set TWU    angg.twu.net
#  eval spawn $argv
#  interact {
#    -o -nobuffer "edrx@${SUCURI}'s password: " { sendpasswd $passwd(puc) }
#       -nobuffer "edrx@${TWU}'s password: "    { sendpasswd $passwd(twu) }
#       -nobuffer "edrx@parati's password: "    { sendpasswd $passwd(parati) }
#       "\033\[H\033\[JConnection to sucuri.mat.puc-rio.br closed." {}
#       "\033\[H\033\[JConnection to angg.twu.net closed." {}
#       "\033\[H\033\[JConnection to parati closed." {}
#  }
#%%%
#) $*
#}

#alias Sucuri='autopasswd ssh -C -l edrx sucuri.mat.puc-rio.br'
alias    Twu='autopasswd ssh -C edrx@angg.twu.net'

# «pucmailget»  (to ".pucmailget")
#function pucmailget () {
#  cd ~/MAIL/
#  autopasswd \
#    rsync -avz -e ssh \
#    edrx@${SUCURI}:/var/spool/mail/edrx ~/MAIL/current.pucmail
#}
#function pucmailread () {
#  cd ~/MAIL
#  mutt -R -f current.pucmail
#}

# (eev "autopasswd ssh -C -l edrx sucuri.mat.puc-rio.br")
# (eev "autopasswd ssh -C edrx@angg.twu.net")

# «R» (to ".R")
# (find-angg "run-zsh")
# alias R="sudo ~/run-zsh"
alias R="PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin sudo ~/run-zsh"

# «umlkill»  (to ".umlkill")
function umlkill () {
  # sudo kill $(cat ~/.uml/*/pid)
  sudo killall -9 linux
  sudo rm -Rfv ~/.uml/*
}

# «cddbtrackname»  (to ".cddbtrackname")
# (find-zsh0 "echo '/foo/bar.plic.ploc' | sed-extension")
# (find-zsh0 "echo 'TTITLE3=Paint It, Black' | cddbtrackname 04 && echo ok")
# (find-zsh0 "echo 'TTITLE3=Paint It, Black' | cddbtrackname 05 || echo not ok")
# (find-zsh0 "echo \"TTITLE18=(I Can't Get No) S\"| cddbtrackfilename tr19.ogg")
#
alias sed-extension="sed 's/^.*\(\.[^./]*$\)/\1/'"
function cddbtrackname () {
  lua50 =(<<<'
    N = tonumber(arg[1])
    for li in io.lines() do
      local _, __, n, str = string.find(li, "^TTITLE([0-9]*)=(.*)")
      if _ and N == n+1 then print(str); os.exit(0) end
    end
    os.exit(1)
  ') $1
}
function cddbtrackfilename () {(
  n=$(echo $1 | tr -cd 0-9)
  s=$(cddbtrackname $n | tr "\047/ " __)
  ext=$(echo $1 | sed-extension)
  echo $n-$s$ext
)}

# http://www.freedb.org/freedb/soundtrack/bf0cdb0e
# (find-zsh "cddb-rename-echo $S/http/www.freedb.org/freedb/soundtrack/bf0cdb0e track{1,2,3}.wav")
function cddb-rename-echo () {
  for i in $*[2,-1]; do
    echo "mv -iv $i $(cddbtrackfilename $i < $1)"
  done
}
function cddb-rename-mv () {
  for i in $*[2,-1]; do
    mv -iv $i $(cddbtrackfilename $i < $1)
  done
}

function setlogname () {
  export LOGNAME=$1
  export MAIL=/var/mail/$1
}

# «eev-current»  (to ".eev-current")
# «to-eev-current»  (find-angg ".emacs" "to-eev-current")
# (find-angg ".emacs" "eev-current-make-htmls")

# (find-eevex "tools.el" "make-eev-htmls")
#
# (progn (load-library (ee-eevexfile "tools.el")) (make-eev-htmls))
# (eev "eev-current-make; eev-current-upload")
#
function eev-current-make () {
  cd ~/eev-current/
  (TZ=GMT date; date) > VERSION
  tar -cvzf ~/eev-current.tar.gz $(cat .files)
  laf ~/eev-current.tar.gz
}
# «eev-current-upload»  (to ".eev-current-upload")
function eev-current-upload () {
  eev-current-make
  Scp ~/eev-current.tar.gz edrx@angg.twu.net:public_html/
  autopasswd rsh edrx@angg.twu.net '
    cd ~/public_html
    cp -v eev-current.tar.gz ..
    cp -v eev-current.tar.gz ../slow_html/
    ls -lAF eev-current.tar.gz
  '
}

# «upload»  (to ".upload")
# (find-angg ".emacs" "upload")
function absolute () { case $1 in  /*) echo $1;;  *) echo $PWD/$1;;  esac; }
function striphome () { absolute $1 | sed "s,^$HOME/,,"; }
function upload_command () {(
  FULLSTEM=$(striphome $1)
  DIRSTEM=$(dirname $FULLSTEM)
  FILESTEM=$(basename $FULLSTEM)
  echo "\
    cd ~/public_html/$DIRSTEM/ &&
    Scp $FILESTEM $FILESTEM.html \\
      edrx@angg.twu.net:public_html/$DIRSTEM/"
  echo "# http://angg.twu.net/$FULLSTEM"
  echo "# http://angg.twu.net/$FULLSTEM.html"
)}
function upload () {(
  makeP
  for i in $*; do
    COMMAND="$(upload_command $1)"
    echo -n $COMMAND
    eval $COMMAND
  done
)}

# (find-zsh0 "upload_command ~/eev-current/README")
# (find-zsh0 "upload_command ~/eev-current/examples/svn.e")

# (find-node "(screen)Detach")
# (find-zsh "xterm -h" "size (in characters)")
#
alias xterm-80x50-screen='xterm -geometry 80x50 -e screen'



# «prep-apti»  (to ".prep-apti")
#
function prep-apti-eev-full () {
  apti emacs21 emacs21-el elisp-manual emacs-lisp-intro w3m-el zsh expect
}
function prep-apti-lua () {
  apti liblua50     liblualib50     libtolua0    lua50     luasocket     \
       liblua50-dev liblualib50-dev libtolua-dev lua50-doc luasocket-dev
}
function prep-apti-etc () {
  apti less console-tools kbd-compat gpm zgv strace grep-dctrl \
       lsof netcat ltrace nmap build-essential
}
function prep-apti-autodetect () {
  apti read-edid hotplug discover mdetect kudzu
}
function prep-apti-X () {
  apti xdebconfigurator x-window-system fvwm xzoom tkdiff
}
function prep-apti-sound () {
  apti bplay mpg321 vorbis-tools
}
function prep-apti-dict () {
  apti dict dictd dict-gcide dict-wn dict-jargon
# apti dict-freedict-eng-por dict-vera
}
function prep-apti-dev-doc () {
  apti glibc-doc bash-doc zsh-doc grub-doc
}
function prep-apti-dev-debian () {
  apti apt-howto-en		\
       debian-installer-manual	\
       debian-policy		\
       debian-reference-en	\
       developers-reference	\
       doc-debian		\
       libapt-pkg-doc		\
       maint-guide		\
       quick-reference-en
}

function prep-apti-all () {
  prep-apti-eev-full
  prep-apti-lua
  prep-apti-autodetect
  prep-apti-etc
  prep-apti-X
  prep-apti-sound
  prep-apti-dict
  prep-apti-dev-doc
  prep-apti-dev-debian
}

# These are not included in prep-apti-all
function prep-apti-extras () {
  apti tetex-base tetex-bin tetex-doc tetex-extra tetex-src \
       ssh rsync cvs \
       gv a2ps gimp imagemagick mozilla-firefox xzgv unclutter \
       tcl8.4-dev tcl8.4-doc tk8.4-dev tk8.4-doc tclreadline libtk-img \
       cdparanoia cdrdao cdrecord \
       debootstrap
}
function prep-apti-emulation () {
  apti qemu user-mode-linux user-mode-linux-doc uml-utilities
}

# «prep-apti-builddeps-emacs»  (to ".prep-apti-builddeps-emacs")
# (find-es "emacs" "emacs-from-cvs")
# http://ftp.debian.org/debian/pool/main/e/emacs21/emacs21_21.4a+1-3.dsc
function prep-apti-builddeps-emacs () {
  apti cvs mailx libncurses5-dev texinfo liblockfile-dev libungif4-dev \
    libtiff4-dev libtiff-dev xaw3dg-dev libpng3-dev libjpeg62-dev \
    autotools-dev dpkg-dev quilt debhelper libxaw7-dev sharutils
}
function prep-apti-builddeps-lua () {
  apti build-essential libreadline5-dev
}

# «prep-X-reconfigure»  (to ".prep-X-reconfigure")
# (find-es "conf")
#
function prep-X-reconfigure () {
  # dpkg-reconfigure xserver-xfree86
    dpkg-reconfigure xserver-xorg
}

# «prep-X-nodm»  (to ".prep-X-nodm")
# (find-apt-answer "nodm?")
# update-rc.d -f xdm remove
# (find-fline "/etc/init.d/xdm" "Not starting X display manager (xdm)")
function prep-X-nodm () {
  echo false > /etc/X11/default-display-manager
}

# (find-es "emacs" "erc")
# http://erc.sourceforge.net/snaps/
# http://erc.sourceforge.net/snaps/erc-2004-12-05.tar.gz
function prep-erc () {
  if [[ ! -e $S/http/erc.sourceforge.net/snaps/erc-2004-12-05.tar.gz ]]; then
    psne http://erc.sourceforge.net/snaps/erc-2004-12-05.tar.gz
  fi
  rm -Rfv ~/usrc/erc/
  tar -C ~/usrc/ -xvzf $S/http/erc.sourceforge.net/snaps/erc-2004-12-05.tar.gz
  cd     ~/usrc/erc/
  make   |& tee om
}

# «prep-guest-mount»  (to ".prep-guest-mount")
# (find-fline "/etc/fstab" "\n# /guest")
function prep-guest-mount () {
  mount /guest
  mount /guest/proc
  mount /guest/sys
  mount /guest/dev/pts
  mount /guest/dev/shm
}
function prep-guest-umount () {
  umount /guest/dev/shm
  umount /guest/dev/pts
  umount /guest/sys
  umount /guest/proc
  umount /guest
}


function aumix-vol () { sudo aumix -v $1 -w $1 }

# «aa»  (to ".aa")
#function aa () {
#  sudo ifconfig lo 127.0.0.1
#  sudo route add -host 127.0.0.1 lo
#  sudo modprobe snd_pcm_oss
#  sudo chmod 4755 /sbin/kbdrate
#  sudo chmod 666  /dev/fd0
#  sudo chmod 666  /dev/lp0
#  sudo modprobe -r apm
#  sudo modprobe apm power-off=1
#  # (find-sh "ls -lAF /dev/ | grep audio")
#  sudo chmod 666 adsp audio dsp mixer rtc
#  sudo aumix -v 90 -w 90
#  sudo modprobe ide-cd		;# for linux 2.6
#}

# (find-es "sound" "alsaconf")
#function aa () {
#  sudo alsaconf
#  sudo alsactl store
#  # For persephone (for aumix):
#  sudo chmod 777 /dev/.static
#  sudo rm -fv /dev/sound  &&  sudo ln -sf .static/dev /dev/sound
#  sudo cp -sv /dev/.static/dev/dsp /dev/
#  sudo aumix -v 97 -w 98
#  sudo aumix -v query
#  sudo aumix -w query
#}


# «ASROOT»  (to ".ASROOT")
# For tramp: (find-es "emacs" "tramp")
export ASROOT="/sudo:root@localhost:"

# (find-es "mail" "mutt-accents")
#function mymutt () {
#  LANG=en_US LANGUAGE=en_US LC_ALL=en_US mutt $*
#}
#function mymutt () {
#  LANG=en_US.ISO-8859-1 LANGUAGE=en_US.ISO-8859-1 LC_ALL=en_US.ISO-8859-1 \
#    mutt $*
#}

# «intermail»  (to ".intermail")
# (find-angg ".emacs" "intermail")
# (find-angg "bin/intermail")
function intermailfiles () {
  for i in $*; do echo $i.args; echo $i.input; done
}
function intermailupload () {
  cd ~/INTERMAIL/; Scp $(intermailfiles $*) edrx@${SUCURI}:INTERMAIL/
}
function intermailrealsend () {
  cd ~/INTERMAIL/ && \
  for i in $*; do
    echo "Running: sendmail $(cat $i.args) < $i.input"
    sendmail $(cat $i.args) < $i.input
  done
}

function mycd () { mkdir -p $1; cd $1 }

# «mymkdircd»  (to ".mymkdircd")
# Note the "exit"; this function is meant to be used in find-zsh0
# (find-zsh0 "mymkdircd /tmp/shots/; import -window root $(myincr n).png")
# (find-fline "/tmp/shots/")
function mymkdircd () {
  mkdir -p $1
  cd $1 || (echo "Not a usable directory: $1"; exit 1)
}

# «myincr»  (to ".myincr")
# (find-angg "bin/Xscreenshot")
function myincr () {
  if [[ ! -e $1 ]]; then echo 0 > $1; fi
  echo $[$(< $1)+1] | tee $1
}

# «ncget»  (to ".ncget")
# «ncsend»  (to ".ncsend")
# REMOTE=24.60.246.134
#REMOTE=24.60.246.134
#NCPORT=1234
#function ncget () {
#  mkdir -p /tmp/nc/
#  cd       /tmp/nc/
#  netcat -l -p $NCPORT > $(myincr n).tgz
#  tar -tvzf $(cat n).tgz
#  echo -n "   "; ls -l $PWD/$(cat n).tgz
#}
#function ncsend () {
#  tar -cvf - $* | gzip -c9 | netcat -q 0 ${REMOTE:-localhost} $NCPORT
#}
# A demo:
# (eechannel-xterm "A")
# (eechannel-xterm "B")
# (eechannel "A" "ncget\r")
# (eechannel "B" "cd ~/elisp; REMOTE='' ncsend tron.el tron.el.png\r")

function uploadtoworkshop () {
  Scp $1 edrx@angg.twu.net:public_html/workshop/$(basename $1)
  echo http://angg.twu.net/workshop/$(basename $1)
}


# «myip-ppp0»  (to ".myip-ppp0")
# (find-angg ".emacs" "myip")
# (find-zsh "ifconfig ppp0; myip-ppp0")
#
function myip-ppp0 () {
  ifconfig ppp0 | awk 'NR==2' | tr : ' ' | awk '{print $3}'
}
# Then I can do "netcat -l -p 1234 > /tmp/file" on my machine
# and someone else can pipe a file through this:
# (find-zsh "echo \"| netcat $(myip-ppp0) 1234\"")


# For qemu
# example: echo foo | toguest
#function toguest   () { nc -q 0 172.20.0.2 1234 }
#function fromguest () { nc -l -p 1234 }

#export AMULE=~/usrc/aMule-2.0.0rc8/src/amule
#export AINCOMING=~/.aMule/Incoming
#export ATEMP=~/.aMule/Temp/


# For movies
# PS1="%d(%n$_CHROOTSTR)# "
# PS1="%d# "


# (find-es "x" "fstobdf")
#function myfstobdf () { fstobdf -s 127.0.0.1:7100 -fn $* }

# «fvwm-bw»  (to ".fvwm-bw")
function fvwm-bw () {
  FvwmCommand 'Style "*" Color white/gray50'
  FvwmCommand 'Style "*" HilightFore white'
  FvwmCommand 'Style "*" HilightBack gray25'
  FvwmCommand 'KillModule FvwmPager'
  xsetroot -solid white
}

#export MODDIR=/lib/modules/2.6.8-1-386
#export CONVITE=/var/www/tmp/convite
#export POD=24.60.246.134

function myfiglet () { figlet $* | awk '{printf "%% %s\n", $0}' }

#export VW=/var/www
#export VWT=/var/www/tmp


# «hh»  (to ".hh")
# (find-angg ".emacs" "hh")
# http://article.gmane.org/gmane.emacs.eev.devel/22
# http://lists.gnu.org/archive/html/eev/2005-07/msg00019.html
function hh () { history | tee $EEVTMPDIR/hh }



#--------
# UFF
# cd ~/eev-current/; ./eev-rctool prepare
# mkdir -p ~/tmp ~/usrc

# «regv-beamer»  (to ".regv-beamer")
# (find-es "ps" "gv")
# (find-node "(gv)Resource files" "~/.gv")
function regv-beamer () {
  echo 'GV*background: black' > ~/.gv.beamer
  regv $1 --ad=$HOME/.gv.beamer --spartan --scale=3 -geometry 1135x785+916+737
}

function upload-re () {
  Scp ~/re edrx@angg.twu.net:public_html/
}


# «Xfontslists»  (to ".Xfontslists")
# (find-es "x" "deb-for-a-font")
function Xfontslists () {
  find /usr/X11R6/lib/X11/fonts/ -type f -name 'fonts.dir'
  find /etc/X11/fonts/           -type f -name '*.alias'
}
# (find-zsh "grep -i Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO10646-1 $(Xfontslists)")
# (find-zsh "dmissing usr/X11R6/lib/X11/fonts/misc/6x13.pcf.gz")

# «router-config-jan2006»  (to ".router-config-jan2006")
# For the router, 2006jan05
# Btw: (find-fline "/etc/resolv.conf")
# terra: nameserver 200.149.55.143
#        nameserver 200.165.132.148
# velox: 
#function ii () {
#  sudo poff -a
#  sudo ifconfig eth0 down
#  sudo ifconfig eth0 192.168.0.5 up
#  sudo route add default gw 192.168.0.1
#}

# (find-fline "/etc/" "resolv.conf")
# (find-fline "/etc/resolv.conf")
# Velox: (find-zsh0 "setresolvconf 200.149.55.142 200.165.132.148")
# Terra: (find-zsh0 "setresolvconf 200.149.55.143 200.165.132.148")
# Scorphus: (find-zsh0 "setresolvconf 200.165.132.147 200.165.132.154")
# Scorphus: (find-zsh0 "setresolvconf 200.149.55.140  200.165.132.148")
# Koolosh: (find-zsh0 "setresolvconf  200.149.55.142  200.165.132.154")
#function setresolvconf () {
#  sudo chmod 666 /etc/resolv.conf
#  echo namerserver $1  > /etc/resolv.conf
#  echo namerserver $2 >> /etc/resolv.conf
#  # sudo chmod 644 /etc/resolv.conf
#}

# «wrap»  (to ".wrap")
# (find-node "(gawk)ARGC and ARGV")
# (find-zsh "cd ~/TH/L/; grep -il inx $(find *) | sort | wrap -fline '~/TH/L/'")
function wrap () {
  awk -v LINK="$1" -v PREFIX="$2" '
    {printf "(find%s \"%s%s\")\n", LINK, PREFIX, $0}
  '
}

# «cddb2rentracks»  (to ".cddb2rentracks")
# (find-angg ".emacs" "freedb-rename")
# (find-angg "bin/gsub.lua")
# (find-zsh "cddb2rentracks < $S/http/www.freedb.org/freedb/rock/cf0d740f")
function cddb2rentracks () {
  gsub.lua -f \
    'TTITLE([0-9]+)=(.*)' \
    'function (n, name) return
         format("rentrack %02d %s", n+1,
                string.lower(gsub(name, "[ \039]", "_")))
       end'
}

# «wavsandtracks»  (to ".wavsandtracks")
# Find the "trackNN.cdda.{wav,ogg}" and the wav files in my ~/NICOTINE dir
# (find-zsh "wavsandtracks")
# (find-sh "cd $S/http/www.freedb.org/; grep -i gong $(find * -type f) | gsub.lua '' 'http://www.freedb.org/%1'")
function wavsandtracks () {
  cd; find NICOTINE | egrep 'track|wav$' | xargs -n 1 dirname \
    | sort | uniq | gsub.lua '' '(find-fline "~/%1/")'
}

# «ruby»  (to ".ruby")
# For tons of details see: (find-angg ".ruby/edrxinit.rb")
export RUBYLIB=$HOME/.ruby

# «mplayer»  (to ".mplayer")
# (find-es "dvd" "mplayer-upstream")
#export MPLAYERDIR=$HOME/bigsrc/MPlayer-1.0pre8

# «mysqueak»  (to ".mysqueak")
# (find-angg ".emacs" "squeak")
# (find-es "squeak" "install-2023")
# (find-es "squeak" "20220302-transpose")
# (find-es "squeak" "squeak-debian-2006")
# (find-fline "~/SQUEAK/Squeak6.0-22104/")
function mysqueak () { cd ~/SQUEAK/Squeak5.3-19459-64bit-202003021730-Linux/; ./squeak.sh }
function mysqueak () { cd ~/SQUEAK/Squeak6.0-22104-64bit-202206021410-Linux-x64/ && ./squeak.sh }
function mysqueak () { cd ~/SQUEAK/Squeak6.0-22104/ && ./squeak.sh & }

# «mypharo»  (to ".mypharo")
# (find-es "pharo" "running-PHARO")
function mypharo () { cd ~/PHARO/; ./pharo-ui & }

# «cuis»  (to ".cuis")
# (find-es "cuis")
function mycuis () { cd ~/usrc/cuis/MyProject/ && cogspur/squeak Cuis-Smalltalk-Dev/Cuis6.0-5608.image }


# «eth_multicast_diagnose»  (to ".eth_multicast_diagnose")
# 2006sep28: I replaced my SiS 86c326 (PCI, 4MB) by a Riva TNT2 (AGP,
# 32MB) and the ethernet card stopped working... The error - at
#   (find-fline "$ASROOT/var/log/ppp-connect-errors")
# was: "pppoe: Interface eth0 has broadcast/multicast MAC address??"
#
# (find-zsh "eth_multicast_diagnose")
# (find-zsh "eth_multicast_diagnose" "into ram disk...")
# (find-zsh "eth_multicast_diagnose |& tee ~/tmp/oethmc_eth_eth=via.txt")
# (find-fline                             "~/tmp/oethmc_eth_eth=via.txt")
# (find-zsh "eth_multicast_diagnose |& tee ~/tmp/oethmc_eth_eth=2=11.txt")
# (find-fline                             "~/tmp/oethmc_eth_eth=2=11.txt")
# (find-zsh "eth_multicast_diagnose |& tee ~/tmp/oethmc_eth_lowermost.txt")
# (find-zsh "eth_multicast_diagnose |& tee ~/tmp/oethmc_eth_lowermost1=11.txt")
# (find-fline                             "~/tmp/oethmc_eth_lowermost.txt")
# (find-fline                             "~/tmp/oethmc_eth_lowermost1=11.txt")
#
function eth_multicast_diagnose () {
  # (find-node "(sed)Escapes")
  echo " dmesg | sed s/.\\d008//g:"
         dmesg | sed s/.\\d008//g; echo
  echo " lspci:"
         lspci; echo
  echo " ifconfig:"
         ifconfig; echo
  echo " sudo tail /var/log/ppp-connect-errors"
         sudo tail /var/log/ppp-connect-errors; echo
  echo " cat /proc/interrupts"
         cat /proc/interrupts; echo
  echo " cat /proc/ioports"
         cat /proc/ioports
}

# «asgraftpoints»  (to ".asgraftpoints")
# (find-man "8 mkisofs" "-graft-points")
function asgraftpoints () {
  awk '{ print "/" $1 "=" $1 }' > /tmp/graft.points
  echo -graft-points -path-list /tmp/graft.points
}


# «music_dirs»  (to ".music_dirs")
# (progn (eejump nil) (ee-goto-rest '("eq arg 38")))
#MP3=/big/music/mp3            ;# (find-fline "/big/music/mp3/")
#NICOTINE=$HOME/NICOTINE       ;# (find-fline "~/NICOTINE/")
#RIPS=/big/music/rips          ;# (find-fline "/big/music/rips/")
#RIPSBRA=/big/music/rips-bra   ;# (find-fline "/big/music/rips-bra/")
#RIPSRARE=/big/music/rips-rare ;# (find-fline "/big/music/rips-rare/")
#OWAVS=/oldfs/music            ;# (find-fline "/oldfs/music/")
#DTOGGS=$VWT/DTO/ogg           ;# (find-fline "$VWT/DTO/ogg/")
#          ;# (find-fline "~/tmp/rips/troggs-best/excellent/")
#          ;# (find-fline "~/tmp/rips/")
#          ;# (find-fline "$VWT/")


# «psne-over»  (to ".psne-over")
function psne-rm () { rm -v $(urldir $1)$(basename $1) }
function psne-over () { psne-rm $1; psne $1 }

# (find-zsh0 "psne-over http://dto.freeshell.org/e/cell.el")
# (find-dtoefile "cell.e")

# «MAKEDEV_create»  (to ".MAKEDEV_create")
# (find-angg ".emacs" "find-cat-to-lp0-script")
# (find-angg ".emacs" "find-cat-to-lp0-script" "MAKEDEV_create /tmp/lp0")
# Use this with "/dev/MAKEDEV -n"...
# (find-sh "cd /tmp/; /dev/MAKEDEV -n audio")
# (find-sh "cd /tmp/; /dev/MAKEDEV -n lp")
# (find-fline "/dev/MAKEDEV" "create $1	$2 $3 $4 $5:$6 $7")
# (find-fline "/dev/MAKEDEV" "mknod $1- $2 $3 $4")
function MAKEDEV_create () {
  rm -f $1-
  if mknod $1- $2 $3 $4 &&
     chown $5 $1- &&
     chmod $6 $1- &&
     mv $1- $1
  then
     : # it worked
  else
     # Didn't work, clean up any mess...
     echo "makedev $@: failed"
     rm -f $1-
  fi
}

function channel () { $EEVDIR/eegchannel $1 $SHELL; }

export LANG=C

function myps2up () { pstops "2:0L@.6(19cm,1cm)+1L@.6(19cm,13.85cm)" $* }


# «eeh»  (to ".eeh")
# http://article.gmane.org/gmane.emacs.eev.devel/59
# http://lists.gnu.org/archive/html/eev/2007-09/msg00009.html
# function ee () { set -v; print -s -f "%s" "`cat $EE`"; . $EE $*; set +v; }
function eeh () { set -v; print -s -f "%s" "$(cat $EE)"; echo "(Added to history:)"; cat $EE; set +v; }


function kill-firefox () {
  echo "killall $* firefox-bin"
        killall $* firefox-bin
}


# «mesk-up»  (to ".mesk-up")
# For meskita (my machine at omnisys)
#function mesk-up () {
#  sudo dhclient
## sudo ifconfig eth2:1 10.1.0.101 netmask 255.255.0.0
#  sudo ifconfig eth2:1 10.1.0.15 netmask 255.255.0.0
#  sudo ifconfig
#  # Caramba, tem eth2 e eth2:1?
#}

# «pers-up»  (to ".pers-up")
# Make persephone available at the birdland net
#function pers-up () {
#  sudo ifconfig eth1:1 10.1.0.101 netmask 255.255.0.0
#  sudo ifconfig
#}

# «dek-up»  (to ".dek-up")
# For dekooning at omnisys <- no longer.
# Make dekooning available at the birdland net
# (find-sh "sudo ifconfig")
#function dek-up () {
#  # sudo dhclient
#  sudo ifconfig eth0:1 10.1.0.102 netmask 255.255.0.0
#  sudo ifconfig
#}

# «mesk-ip»  (to ".mesk-ip")
# (find-sh "sudo ifconfig")
# (find-sh "sudo ifconfig eth2")
# (find-sh0 "sudo ifconfig eth2 | tr ' :' '\\n\\n' | grep 192 | head -n 1")
# (find-zsh0 "mesk-ip")
#function mesk-ip () {
#  sudo ifconfig eth2 | tr ' :' '\n\n' | grep 192 | head -n 1
#}

# «muttfetchmail»  (to ".muttfetchmail")
# (find-es "mail" "mutt-keys")
# Because at omnisys a POP/SSL fetch authorizes sending mail for some minutes
# (find-zsh "TERM=vt100 muttfetchmail")
#function muttfetchmail () {
#  expect -c '
#    set timeout -1
#    log_user 1
#    spawn mutt
#    send Gx
#    expect eof {}
#  '
#}



# «tcl-tk»  (to ".tcl-tk")
# (find-angg ".emacs" "tcl-tk")
# (find-es "tcl" "tcl8.4-deb-src")
# (find-es "tcl" "tk8.4-deb-src")
# (find-tk84sh  "cd unix; LD_LIBRARY_PATH=                       ldd ./wish")
# (find-tk84sh  "cd unix; LD_LIBRARY_PATH=$TCLTK_LD_LIBRARY_PATH ldd ./wish")
# (find-tcl84sh "cd unix; LD_LIBRARY_PATH=                       ldd ./tclsh")
# (find-tcl84sh "cd unix; LD_LIBRARY_PATH=$TCLTK_LD_LIBRARY_PATH ldd ./tclsh")
#export TKSRCDIR=$HOME/usrc/tk8.4/tk8.4-8.4.12/unix
#export TCLSRCDIR=$HOME/usrc/tcl8.4/tcl8.4-8.4.12/unix
#export TCLTK_LD_LIBRARY_PATH=$TCLSRCDIR:$TKSRCDIR:

# «tarcp»  (to ".tarcp")
# (find-zsh0 "function foo () {echo $*[1,-2]}; foo A B C D ;#-> A B C")
# function tarcp () { echo tar -cf - $*[1,-2] "|" tar -xvf - -C $*[-1] }
function tarcp () { tar -cf - $*[1,-2] | tar -xvf - -C $*[-1] }

# «fvwm-netbsd»  (to ".fvwm-netbsd")
# (find-es "fvwm" "fvwm-netbsd")
# For NetBSD machines in which I have to compile fvwm inside
# my home directory...
#function fvwm-netbsd () {
#  FVWM_MODULEDIR=$HOME/usrc/fvwm-2.5.18/usr/libexec/fvwm/2.5.18 \
#   LD_LIBRARY_PATH=/usr/X11R6/lib \
#    ~/usrc/fvwm-2.5.18/fvwm/fvwm -replace &
#}

# if machinename == freire then alias fvwm to fvwm-netbsd (?)


# (find-es "http" "disguise-user-agent")
# (find-es "wget" "user-agent")
# (find-fline "$VWT/screenies/set.cgi")
export MOZILLA_USER_AGENT='Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070310 Iceweasel/2.0.0.3 (Debian-2.0.0.3-1)'

# (find-udw3m "lynx/lynx_help/Lynx_users_guide.html" "-auth=ID:PW")
# (find-udw3m "lynx/lynx_help/Lynx_users_guide.html" "-useragent=STRING")
function dpsne () {
  # psne $* --http-user=owzFHY --http-password=KpzHPuX@ -U $MOZILLA_USER_AGENT -c
  psne $* --http-user=4hzcdX --http-password=arXtY8xR -U $MOZILLA_USER_AGENT -c
}
function dlynx () {
  lynx -auth=owzFHY:KpzHPuX@ -useragent=$MOZILLA_USER_AGENT $*
}
function dlynxz () {
  dlynx -dump $1 | tr ' ' \\n | grep http | grep zip
}
#function hpsne () {
#  psne $* --http-user=eduardoochs --http-password=Pogob0l -U $MOZILLA_USER_AGENT -c
#}

# «unpackimgzips» (to ".unpackimgzips")
function unpackimgzip_at () {
  echo mkdir -p $1$(basename $2 .zip)/
       mkdir -p $1$(basename $2 .zip)/
  echo unzip -d $1$(basename $2 .zip)/ $2
       unzip -d $1$(basename $2 .zip)/ $2
}
function unpackimgzips_at () {
  for i in $*[2,-1]; do
    unpackimgzip_at "$1" $i
  done
}
function unpackimgzips () {
  unpackimgzips_at unpacked/ $*
}
function UNPACKimgzips () {
  unpackimgzips_at UNPACKED/ $(find $* -type f)
}


# «pppp»  (to ".pppp")
# (find-es "ppp")
# How to use this:
#   "pp"   kills the current pppoe connection,
#   "ppp"  tries to establish a pppoe connection
#          (it usually takes ~8 seconds to succeed),
#   "pppp" prints the last lines of the pppd log.
# This is very useful for Oi Velox - a (slow) broadband service
# in which the connection ofter breaks when the phone rings or
# someone picks up the phone.
#
#function pp   () { echo "sudo poff -a"; sudo poff -a; }
#function ppp  () { echo "sudo pon dsl-provider"; sudo pon dsl-provider; }
#function pppp () { echo "sudo plog"; sudo plog; }
#function rrrr () {
#  sudo route del -net 0.0.0.0 gw 192.168.254.254 netmask 0.0.0.0 dev eth0
#  sudo route del -net 192.168.254.0 gw 0.0.0.0 netmask 255.255.255.0 dev eth0
#}
#
# My lenny partition at persephone sets up a default gateway at eth0 at boot:
# Lenny:
# Kernel IP routing table
# Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
# 200.222.118.26  0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
# 192.168.254.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
# 0.0.0.0         192.168.254.254 0.0.0.0         UG    0      0        0 eth0
#
# Etch:
# Kernel IP routing table
# Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
# 200.222.118.26  0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
# 0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 ppp0
#
# and?... 8-\

# «BMPtodjvu»  (to ".BMPtodjvu")
# (find-es "scan" "bmps-to-djvu")
#function BMPtodjvu () {
#  for i in $*; do
#    j=$(basename $i .BMP).pbm
#    k=$(basename $i .BMP).djvu
#    echo convert $i $j
#         convert $i $j
#    echo cjb2 -dpi 600 -lossy $j $k
#         cjb2 -dpi 600 -lossy $j $k
#  done
#}
#function BMPtodjvu_filenames () {
#  for i in $*; do echo $(basename $i .BMP).djvu; done
#}
#function BMPstopdf () {
#  BMPtodjvu $*[2,-1]
#  echo djvm -create      $1.djvu $(BMPtodjvu_filenames $*[2,-1])
#       djvm -create      $1.djvu $(BMPtodjvu_filenames $*[2,-1])
#  echo ddjvu -format=pdf $1.djvu $1.pdf
#       ddjvu -format=pdf $1.djvu $1.pdf
#}

# «djvu-unpack»  (to ".djvu-unpack")
# (find-es "scan" "djvu-unpack")
function djvu-unpack () {
  rm -Rv /tmp/djvu-unpack/
  mkdir  /tmp/djvu-unpack/
  # cd     /tmp/djvu-unpack/
  npage=0
  for fname_djvu in $A; do
    npages=$(djvused -e 'n' $fname_djvu)
    echo "$fname_djvu: $npages ($[$npage+1] to $[$npage+$npages])"
    for i in $(seq 1 $npages); do
      npage=$[$npage+1]
      npage_djvu=/tmp/djvu-unpack/$(printf "p%03d.djvu" $npage)
      djvused -e "select $i; save-page-with $npage_djvu" $fname_djvu
    done
  done
}
function djvu-repack () {
  djvm -create $1 /tmp/djvu-unpack/*.djvu
}

function mypdf2djvu () { pdf2djvu --monochrome --lossy -o $1.djvu $1 }


function rmmkdircd () { rm -Rfv $1; mkdir $1; cd $1; }

# (find-es "hardware" "nokia-x2-01")
# export CEL=/media/0000-EAF4/Playlists


# «p8» (to ".p8")
# 8.8.8.8 is Google DNS
p8 () { echo ping 8.8.8.8; ping 8.8.8.8; }

# «tt» (to ".tt")
tt () { while true; do date; sleep 1; done; }

# «Twus-and-Twup» (to ".Twus-and-Twup")
# (find-angg ".emacs" "tramp-twu")
# These are in tramp syntax.
export Twup=/scp:edrx@angg.twu.net:/home/edrx/public_html
export Twus=/scp:edrx@angg.twu.net:/home/edrx/slow_html
# «TWUS-and-TWUP» (to ".TWUS-and-TWUP")
# These are in ssh syntax.
export TWUS=edrx@angg.twu.net:slow_html
export TWUP=edrx@angg.twu.net:public_html

# «Lins-and-Linp»  (to ".Lins-and-Linp")
# «LINS-and-LINP»  (to ".LINS-and-LINP")
# (find-angg ".emacs" "linode")
export Linp=/scp:edrx@linode:/home/edrx/public_html
export Lins=/scp:edrx@linode:/home/edrx/slow_html
export LINS=edrx@linode:slow_html
export LINP=edrx@linode:public_html


# «git-test» (to ".git-test")
# (find-es "git" "git-test-2")
git-test () {
    N=0
    N () { echo $N; }
  ++N () { N=$[$N+1]; echo $N; }
  Dump1   () { echo $1 \($(cat $1)\); }
  Dumps   () { for i in $*; do Dump1 $i; done; }
  Dump    () { Dumps $(find * -type f | sort); }
  Modify1 () { ++N >> $1; Dump1 $1; }
  Modify  () { for i in $*; do Modify1 $i; done; }
  Commit  () { git commit -a -m $(N); }
  Diagram () { PAGER=cat git log --oneline --graph --decorate --all; }
}

function t () { transmission-gtk &; }

# «flac2mp3» (to ".flac2mp3")
# (find-es "mp3" "flac2all")
flac2mp3 () {
  mkdir $2
  # flac2all mp3 "$1" -o "$2" -l 'b 320'
    flac2all mp3 "$1" -o "$2" -l 'b 256'
}

# «m4a2mp3» (to ".m4a2mp3")
m4a2mp3 () {
  mkdir -p $2/
  for i_m4a in $1/*.m4a; do
    i=$2/$(basename $i_m4a .m4a)
    echo avconv -i $i_m4a -b:a 256k $i.mp3
         avconv -i $i_m4a -b:a 256k $i.mp3
  done
}

# «mp32mp3256» (to ".mp32mp3256")
mp32mp3256 () {
  mkdir -p $2/
  for i_320 in $1/*.mp3; do
    i=$2/$(basename $i_320 .mp3)
    echo avconv -i $i_320 -b:a 256k $i.mp3
         avconv -i $i_320 -b:a 256k $i.mp3
  done
}

# «rot0» (to ".rot0")
# (find-angg ".emacs" "rotate")
rot0 () {
  convert $1 -rotate 0 -auto-orient $1
}



# «python» (to ".python")
# (find-angg ".pythonrc.py")
# (find-es "python" "PYTHONSTARTUP")
# (find-es "python" "PYTHONSTARTUP" ".pythonrc.py")
export PYTHONSTARTUP=$HOME/.pythonrc.py




# «linkdasruas» (to ".linkdasruas")
# (find-es "localvideos" "command-line" "Generate /tmp/linkdasruas.{cps,dls}")
makelinkdasruashtml () {
  cd ~/TH/L/
  lua51        ~/blogme3/blogme3.lua \
    -lv_blogme ~/blogme3/local-videos.blogme \
    -big_videos_ls /sda5/videos/manifs/ \
    -videos_ls     manifs/ \
    -text          ~/linkdasruas.txt \
    -lv_html  ~/TH/L/linkdasruas.html \
    -cps /tmp/linkdasruas.cps \
    -dls /tmp/linkdasruas.dls
}
makelinkdasruashtmlcp () {
  makelinkdasruashtml
  cp -v ~/TH/L/linkdasruas.html ~/linkdasruas.html
}

export HOST
# (getenv "HOME")
# (getenv "HOST")




# «eev2-files» (to ".eev2-files")
# (find-eev2-links)
# (find-angg "eev-videos/")
# (find-angg "eev-videos/0.sh")
# (find-es "eev" "eev2.tgz")
# (find-eevsh "grep ^.require eev2-all.el")
# (find-eevsh "grep ^.require eev2-all.el | awk '{print $2}'")
# (find-eevsh "grep ^.require eev2-all.el | awk '{print substr($2, 2, length($2)-2)}'")
# (find-eevsh "grep ^.require eev2-all.el | awk '{print substr($2, 2, length($2)-2) \".el\"}'")
# (find-zsh "eev2-files")
# (find-zsh "eev2-files-all")

eev2-files () {
  grep ^.require ~/eev-current/eev2-all.el |
  awk '{print substr($2, 2, length($2)-2) ".el"}'
}
eev2-files-all () {
  echo VERSION
  echo README.md
  echo ChangeLog
  echo eev-readme.el
  echo eev2-all.el
  eev2-files
}
eev2-build-tgz () {
  cd ~/eev-current/
  (TZ=GMT date; date) > VERSION
  tar -cvzf /tmp/eev2.tgz $(eev2-files-all)
  laf       /tmp/eev2.tgz
}

eev2-files-all-git () {
  (cd ~/eev-current/; git ls-files)
}
eev2-build-tgz-git () {
  cd ~/eev-current/
  (TZ=GMT date; date) > VERSION
  tar -cvzf /tmp/eev2.tgz $(eev2-files-all-git)
  laf       /tmp/eev2.tgz
}

eev2-test-unpack () {
  rm -Rv /tmp/eev/
  mkdir  /tmp/eev/
  cd     /tmp/eev/
  tar -xvzf ../eev2.tgz
}
eev2-test () {
  eev2-build-tgz
  eev2-test-unpack
  FvwmCommand "CursorMove +0 +100" &&
    emacs-default-X0 -Q -l eev-readme.el eev-readme.el
  # emacs -Q -fn 6x13 -fg bisque -bg black eev-readme.el
  # (find-enode "Action Arguments")
}
eev2-upload0 () {
  Scp-np $* /tmp/eev2.tgz     edrx@angg.twu.net:slow_html/eev-current/
  Scp-np $* /tmp/eev2.tgz     edrx@angg.twu.net:public_html/eev-current/
  # Scp-np $* ~/eev-videos/2.el edrx@angg.twu.net:public_html/eev-videos/
}
eev2-upload () {
  # eev2-upload0 $* | grep -v password
  eev2-upload0 $*
}

eev2-upload0-tar () {
  Scp-np $* /tmp/eev2.tar     edrx@angg.twu.net:slow_html/eev-current/
  Scp-np $* /tmp/eev2.tar     edrx@angg.twu.net:public_html/eev-current/
}
eev2-upload-tar () {
  eev2-upload0-tar $*
}

# «Scp-np» (to ".Scp-np")
# (find-angg "EXPECT/Scp")
Scp-np () {
  Scp $* | grep -v password
}


function mkdire () {
  sudo mkdir $1; sudo chown -v edrx. $1
}

# «flsfiles» (to ".flsfiles")
# (find-angg "LUA/flsfiles.lua")
# (find-es "zsh" "positional-parameters")
# (find-latex-upload-links "2018dednat6-extras")
function flsfiles     () { ~/LUA/flsfiles.lua $1 | grep -v "^/" }
function flsfiles-tgz () { tar -chvzf "$2"       $(flsfiles $1) $*[3,-1] }
function flsfiles-zip () { rm -fv "$2"; zip "$2" $(flsfiles $1) $*[3,-1] }

# «print-quadro-sexps» (to ".print-quadro-sexps")
# (find-es "awk" "ARGV")
# (find-zsh "cd ~/2017.2-LA/; find *.jpg | cut -b-8")
# (find-zsh "cd ~/2017.2-LA/; find *.jpg | cut -b-8 | print-quadro-sexps laQ172")
function print-quadro-sexps () {
  Q=$1 awk '{printf(";; (%s %2d \"%s\")\n", ENVIRON["Q"], NR, $0)}'
}


# «my-cmp-tkdiff» (to ".my-cmp-tkdiff")
# (find-es "git" "eev-fix-git-2018may31")
# (find-es "zsh" "expansion")
# (find-angg "bin/gsub.lua")
function my-git-list-files () { (cd $1 &&           git ls-files $*[2,-1])     }
function my-git-laf-files  () { (cd $1 &&     laf $(git ls-files $*[2,-1]))    }
function my-git-cp-files   () { (cd $1 && cp -iav $(git ls-files $*[3,-1]) $2) }
function my-tkdiff-links   () { gsub.lua '.+' '(find-tkdiff "'$1'%1" "'$2'%1")'  }
function my-cmp            () { for i in $(cat); do echo $i; cmp $1$i $2$i; done }
function my-cmp-list       () { for i in $(cat); do cmp -s $1$i $2$i || echo $i; done }
function my-cmp-tkdiff     () { my-cmp-list ${~1} ${~2} | my-tkdiff-links $1 $2 }


# «locale» (to ".locale")
# (find-es "locale" "collation")
export LC_ALL=C


# «bracketed-paste» (to ".bracketed-paste")
# (find-es "zsh" "backeted-paste")
if [[ "$TERM" = dumb ]]; then unset zle_bracketed_paste; fi


# «nim»  (to ".nim")
# (find-es "nim" "nim-1.6.10")
# export PATH=$HOME/usrc/Nim/bin:$PATH


# «texlive-2016»  (to ".texlive-2016")
# «texlive-2017» (to ".texlive-2017")
# «texlive-2018» (to ".texlive-2018")
# «texlive-2019» (to ".texlive-2019")
# «texlive-2020» (to ".texlive-2020")
# See: (find-es "arxiv" "texlive-2016")
#      (find-es "arxiv" "texlive-2017")
# export PATH=/usr/local/texlive/2016/bin/x86_64-linux:$PATH
# export PATH=/usr/local/texlive/2017/bin/x86_64-linux:$PATH
# export PATH=/usr/local/texlive/2017/bin/x86_64-linux:$PATH
# export PATH=/usr/local/texlive/2018/bin/x86_64-linux:$PATH
# export PATH=/usr/local/texlive/2019/bin/x86_64-linux:$PATH
export PATH=/usr/local/texlive/2020/bin/x86_64-linux:$PATH
# export PATH=/usr/local/texlive/2021/bin/x86_64-linux:$PATH
# (find-sh "echo $PATH | tr : '\n'")


# «cabal»  (to ".cabal")
# (find-es "cabal" "cabal-PATH")
# (find-es "haskell" "cabal-PATH")
# (find-angg ".emacs" "cabal-path")
# (find-fline "~/.cabal/bin/")
#export PATH=$HOME/.cabal/bin:$PATH
export PATH=$HOME/.cabal/bin:$HOME/.ghcup/bin:$PATH

# «opam»  (to ".opam")
# (find-es "ocaml" "opam-init")
# (find-fline "~/.opam/opam-init/variables.sh")
# OPAM configuration
test -r ~/.opam/opam-init/init.zsh && . ~/.opam/opam-init/init.zsh > /dev/null 2> /dev/null || true

# «pip-path»  (to ".pip-path")
# (find-es "python" "pip")
# (find-fline "~/bin/")
# (find-fline "~/.local/bin/")
# (find-fline "~/.local/bin/" "yt-dlp")
# (find-fline "~/.elan/bin/")

# (find-fline "~/bin/")
# The script youtube-dl is installed in '/home/edrx/.local/bin' which
# is not on PATH.
# Consider adding this directory to PATH or, if you prefer to suppress
# this warning, use --no-warn-script-location.
#export PATH=$HOME/.local/bin:$PATH
#export PATH=$HOME/bin:$HOME/.local/bin:$PATH
export PATH=$HOME/bin:$HOME/.elan/bin:$HOME/.local/bin:$PATH

export PATH=$HOME/bin:$PATH
export PATH=$HOME/.local/bin:$PATH
export PATH=$HOME/.elan/bin:$PATH


# «plan9»  (to ".plan9")
# (find-es "plan9" "plan9port-2022")
export PLAN9=/home/edrx/usrc/plan9port
export PATH=$PATH:$PLAN9/bin

export PATH=$PATH:$HOME/.nimble/bin

# «luarocks»  (to ".luarocks")
# (find-fline "~/.luarocks/bin/" "luacheck")
# (find-fline "~/.luarocks/bin/luacheck")



# «movedotemacs»  (to ".movedotemacs")
# For Doom. Doesn't work well.
#movedotemacsto () {
#  cd &&
#  mkdir -fv $1 &&
#  mv -ifv .emacs .emacs.d $1/
#}
#movedotemacsfrom () {
#  cd &&
#  mv -ifv $1/.emacs $1/.emacs.d . &&
#  rmdir -v $1/
#}

# «screenkey»  (to ".screenkey")
# (find-es "screencasts" "screenkey")
screenkey-on () {
  screenkey -s small --mods-mode emacs --opacity 0.3 --timeout 0.5
}
screenkey-off () {
  killall screenkey
}

# «sk»  (to ".sk")
# (to "x00")
# (find-es "x" "setxkbmap")
# (find-es "x" "X-kbdrate")
sk () {
  setxkbmap us
}

# «basename_tgz»  (to ".basename_tgz")
# (find-es "unix" "tar")
basename_tgz () { basename $(tar -tzf $FNAME | head -n 1); }

# ecg () { mpv https://live0.emacsconf.org/gen.webm }
# ecd () { mpv https://live0.emacsconf.org/dev.webm }

# «termux»  (to ".termux")
# (find-angg ".emacs.templates" "find-termux-links")
# (find-es "termux")
# (find-es "android" "termux-rsync")
# (find-angg ".emacs" "termux")
exporttermuxvars () {
  $1 export TERMUXIP=192.168.1.2
  $1 export TERMUXIP=192.168.0.111
  $1 export TERMUXIP=192.168.43.1
  $1 export TERMUXIP=10.16.249.61
  $1 export TERMUXIP=10.3.184.122
  $1 export TERMUXUSER=u0_a037
  $1 export TERMUXE="ssh -l $TERMUXUSER -p 8022"
  $1 export TERMUXS="ssh://$TERMUXUSER@$TERMUXIP:8022"
  $1 export TERMUXWHATSAPP=$TERMUXIP:/storage/emulated/0/Android/media/com.whatsapp/Whatsapp
  $1 export TERMUXWPIMAGES="$TERMUXWHATSAPP/Media/WhatsApp\\ Images"
  $1 export TERMUXWPVIDEO="$TERMUXWHATSAPP/Media/WhatsApp\\ Video"
  $1 export TERMUXCAMERA="$TERMUXIP:/storage/emulated/0/DCIM/Camera"
  #
  $1 export TERMUXTRAMP="/scp:${TERMUXUSER}@${TERMUXIP}#8022:"
  $1 export TERMUXTRAMPWP="$TERMUXTRAMP/storage/emulated/0/Android/media/com.whatsapp/Whatsapp"
  $1 export TERMUXTRAMPWPIMAGES="$TERMUXTRAMPWP/Media/WhatsApp Images"
  $1 export TERMUXTRAMPWPVIDEO="$TERMUXTRAMPWP/Media/WhatsApp Video"
  $1 export TERMUXTRAMPCAMERA="$TERMUXTRAMP/storage/emulated/0/DCIM/Camera"
}
#exporttermuxvars
# (find-zsh "exporttermuxvars echo")


# «video-duration»  (to ".video-duration")
# (find-angg "bin/extract-frame")
# (find-es "ffmpeg" "video-duration")
video-duration () {
  ffprobe -v error -select_streams v:0 -show_entries stream=duration \
    -of default=noprint_wrappers=1:nokey=1 $1
}
# Arguments are: infile position outfile
extract-frame-ipo () { ffmpeg -loglevel error -y -ss $2 -i $1 -frames:v 1 $3 }
extract-frame-io  () { extract-frame-ipo $1 $[$(video-duration $1)/2] $2 }


edev () { mpv https://live0.emacsconf.org/dev.webm }
egen () { mpv https://live0.emacsconf.org/gen.webm }



# Keep this at the end.
# (find-es "zsh" "zshrc-hash-bang-eval")
eval $1

#  Local Variables:
#  coding:               raw-text-unix
#  ee-anchor-format:     "«%s»"
#  End: