Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- tab-width: 4 -*- ;; Emacs
- # vi: set tabstop=8 :: Vi/ViM
- #
- # zsh_profile for mailtime
- # Author: Devin Teske <dteske@freebsd.org>
- # Last Change: 2020 May 19
- ############################################################ GLOBALS
- #
- # Global exit status variables
- #
- export SUCCESS=0
- export FAILURE=1
- #
- # Are we running interactively?
- #
- interactive=
- case "$-" in
- *i*) interactive=1
- esac
- #
- # Is filename globbing enabled?
- #
- if [ "$ZSH_NAME" ]; then
- glob=
- setopt shwordsplit
- else
- glob=1
- case "$SHELLOPTS" in noglob|*:noglob:*|*:noglob) glob= ;; esac
- fi
- #
- # OS Specifics
- # NB: Requires uname(1) -- from base system
- #
- : ${UNAME_s:=$(uname -s)}
- #
- # Fix lolcat to work properly in local XTerm
- #
- [ "$TERM" != "${TERM#xterm}" -a ! "$SSH_CLIENT" ] && stty tab0
- #
- # bash(1) builtin's we should pass to $LOLCAT [lolcat]
- #
- LOL_BUILTINS='cd dirs echo help popd printf pushd pwd shopt times type'
- _LOL_BUILTINS=
- [ "$glob" ] && set -f
- for _prog in $LOL_BUILTINS; do
- _LOL_BUILTINS="$_LOL_BUILTINS|$_prog"
- done
- unset _prog
- _LOL_BUILTINS="${_LOL_BUILTINS#|}"
- [ "$glob" ] && set +f
- #
- # External programs we should NOT pass to $LOLCAT [lolcat]
- #
- NOLOL_PROGS='
- adduser arc
- bashbug bc bitchx bsdconfig bsdinstall
- condy cscope csh cvsbug
- dd dialog dpv
- edit edquota ee emacs* env etcupdate ex
- freebsd-update fsdb *ftp fvwm-bug
- *gdb*
- *hx
- iftop irssi
- *key *keys
- lldb *login lolcat ls
- Mail mail* *man* mping mysql
- nano ngctl nvi
- perlbug perlthanks pico pppctl psql
- rcp *run
- sade *scp screen shgid sr srvi *ssh* su sudo* sysinstall systat
- talk tcsh *telnet tmux tzsetup
- vi *view vigr *vim* vipw visudo
- watch
- zsh
- ' # NOLOL_PROGS
- _NOLOL_PROGS=
- [ "$glob" ] && set -f
- for _prog in $NOLOL_PROGS; do
- _NOLOL_PROGS="$_NOLOL_PROGS|$_prog"
- done
- unset _prog
- _NOLOL_PROGS="${_NOLOL_PROGS#|}"
- [ "$glob" ] && set +f
- #
- # Commands we should pass to $LOLCAT [lolcat]
- #
- LOL_CMDS='
- # One case pattern per-line; no inline comments
- # NB: Whitespace needs to be escaped or quoted
- # NB: Patterns implicitly allow trailing args
- # Non-interactive commands
- "*bash -c"
- "*bash -xc"
- "*bash "*" -c"
- "python -c"
- "python "*" -c"
- "R [a-zA-Z]*"
- "sh -c"
- "sh -xc"
- "sh "*" -c"
- "zsh -c"
- "zsh -xc"
- "zsh "*" -c"
- # FreeBSD commands
- "wpa_cli [a-z]*"
- # FreeBSD pkg(8) commands
- "pkg annotate -y"
- "pkg annotate "*" -y"
- "pkg annotate --yes"
- "pkg annotate "*" --yes"
- "pkg autoremove -y"
- "pkg autoremove "*" -y"
- "pkg autoremove --yes"
- "pkg autoremove "*" --yes"
- "pkg check -y"
- "pkg check "*" -y"
- "pkg check --yes"
- "pkg check "*" --yes"
- "pkg clean -y"
- "pkg clean "*" -y"
- "pkg clean --yes"
- "pkg clean "*" --yes"
- "pkg delete -y"
- "pkg delete "*" -y"
- "pkg delete --yes"
- "pkg delete "*" --yes"
- "pkg fetch -y"
- "pkg fetch "*" -y"
- "pkg fetch --yes"
- "pkg fetch "*" --yes"
- "pkg install -y"
- "pkg install "*" -y"
- "pkg install --yes"
- "pkg install "*" --yes"
- "pkg lock -y"
- "pkg lock "*" -y"
- "pkg lock --yes"
- "pkg lock "*" --yes"
- "pkg remove -y"
- "pkg remove "*" -y"
- "pkg remove --yes"
- "pkg remove "*" --yes"
- "pkg unlock -y"
- "pkg unlock "*" -y"
- "pkg unlock --yes"
- "pkg unlock "*" --yes"
- "pkg upgrade -y"
- "pkg upgrade "*" -y"
- "pkg upgrade --yes"
- "pkg upgrade "*" --yes"
- # VCS commands
- "cvs ci -m"
- "cvs ci "*" -m"
- "cvs commit -m"
- "cvs commit "*" -m"
- "git commit -m"
- "git commit "*" -m"
- "git commit --message"
- "git commit "*" --message"
- "git commit --no-edit"
- "git commit "*" --no-edit"
- "git revert --no-edit"
- "git revert "*" --no-edit"
- "p4 branch -"[dio]
- "p4 branch "*" -"[dio]
- "p4 change -"[dio]
- "p4 change "*" -"[dio]
- "p4 changelist -"[dio]
- "p4 changelist "*" -"[dio]
- "p4 client -"[dio]
- "p4 client "*" -"[dio]
- "p4 depot -"[dio]
- "p4 depot "*" -"[dio]
- "p4 job -"[dio]
- "p4 job "*" -"[dio]
- "p4 label -"[dio]
- "p4 label "*" -"[dio]
- "p4 protect -"[io]
- "p4 protect "*" -"[io]
- "p4 resolve -a"[mty]
- "p4 resolve "*" -a"[mty]
- "p4 stream -"[dio]
- "p4 stream "*" -"[dio]
- "p4 submit -"[di]
- "p4 submit "*" -"[di]
- "p4 user -"[dio]
- "p4 user "*" -"[dio]
- "p4 workspace -"[dio]
- "p4 workspace "*" -"[dio]
- "svn ci -m"
- "svn ci "*" -m"
- "svn ci --message"
- "svn ci "*" --message"
- "svn ci --non-interactive"
- "svn ci "*" --non-interactive"
- "svn commit -m"
- "svn commit "*" -m"
- "svn commit --message"
- "svn commit "*" --message"
- "svn commit --non-interactive"
- "svn ci "*" --non-interactive"
- "svnlite ci -m"
- "svnlite ci "*" -m"
- "svnlite ci --message"
- "svnlite ci "*" --message"
- "svnlite ci --non-interactive"
- "svnlite ci "*" --non-interactive"
- "svnlite commit -m"
- "svnlite commit "*" -m"
- "svnlite commit --message"
- "svnlite commit "*" --message"
- "svnlite commit --non-interactive"
- "svnlite ci "*" --non-interactive"
- ' # LOL_CMDS
- _LOL_CMDS=$( echo "$LOL_CMDS" |
- while read -r _cmd; do
- [ "${_cmd:-x}" = "${_cmd#\#}" ] || continue
- echo -n "|$_cmd|$_cmd\[\$IFS]*"
- done
- )
- _LOL_CMDS="${_LOL_CMDS#|}"
- #
- # Commands we should NOT pass to $LOLCAT [lolcat]
- #
- NOLOL_CMDS='
- # One case pattern per-line; no inline comments
- # NB: Whitespace needs to be escaped or quoted
- # NB: Patterns implicitly allow trailing args
- # Commands containing pipe
- *"|"*
- # Interactive commands
- *"bash"
- "python"
- "R"
- "sh"
- "zsh"
- # General commands that launch $EDITOR or behave interactively
- "crontab -e"
- "crontab "*" -e"
- "sdiff -o"
- "sdiff "*" -o"
- # FreeBSD specific commands that launch $EDITOR or behave interactively
- "bsdlabel -e"
- "camcontrol modepage "*" -e"
- "disklabel -e"
- "gbde init "*" -i"
- "gvinum create"
- "make config"
- "make import"
- "wpa_cli"
- # FreeBSD pkg(8) commands that either prompt or show progress
- "pkg annotate"
- "pkg autoremove"
- "pkg check"
- "pkg clean"
- "pkg delete"
- "pkg fetch"
- "pkg install"
- "pkg lock"
- "pkg remove"
- "pkg shell"
- "pkg unlock"
- "pkg upgrade"
- # VCS commands that launch $EDITOR or behave interactively
- "cvs ci"
- "cvs commit"
- "git commit"
- "git help"
- "git rebase -i"
- "git rebase "*" -i"
- "git rebase --interactive"
- "git rebase "*" --interactive"
- "git revert"
- "p4 attribute -i"
- "p4 attribute "*" -i"
- "p4 branch"
- "p4 change"
- "p4 changelist"
- "p4 client"
- "p4 depot"
- "p4 job"
- "p4 label"
- "p4 login"
- "p4 passwd"
- "p4 protect"
- "p4 resolve"
- "p4 stream"
- "p4 submit"
- "p4 user"
- "p4 workspace"
- "svn ci"
- "svn commit"
- "svnlite ci"
- "svnlite commit"
- # Other commands that behave interactively
- "make chroot_shell"
- "make "*" chroot_shell"
- "make distclean"
- "make "*" distclean"
- "make remove_chroot"
- "make "*" remove_chroot"
- ' # NOLOL_CMDS
- _NOLOL_CMDS=$( echo "$NOLOL_CMDS" |
- while read -r _cmd; do
- [ "${_cmd:-x}" = "${_cmd#\#}" ] || continue
- echo -n "|$_cmd|$_cmd\[\$IFS]*"
- done
- )
- _NOLOL_CMDS="${_NOLOL_CMDS#|}"
- ############################################################ FUNCTIONS
- unalias quietly 2> /dev/null
- quietly() { "$@" > /dev/null 2>&1; }
- quietly unalias have
- have() { type "$@" > /dev/null 2>&1; }
- # lolexec [$command [$args ...]]
- #
- # Create a wrapper function for $command, sending output to `lolcat' (or
- # `cowsay') transparently. To make this execute for all commands, automatically
- # sending all output to lolcat, make this function the DEBUG trap.
- #
- # For example:
- # trap lolexec DEBUG
- #
- # When trapped as the DEBUG routine in bash, any/all command lines that...
- # + Do NOT contain the pipe character
- # + Do NOT start with an exclamation point by-itself (e.g., "! top")
- # ... will have their output sent to lolcat.
- #
- # NB: Requires awk(1) -- from base system
- #
- if [ "$ZSH_NAME" ]; then
- preexec() { lolexec "$1"; }
- precmd() { trap - DEBUG; }
- type_t() {
- case "$( builtin type "$@" 2> /dev/null )" in
- *" is a shell function") builtin echo function ;;
- *" is an alias for "*) builtin echo alias ;;
- *" is a shell builtin") builtin echo builtin ;;
- *" is a reserved word") builtin echo keyword ;;
- *" is /"*) builtin echo file ;;
- *) builtin echo unknown
- esac
- }
- else
- type_t() { builtin type -t "$@" 2> /dev/null; }
- LOLEXEC='[ "$( trap -p DEBUG )" ]'
- LOLEXEC="$LOLEXEC || trap \"trap - DEBUG; lolexec\" DEBUG"
- fi
- alias -- +lol='trap - DEBUG; +lolcat'
- alias -- -lol='-lolcat'
- quietly unalias -lolcat
- -lolcat()
- {
- if [ $# -lt 1 -o ! "$*" ]; then
- unset PROMPT_COMMAND
- return $SUCCESS
- fi
- local cmd
- for cmd in "$@"; do
- _NOLOL_CMDS="$_NOLOL_CMDS|$cmd|$cmd\[\$IFS]*"
- done
- }
- case "$UNAME_s" in
- Darwin) -lol ls ;;
- esac
- quietly unalias +lolcat
- +lolcat()
- {
- PROMPT_COMMAND="$LOLEXEC"
- LOLCAT="${*:-$LOLCAT}"
- }
- quietly unalias lolexec
- lolexec()
- {
- builtin [ "$ZSH_NAME" ] && builtin local FUNCNAME="$funcstack[1]"
- builtin export OLDPWD # Required for `cd -' and `pushd -'
- builtin local _lolcat="$LOLCAT" _lc=
- builtin local _prog _register=1
- builtin local cmd fprog prefix=_${FUNCNAME}_ prog=
- case "$_LOLFUNC" in
- ""|$FUNCNAME) builtin : fall through ;;
- *)
- builtin unset -f $_LOLFUNC 2> /dev/null
- type_t $prefix$_LOLFUNC > /dev/null 2>&1 &&
- builtin eval "$( builtin type $prefix$_LOLFUNC |
- builtin command awk -v prefix=$prefix '
- NR == 2 { sub("^" prefix, ""); print }
- NR > 2
- ' )"
- esac
- _LOLFUNC=
- case "$_lolcat" in
- "") builtin [ $# -eq 0 ] || builtin [ "$ZSH_NAME" ] || "$@"
- builtin return ;;
- *lolcat) _lc=1 ;;
- esac
- if builtin [ "$ZSH_NAME" ]; then
- cmd="$1"
- else
- case "$#" in
- 0) cmd=$( history 1 ) || builtin return
- cmd="${cmd#*[0-9] }" ;;
- *) cmd="$*"
- esac
- fi
- builtin [ "$cmd" ] || builtin return
- builtin export LOL_CMD="$cmd"
- builtin eval "case \"\$cmd\" in
- $_LOL_CMDS) builtin : fall through ;;
- $_NOLOL_CMDS)
- builtin [ \$# -eq 0 ] || builtin [ \"\$ZSH_NAME\" ] || \"\$@\"
- builtin return
- esac"
- for prog in $cmd; do
- builtin [ "${prog:-x}" = "${prog#*=}" ] || builtin continue
- builtin [ "$prog" = "!" ] || builtin break
- builtin [ $# -eq 0 ] || builtin [ "$ZSH_NAME" ] || "$@"
- builtin return
- done
- case "$prog" in
- ""|*[^[:alnum:]_]*)
- builtin [ $# -eq 0 ] || builtin [ "$ZSH_NAME" ] || "$@"
- builtin return
- esac
- _prog=$prog
- while builtin [ "$( type_t $prog 2> /dev/null )" = alias ]; do
- fprog=$( builtin type $prog )
- fprog="${fprog#*\`}"
- fprog="${fprog%\'}"
- for prog in $fprog; do
- builtin [ "$prog" = "!" ] || builtin break
- builtin [ $# -eq 0 ] || builtin [ "$ZSH_NAME" ] || "$@"
- builtin return
- done
- builtin [ "$prog" = "$_prog" ] && builtin break # infinite loop
- _prog=$prog
- done
- if builtin [ "$prog" = "$FUNCNAME" -o ! "${prog#type_t}" ]; then
- builtin [ $# -eq 0 ] || builtin [ "$ZSH_NAME" ] || "$@"
- builtin return
- fi
- case "$( type_t $prog 2> /dev/null )" in
- alias|file) # blacklist
- builtin eval "case \"\$prog\" in
- $_NOLOL_PROGS)
- builtin [ \$# -eq 0 ] || builtin [ \"\$ZSH_NAME\" ] ||
- \"\$@\"
- builtin return
- esac"
- fprog="builtin command $prog"
- _LOLFUNC=$prog
- builtin [ "$_lc" ] && case "$prog" in
- *less|*more) # [bz,lz,xz,z]less [z]more
- builtin eval "function $prog()
- {
- $fprog \"\$@\" |& $LOLCAT -f |
- builtin command less -R
- }"
- _register= ;;
- ping*) # l2ping ping ping6
- _lolcat="$_lolcat -a" ;;
- tail) # check for `-f' or `-F'
- case "$cmd" in
- *[$IFS]-[fF]|*[$IFS]-[fF][$IFS]*) _lolcat="$_lolcat -a"
- esac ;;
- esac
- ;;
- builtin|keyword) # whitelist
- builtin eval "case \"\$prog\" in
- $_LOL_BUILTINS) builtin : fall through ;;
- *)
- builtin [ \$# -eq 0 ] || builtin [ \"\$ZSH_NAME\" ] ||
- \"\$@\"
- builtin return
- esac"
- fprog="builtin $prog"
- _LOLFUNC=$prog ;;
- function) # overlay
- builtin [ "$_lc" ] && case "$prog" in
- tlog|tm|taal|tael) # wrappers to `tail -F'
- _lolcat="$_lolcat -a" ;;
- esac
- builtin eval "$prefix$( builtin type $prog |
- builtin command awk 'NR>1' )"
- fprog="$prefix$prog"
- _LOLFUNC=$prog ;;
- *) # unknown
- builtin [ $# -eq 0 ] || builtin [ "$ZSH_NAME" ] || "$@"
- builtin return
- esac
- builtin [ "$LOLDEBUG" ] && builtin echo \
- "$FUNCNAME: prog=[$prog] fprog=[$fprog] cmd=[$cmd]" >&2
- builtin [ "$_register" ] && builtin eval "function $prog()
- {
- exec 3>&1
- local cwd=\"\${D0:-\${DIRSTACK[0]:-\$( builtin pwd )}}\"
- builtin local meta=\"\$( exec 4>&1; (
- $fprog \"\$@\"
- builtin echo \"\$?:\$( builtin pwd )\" >&4
- ) |& $_lolcat >&3 )\"
- builtin local ret=\"\${meta%%:*}\" chdir=\"\${meta#*:}\"
- case \"$prog\" in
- dirstack_wrap) builtin \"\$@\" ;;
- pushd|popd) builtin $prog \"\$@\" ;;
- *) builtin [ \"\$cwd\" != \"\$chdir\" ] &&
- builtin cd \"\$chdir\"
- esac > /dev/null 2>&1
- builtin type dirstack2d > /dev/null 2>&1 &&
- builtin [ \"\$cwd\" != \"\$chdir\" ] && dirstack2d
- builtin return \$ret
- }"
- builtin [ $# -eq 0 ] || builtin [ "$ZSH_NAME" ] || "$@"
- }
- ############################################################ SHELL BEHAVIOR
- #
- # lolcat integration
- #
- [ "$interactive" ] && PROMPT_COMMAND="$LOLEXEC"
- have lolcat && LOLCAT=lolcat
- ################################################################################
- # END
- ################################################################################
Add Comment
Please, Sign In to add comment