summaryrefslogtreecommitdiff
path: root/pbs-plumb-shlib
diff options
context:
space:
mode:
Diffstat (limited to 'pbs-plumb-shlib')
-rw-r--r--pbs-plumb-shlib84
1 files changed, 84 insertions, 0 deletions
diff --git a/pbs-plumb-shlib b/pbs-plumb-shlib
new file mode 100644
index 0000000..c51ddd0
--- /dev/null
+++ b/pbs-plumb-shlib
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+. libremessages
+
+# "Primitive" git functions ##########################################
+
+in_git() {
+ git rev-parse --git-dir &>/dev/null
+}
+
+gitdir() {
+ git rev-parse --git-dir
+}
+
+gitroot() {
+ git rev-parse --show-toplevel
+}
+
+have_file() {
+ local file=$1
+ if in_git; then
+ if [[ -f "$(gitroot)/$file" ]]; then
+ return 0;
+ fi
+ fi
+ return 1
+}
+
+# Deal with being in a PBS package repository ########################
+
+in_pbs-package() {
+ have_file .pbs-package
+}
+
+ensure_in_pbs-package() {
+ if ! in_pbs-package; then
+ error "Not in a PBS package directory"
+ exit 1
+ fi
+}
+
+pbs-package-root() {
+ ensure_in_pbs-package
+ gitroot
+}
+
+cdto_pbs-package-root() {
+ ensure_in_pbs-package
+ cd "$(gitroot)"
+}
+
+# Deal with being in a PBS repository ################################
+
+in_pbs() (
+ if in_pbs-package; then
+ cd "$(pbs-package-root)/.."
+ fi
+ have_file .pbs-root
+)
+
+ensure_in_pbs() {
+ if ! in_pbs; then
+ error "Not in a PBS directory"
+ exit 1
+ fi
+}
+
+pbs-root() {
+ ensure_in_pbs
+ (
+ if in_pbs-package; then
+ cd "$(pbs-package-root)/.."
+ fi
+ gitroot
+ )
+}
+
+cdto_pbs-root() {
+ ensure_in_pbs
+ if in_pbs-package; then
+ cd "$(pbs-package-root)/.."
+ fi
+ cd "$(gitroot)"
+}