aboutsummaryrefslogtreecommitdiff
path: root/sbostuff.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sbostuff.sh')
-rw-r--r--sbostuff.sh102
1 files changed, 102 insertions, 0 deletions
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 <<EOF
+visl - edit the .SlackBuild, .info, README, and slack-desc in the
+ current directory.
+
+Usage: visl <opts>
+
+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, <opts> 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 <<EOF
+cdsb - change directory to a SlackBuild.
+
+Usage: cdsb <build>
+
+With no <build> argument, changes to the root of the SBo tree.
+
+<build> 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
+}
+