aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNæþ'n Lasseter <Næþ'n Lasseter nathan@bytemark.co.uk>2016-08-25 14:22:29 +0100
committerNæþ'n Lasseter <Næþ'n Lasseter nathan@bytemark.co.uk>2016-08-25 14:22:29 +0100
commitbe45dcad9491e809d13145baab5e6ea1caf80791 (patch)
tree7144a6ca8f90c37a600f050e6ad48d535535186e
Initial Commit
-rw-r--r--LICENCE12
-rw-r--r--READ.ME15
-rw-r--r--bashrc.sample6
-rwxr-xr-xincoming/post-local/99-ls3
-rwxr-xr-xincoming/pre-local/00-git-pull20
-rwxr-xr-xincoming/pre-local/01-hg-pull20
-rw-r--r--outgoing/post-local/.empty0
-rw-r--r--outgoing/pre-local/.empty0
-rw-r--r--rc36
9 files changed, 112 insertions, 0 deletions
diff --git a/LICENCE b/LICENCE
new file mode 100644
index 0000000..307771d
--- /dev/null
+++ b/LICENCE
@@ -0,0 +1,12 @@
+Copyright (c) 2016, Næþ'n Lasseter
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/READ.ME b/READ.ME
new file mode 100644
index 0000000..f2bc4b8
--- /dev/null
+++ b/READ.ME
@@ -0,0 +1,15 @@
+1) Clone this repo
+2) Source the rc file in your .bashrc
+3) Start adding your scripts
+
+When you cd to mydir, scripts will run in the following order:
+ 1) cdhooks/incoming/pre-local/
+ 2) mydir/.cdhooks/incoming/
+ 3) cdhooks/incoming/post-local/
+
+When you cd away from mydir:
+ 1) cdhooks/outgoing/pre-local/
+ 2) mydir/.cdhooks/outgoing/
+ 3) cdhooks/outgoing/post-local/
+
+All of the outgoing scripts run before any of the incoming scripts.
diff --git a/bashrc.sample b/bashrc.sample
new file mode 100644
index 0000000..dea2fbf
--- /dev/null
+++ b/bashrc.sample
@@ -0,0 +1,6 @@
+###
+### cdhooks
+###
+
+source ~/.cdhooks/rc
+export CDHOOKS_VERBOSE=
diff --git a/incoming/post-local/99-ls b/incoming/post-local/99-ls
new file mode 100755
index 0000000..1c1b79f
--- /dev/null
+++ b/incoming/post-local/99-ls
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+ls --color=auto
diff --git a/incoming/pre-local/00-git-pull b/incoming/pre-local/00-git-pull
new file mode 100755
index 0000000..4e42eb2
--- /dev/null
+++ b/incoming/pre-local/00-git-pull
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+function pull_and_update_repo {
+ git pull
+}
+
+function test_if_working_directory_clean {
+ git status 2>&1 | grep 'nothing.*commit' > /dev/null && pull_and_update_repo
+}
+
+function test_if_in_repo_root {
+ [ -d .git ] && test_if_working_directory_clean
+}
+
+function test_if_git_repo {
+ git status 2>&1 | grep 'fatal: Not a git repository' > /dev/null || test_if_in_repo_root
+}
+
+test_if_git_repo
+exit 0
diff --git a/incoming/pre-local/01-hg-pull b/incoming/pre-local/01-hg-pull
new file mode 100755
index 0000000..bbc9336
--- /dev/null
+++ b/incoming/pre-local/01-hg-pull
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+function pull_and_update_repo {
+ hg pull --update
+}
+
+function test_if_working_directory_clean {
+ hg status --all 2>&1 | egrep -v '^C' > /dev/null || pull_and_update_repo
+}
+
+function test_if_in_repo_root {
+ [ -d .hg ] && test_if_working_directory_clean
+}
+
+function test_if_hg_repo {
+ hg status 2>&1 | grep 'abort: no repository found' > /dev/null || test_if_in_repo_root
+}
+
+test_if_hg_repo
+exit 0
diff --git a/outgoing/post-local/.empty b/outgoing/post-local/.empty
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/outgoing/post-local/.empty
diff --git a/outgoing/pre-local/.empty b/outgoing/pre-local/.empty
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/outgoing/pre-local/.empty
diff --git a/rc b/rc
new file mode 100644
index 0000000..5334d94
--- /dev/null
+++ b/rc
@@ -0,0 +1,36 @@
+###
+### cdhooks
+### OH DEAR GOD WHAT WAS I THINKING
+###
+
+function cd {
+ if [ $CDHOOKS_VERBOSE ]; then
+ VERBOSE=--verbose
+ fi
+
+ if [ "x$1" == "x" -o "x$1" == "x-" -o -d "$1" ]; then
+
+ # Outgoing stuff
+ [ -d "$HOME/.cdhooks/outgoing/pre-local" ] && run-parts $VERBOSE $HOME/.cdhooks/outgoing/pre-local
+ [ -d ".cdhooks/outgoing" ] && run-parts $VERBOSE .cdhooks/outgoing
+ [ -d "$HOME/.cdhooks/outgoing/post-local" ] && run-parts $VERBOSE $HOME/.cdhooks/outgoing/post-local
+
+ # cd
+ if [ "x" == "x$*" ]
+ then
+ builtin cd
+ else
+ builtin cd "$*"
+ fi
+
+ # Incoming stuff
+ [ -d "$HOME/.cdhooks/incoming/pre-local" ] && run-parts $VERBOSE $HOME/.cdhooks/incoming/pre-local
+ [ -d ".cdhooks/incoming" ] && run-parts $VERBOSE .cdhooks/incoming
+ [ -d "$HOME/.cdhooks/incoming/post-local" ] && run-parts $VERBOSE $HOME/.cdhooks/incoming/post-local
+
+ else
+
+ echo "[cdhooks] No such directory: $1"
+
+ fi
+}