config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 41bee3b35f684e02140f99c3236f62a431166bf4
parent 66a7b3e61a9843ee50d783620223ff917cd33928
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Fri, 12 Feb 2021 20:46:05 -0800

Cleanup and revise shell functions

- Add and remove various modules
- Allow `include' to handle multiple modules
- Load only modules listed in the `SHELL_MODULES' environment variable
- Remove redundent compound around veronica function
- Remove the practically unused `__progname' variable
- Remove unused `lsm' function
- Remove unused `vol' function
- Translate all aliases to functions

Diffstat:
Mmodules/profile/.profile | 1+
Amodules/shell/.config/shell/aliases | 15+++++++++++++++
Mmodules/shell/.config/shell/cd | 2+-
Amodules/shell/.config/shell/etc | 14++++++++++++++
Amodules/shell/.config/shell/fs | 10++++++++++
Amodules/shell/.config/shell/gopher | 4++++
Amodules/shell/.config/shell/hist | 7+++++++
Dmodules/shell/.config/shell/history | 8--------
Mmodules/shell/.config/shell/main | 68++++++++++++--------------------------------------------------------
Mmodules/shell/.config/shell/mpc | 21++++++++++-----------
Mmodules/shell/.config/shell/openbsd | 6+++---
Amodules/shell/.config/shell/sys | 4++++
Mmodules/shell/.config/shell/xorg | 12+++++-------
13 files changed, 86 insertions(+), 86 deletions(-)

diff --git a/modules/profile/.profile b/modules/profile/.profile @@ -33,6 +33,7 @@ export DATE_FMT="%Y.%m.%d" export TIME_FMT="%H.%M" export DATETIME_FMT="$DATE_FMT $TIME_FMT" export MAKEFLAGS="CC=${CC}" +export SHELL_MODULES="aliases cd etc fs hist mpc openbsd private sys xorg" # cache frequently used files cat `which $BROWSER $EDITOR $PAGER $SHELL $TERMINAL $CC tmux git` >/dev/null diff --git a/modules/shell/.config/shell/aliases b/modules/shell/.config/shell/aliases @@ -0,0 +1,15 @@ +# simple shell functions + +ap() { apropos $* ;} +date() { command date ${*:-'+%F %T %z'} ;} +grep() { egrep $* ;} +man() { command man $* ;} +mtime() { stat -t'$DATETIME_FMT' -f%Sm%t%N $* ;} +pkill() { command pkill -x $* ;} +sed() { command sed -E $* ;} + +f() { $EDITOR $* ;} +g() { git $* ;} +l() { $PAGER $* ;} +t() { tmux $* ;} +d() { doas $* ;} diff --git a/modules/shell/.config/shell/cd b/modules/shell/.config/shell/cd @@ -1,4 +1,4 @@ -# cd builtin shell aliases and functions +# cd shell functions # record directories visited into the PWDLOG file. cd() { builtin cd "$@" && echo $PWD >> $PWDLOG ;} diff --git a/modules/shell/.config/shell/etc b/modules/shell/.config/shell/etc @@ -0,0 +1,14 @@ +# shell functions + +doin() { (builtin cd ${1:?No directory} && shift && eval $@) ;} +fed() { doin "$FEED_DIR" feed $@ ;} +hfmt() { w3m -T text/html -O ASCII -dump $* ;} + +tp() { + case $* in + y) export ALL_PROXY="socks://localhost:9050" # curl + export HTTP_PROXY=$ALL_PROXY;; # vimb + n) unset ALL_PROXY; unset HTTP_PROXY;; + *) printf '%s: arguments must be 'y' or 'n'\n' $__progname;; + esac +} diff --git a/modules/shell/.config/shell/fs b/modules/shell/.config/shell/fs @@ -0,0 +1,10 @@ +# filesystem shell functions + +ls() { command ls -1 $* ;} +lsc() { ls $* | rs ;} +sfind() { find . -maxdepth 1 $* ;} + +fp() { + local bin=`which $* 2>/dev/null` + f ${bin:?No path specified} +} diff --git a/modules/shell/.config/shell/gopher b/modules/shell/.config/shell/gopher @@ -0,0 +1,4 @@ +# gopher shell functions + +veronica() (local IFS='?' && gawk "/v2/vs/?${*:?No query}" floodgap.com) +vs() { veronica $* ;} diff --git a/modules/shell/.config/shell/hist b/modules/shell/.config/shell/hist @@ -0,0 +1,7 @@ +# history shell functions + +unalias r 2>/dev/null + +k() { fc -s ;} +r() { fc -s "$*" ;} +hs() { fc -nl 0 | egrep $* ;} diff --git a/modules/shell/.config/shell/history b/modules/shell/.config/shell/history @@ -1,8 +0,0 @@ -# shell history shell aliases and functions - -alias k="fc -s" - -unalias r 2>/dev/null -r() { fc -s "$*" ;} - -hs() { fc -nl 0 | egrep $* ;} diff --git a/modules/shell/.config/shell/main b/modules/shell/.config/shell/main @@ -1,62 +1,18 @@ -# shell aliases and functions +# shell module hub -__progname=`basename -- $0` - -# include shell module. include() { - local include="${SHELL_MODULE_DIR:?unset}/$1" - test -f "$include" || { - printf "%s: include: '%s': File nonexistent.\n" \ - $__progname $include 1>&2; - return 1 - } - . "$include" + for module in $* + do + local include="${SHELL_MODULE_DIR:?unset}/$module" + test -f "$include" || { + printf 'include: '%s': No such file or directory.\n' \ + $include 1>&2; + continue + } + . "$include" + done } -alias doas="doas -- " - -alias ap="apropos" -alias dsu="doas su" -alias grep="egrep" -alias ls="ls -1" -alias man="man " -alias mtime="stat -t'$DATETIME_FMT' -f%Sm%t%N" -alias pkill="pkill -x" -alias sed="sed -E" - -alias f="$EDITOR" -alias g="git" -alias l="$PAGER" -alias t="tmux" -alias d="doas" - -date() { command date ${*:-'+%F %T %z'} ;} -doin() { (builtin cd ${1:?No directory} && shift && eval $@) ;} -fed() { doin "$FEED_DIR" feed $@ ;} -fp() { - local bin=`which $@ 2>/dev/null` - f ${bin:?No path specified} -} -hfmt() { w3m -T text/html -O ASCII -dump $* ;} -lsc() { ls $* | rs ;} -lsm() { ls ${SHELL_MODULE_DIR:?unset} ;} -tp() { - case $* in - y) export ALL_PROXY="socks://localhost:9050" # curl - export HTTP_PROXY=$ALL_PROXY;; # vimb - n) unset ALL_PROXY; unset HTTP_PROXY;; - *) printf '%s: arguments must be 'y' or 'n'\n' $__progname;; - esac -} reload() { . ~/.profile && include main ;} -sfind() { find . -maxdepth 1 $* ;} -veronica() { local IFS='?' && gawk "/v2/vs/?${*:?No query}" floodgap.com ;} -vol() { sndioctl output.level=$@ ;} -vs() { veronica $* ;} -include cd -include history -include mpc -include openbsd -include private 2>/dev/null -include xorg +include $SHELL_MODULES diff --git a/modules/shell/.config/shell/mpc b/modules/shell/.config/shell/mpc @@ -1,13 +1,12 @@ -# mpc aliases and functions - -alias m="mpc" -alias mP="m searchplay any" -alias ma="m add" -alias mi="m play" -alias mj="m next" -alias ml="m playlist" -alias mo="m prev" -alias ms="m search any" -alias mt="m toggle" +# mpc shell functions +m() { mpc ;} +mP() { m searchplay any $* ;} +ma() { m add $* ;} +mi() { m play $* ;} +mj() { m next $* ;} +ml() { m playlist $* ;} +mo() { m prev $* ;} +ms() { m search any $* ;} +mt() { m toggle $* ;} mf() { m listall | egrep $* ;} diff --git a/modules/shell/.config/shell/openbsd b/modules/shell/.config/shell/openbsd @@ -1,7 +1,7 @@ -# OpenBSD specific shell aliases and functions +# OpenBSD shell functions -alias ncpu="sysctl -n hw.ncpufound" -alias load="sysctl -n vm.loadavg" +ncpu() { sysctl -n hw.ncpufound $* ;} +load() { sysctl -n vm.loadavg $* ;} # package management pa() { doas pkg_add -xV $* ;} diff --git a/modules/shell/.config/shell/sys b/modules/shell/.config/shell/sys @@ -0,0 +1,4 @@ +# system management shell functions + +doas() { command doas -- $* ;} +dsu() { doas su $* ;} diff --git a/modules/shell/.config/shell/xorg b/modules/shell/.config/shell/xorg @@ -1,8 +1,6 @@ -# xorg shell aliases and functions +# xorg shell functions -# clipboard -alias dump="grab -out" -alias grab="xclip -selection clipboard" - -alias pdf="zathura" -alias x="startx" +grab() { xclip -selection clipboard $* ;} +dump() { grab -out $* ;} +pdf() { zathura $* ;} +x() { startx $* ;}