|
@@ -0,0 +1,135 @@
|
|
|
+#! /bin/bash
|
|
|
+# Wrap apt queries in a common memorable syntax
|
|
|
+#
|
|
|
+# Usage: aptq QUERY PACKAGE|FILE
|
|
|
+#
|
|
|
+# where QUERY is one of
|
|
|
+#
|
|
|
+# installed - is PACKAGE installed?
|
|
|
+# provdes - what files does PACKAGE provide?
|
|
|
+# owns - what pacakge owns FILE?
|
|
|
+#
|
|
|
+
|
|
|
+set -e; #set -u
|
|
|
+
|
|
|
+# Helper functions
|
|
|
+PROG=`basename "$0" | tr -d '\n'`
|
|
|
+
|
|
|
+function info() { echo `date +%c` ${PROG}\: info: "$@" 1>&2; }
|
|
|
+function warn() { echo `date +%c` ${PROG}\: warning: "$@" 1>&2; }
|
|
|
+function error() { echo `date +%c` ${PROG}\: error: "$@" 1>&2; }
|
|
|
+function debug() { [[ -v DEBUG ]] && echo `date +%c` ${PROG}\: debug: "$@" 1>&2 || true ; }
|
|
|
+function die() { echo `date +%c` ${PROG}\: fatal: "$@" 1>&2 && exit 1; }
|
|
|
+
|
|
|
+
|
|
|
+function usage() {
|
|
|
+ debug "in ${FUNCNAME[0]}"
|
|
|
+
|
|
|
+ if [[ "$#" -gt 0 ]]; then
|
|
|
+ warn $@
|
|
|
+ fi
|
|
|
+
|
|
|
+ cat <<END 1>&2
|
|
|
+Usage: PROG [options] [args]
|
|
|
+
|
|
|
+ arguments
|
|
|
+ arg1 describe arg1
|
|
|
+
|
|
|
+ options
|
|
|
+
|
|
|
+ Group 1
|
|
|
+
|
|
|
+ -a|--abc what does --abc do?
|
|
|
+
|
|
|
+ Other
|
|
|
+
|
|
|
+ -d|--debug debug output
|
|
|
+ -h|--help print usage
|
|
|
+ -v|--verbose verbose output
|
|
|
+END
|
|
|
+ exit 1
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+query=""
|
|
|
+
|
|
|
+while [ ! -z "$1" ];do
|
|
|
+ case "$1" in
|
|
|
+ -h|--help)
|
|
|
+ usage
|
|
|
+ ;;
|
|
|
+ # -f|--fetch)
|
|
|
+ # fetch="true"
|
|
|
+ # ;;
|
|
|
+ # -s|--sleep)
|
|
|
+ # status="true"
|
|
|
+ # ;;
|
|
|
+ installed)
|
|
|
+ debug instlled
|
|
|
+ query="installed"
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+ owns)
|
|
|
+ debug instlled
|
|
|
+ query="owns"
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+ provides)
|
|
|
+ debug instlled
|
|
|
+ query="provides"
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+
|
|
|
+ *)
|
|
|
+ if [[ "$1" =~ ^- ]]; then
|
|
|
+ echo unknown flag $1
|
|
|
+ usage
|
|
|
+ else
|
|
|
+ break
|
|
|
+ fi
|
|
|
+ esac
|
|
|
+shift
|
|
|
+done
|
|
|
+
|
|
|
+if [ "$query" == "" ]; then
|
|
|
+ warn "no known query given"
|
|
|
+ usage
|
|
|
+fi
|
|
|
+
|
|
|
+debug query $query
|
|
|
+debug args are $*
|
|
|
+exit 0
|
|
|
+
|
|
|
+ARGC=$#
|
|
|
+
|
|
|
+if [ "$ARGC" == "0" ]; then
|
|
|
+ set -- `pwd` "$@" # add pwd if no args
|
|
|
+fi
|
|
|
+
|
|
|
+for i in $* ; do
|
|
|
+
|
|
|
+ if [ "$i" == "-f" ]; then
|
|
|
+ fetch=true
|
|
|
+ continue
|
|
|
+ fi
|
|
|
+
|
|
|
+ if [ "$i" == "-s" ]; then
|
|
|
+ status=true
|
|
|
+ continue
|
|
|
+ fi
|
|
|
+
|
|
|
+ if [ "$fetch" == "true" ]; then
|
|
|
+ git fetch
|
|
|
+ fi
|
|
|
+
|
|
|
+ \pushd $i > /dev/null;
|
|
|
+ echo $i;
|
|
|
+
|
|
|
+ if [ "$status" == "true" ]; then
|
|
|
+ git status -s
|
|
|
+ else
|
|
|
+ git branch -vv;
|
|
|
+ fi
|
|
|
+ echo;
|
|
|
+ \popd > /dev/null;
|
|
|
+done
|