dot

packages and services management
Log | Files | Refs | README

commit c4eb2b80c4ef44afa47c6248cdcb2307e8ea103d
parent e02d90b20a1f3f4079c85a877eac9ac763a5f52d
Author: josuah <mail@josuah.net>
Date:   Tue, 20 Dec 2016 11:59:55 +0000

Using local scoping by default with subshells

Diffstat:
M.local/bin/build | 51++++++++++++++++++++++++---------------------------
M.local/bin/status | 47++++++++++++++++-------------------------------
M.local/bin/www | 21+++++++++++----------
3 files changed, 51 insertions(+), 68 deletions(-)

diff --git a/.local/bin/build b/.local/bin/build @@ -17,9 +17,7 @@ then usage() -{ - local name description - +( printf '%s\n' "\ Usage: ${0##*/} COMMAND PACKAGE @@ -31,38 +29,38 @@ l[inks] Update links from ~${PROGRAMS#$HOME} to ~${LOCAL#$HOME} v[iew] View the list of available packages" exit 0 -} +) view() -{ +( find -L "$LOCAL/share/build" -type f | while IFS='' read -r f do read -r comment description < "$f" printf ' %-12s %s\n' "${f#$LOCAL/share/build/}" "$description" done | sort | more exit 0 -} +) error() -{ +( printf '\033[1;31merror\033[0;1m %-12s\033[m %s\n' "$1" "$2" 1>&2 exit 1 -} +) info() -{ +( printf '\033[1;36minfo\033[0;1m %-12s\033[m %s\n' "$1" "$2" 1>&2 -} +) # # Default build function, to be overriden in the build recipes scripts # build() -{ +( find "$CONFIG/$1" -name '*.diff' -exec patch -N -p 1 -i {} \; for file in "$CONFIG/$1/config.mk" "$CONFIG/$1/config.h" @@ -74,13 +72,13 @@ build() [ -f ./configure ] && ./configure --prefix="$PREFIX" make && make PREFIX="$PREFIX" install clean -} +) compile() -{ - local name="$1" tar="$2" - local PREFIX="$PROGRAMS/$name" script="$LOCAL/share/build/$name" +( + name="$1" tar="$2" + PREFIX="$PROGRAMS/$name" script="$LOCAL/share/build/$name" export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 @@ -94,13 +92,12 @@ compile() cd "$PREFIX" && mkdir -p bin doc etc include lib libexec share man cd src && build "$name" cd "$PREFIX" && rmdir -p ./* 2> /dev/null -} +) download() -{ - local name="$1" tar="$2" - local script="$LOCAL/share/build/$name" +( + name="$1" tar="$2" script="$LOCAL/share/build/$name" [ -d "$PROGRAMS/$name/src" ] && error "$name" "already in $PROGRAMS" [ -f "$script" ] || [ -h "$script" ] || error "$name" "no build script" @@ -120,29 +117,29 @@ download() wget -O - "$tar" | tar -xv"$opt" -f - -C "$PROGRAMS/$name" 1> /dev/null mv "$PROGRAMS/$name/"* "$PROGRAMS/$name/src" -} +) remove() -{ +( info "$1" "removing" rm -rf "$PROGRAMS/$1" -} +) index() -{ - local name="$1" +( + name="$1" info "$name" "updating index in ~${LOCAL#$HOME}" cd "$PROGRAMS/$name" || exit 1 find . -type d ! -path "*/src/*" -exec mkdir -p "$LOCAL/{}" \; find . ! -type d ! -path "*/src/*" -exec ln -sf "$PWD/{}" "$LOCAL/{}" \; -} +) main() -{ +( mkdir -p "$PROGRAMS" case "$1" in @@ -180,7 +177,7 @@ main() info '' "removing broken links from ~${LOCAL#$HOME}" find -L "$LOCAL" -type l -exec rm {} \; -} +) main "$@" diff --git a/.local/bin/status b/.local/bin/status @@ -1,9 +1,4 @@ -# Plain text status line for wherever useful 2016-12-13 -# -# _ |_ _ |_ _ -# _\ | (_| | |_| _\ -# -#_______________________________________________________________________________ +# Plain text status line for wherever useful 2016-12-20 SEPARATOR=' ' @@ -15,9 +10,7 @@ STOP=' ' # Maildir format, just file count in "$MAIL/new" # status_mail() -{ - local mail - +( if [ -d "$MAIL/new" ] then mail="$(find "$MAIL/new" -type f | wc -l)" @@ -26,38 +19,33 @@ status_mail() printf %s "$mail" fi -} +) status_abduco() -{ - local buffers="$(($(abduco | wc -l) - 1))" - +( + buffers="$(($(abduco | wc -l) - 1))" [ "$buffers" -gt 0 ] && printf '[%s]' "$buffers" -} +) status_date() -{ +( date +'%Y-%m-%d %H:%M' -} +) -# -# Now that I understand how load average works, I do not even want to look at -# CPU percentage usage. -# status_cpu() -{ +( read -r latest_1 latest_5 latest_15 trailing < /proc/loadavg printf '%s %s %s' "$latest_1" "$latest_5" "$latest_15" -} +) status_battery() -{ - local battery="$( +( + battery="$( find -L /sys/class/power_supply -maxdepth 2 -name capacity \ 2> /dev/null )" @@ -67,26 +55,23 @@ status_battery() IFS='' read -r battery < "$battery" printf '%d%%' "$battery" fi -} +) main() -{ - local segment - +( printf %s "$START" while [ "$#" -gt 0 ] do segment="$(status_"$1")" printf %s "$segment" - [ "$segment" ] && [ $# -gt 1 ] && printf %s "$SEPARATOR" shift done printf '%s\n' "$STOP" -} +) -[ $# -gt 0 ] main "$@" || main mail abduco cpu battery date +[ $# -gt 0 ] && main "$@" || main mail abduco cpu battery date diff --git a/.local/bin/www b/.local/bin/www @@ -5,8 +5,8 @@ LAYOUT="layout.html" parse() -{ - local item="$1" input="$2" +( + item="$1" input="$2" # print the input up to the next keyword, and shift position in input printf %s "${input%%{{*}" @@ -46,15 +46,15 @@ parse() esac parse "$item" "${input#*\}\}}" -} +) # # HTML list of the current directory content. # list() -{ - local dir="$1" +( + dir="$1" printf '<ul>\n' @@ -66,22 +66,22 @@ list() ) printf '</ul>' -} +) # # HTML line of relative links to first level directory # nav() -{ +( find . -mindepth 1 -maxdepth 1 -type d ! -path '*/.*' | sort | sed -r 's_..(.*)_| <a href="{{ root }}/\1">\1</a>_' -} +) main() -{ +( if [ ! -f layout.html ] then printf '%s: no "%s" file in "%s"\n' "${0##*/}" "$LAYOUT" "$PWD" @@ -93,6 +93,7 @@ main() do parse "${d#./}" "$(cat "$LAYOUT")" > "$d/index.html" done -} +) + main "$@"