From c3238e690a1f3254d282623e047f0124206de9b9 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 10 Jun 2020 19:42:04 -0400 Subject: cleanup, wip for eventual release --- sbostuff.sh | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 sbostuff.sh (limited to 'sbostuff.sh') diff --git a/sbostuff.sh b/sbostuff.sh new file mode 100644 index 0000000..bd40a24 --- /dev/null +++ b/sbostuff.sh @@ -0,0 +1,102 @@ +# sbostuff.sh + +# bash functions for sbostuff. And I do mean *bash*: I don't know a +# completely portable way to write this stuff, and I don't use other +# shells. Patches accepted, if you're really motivated to make this +# work in your favorite shell. + +# Source this file from your ~/.bashrc or similar: +# source /path/to/sbostuff/functions.sh +# ...or place this file in /etc/profile.d/ with +x permission. + +if [ -e ~/.sbostuff.cfg ]; then + source ~/.sbostuff.cfg +else + echo "sbostuff: No ~/.sbostuff.cfg, please create one." +fi + +_run_editor() { + local editor + if [ -n "$VISUAL" ]; then + editor="$VISUAL" + elif [ -n "$EDITOR" ]; then + editor="$EDITOR" + else + editor="vim" + fi + eval "$editor" $@ +} + +visl() { + local file + local editor_opts + + case "$1" in + -h|--help) + cat < + +The editor used is controlled by environment variables. If VISUAL +is set, it's used as the editor. Otherwise, if EDITOR is set, it's +used. If neither are set, the default is "vim". + +If given, are passed to the editor as options. +EOF + return 0 ;; + *) editor_opts="$@" ;; + esac + + file="$( basename "$( pwd )" )".SlackBuild + [ ! -e "$file" ] && file="*.SlackBuild" + _run_editor $editor_opts "$file" "${file/SlackBuild/info}" README slack-desc "$@" +} + +_cdsbexp() { + /bin/ls -d1 "$@" 2>/dev/null | grep -v /local/ | head -1 +} + +cdsb() { + # FIXME: get from config file + local dir + local oldshopt + + case "$1" in + -h|--help) + cat < + +With no argument, changes to the root of the SBo tree. + + may be a complete build name (with or without a category), or a +partial name, which will be matched case-insensitively. +EOF + return 0 ;; + --) shift ;; + -*) echo "cdsb: unknown option $1" ; return 1 ;; + esac + + # temporarily do case-insensitive globbing + oldshopt="$( shopt -p nocaseglob )" + shopt -s nocaseglob + + if [ -d $SBO_GITROOT/$1 ]; then + # category/prgnam (exact) + cd $SBO_GITROOT/$1 + elif [ -d "$( _cdsbexp $SBO_GITROOT/*/$1)" ]; then + # prgnam without category (exact) + cd "$( _cdsbexp $SBO_GITROOT/*/$1)" + else + echo "cdsb: no exact match, guessing dir" 1>&2 + dir="$( _cdsbexp $SBO_GITROOT/*/$1* )" + [ -z "$dir" ] && dir="$( _cdsbexp $SBO_GITROOT/*/*$1* )" + [ -n "$dir" ] && cd "$dir" || echo "cdsb: no match" 1>&2 + fi + + eval $oldshopt +} + -- cgit v1.2.3