# 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 export SBO_GITROOT SBO_NAME SBO_EMAIL SBO_GITBRANCH 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 }