aboutsummaryrefslogtreecommitdiff
path: root/rc
blob: 86e2f27b0444b2e24ea0749c1331a6d9a0c86f1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
###
### cdhooks
### OH DEAR GOD WHAT WAS I THINKING
###

function cd {
  if [ $CDHOOKS_VERBOSE ]; then
    VERBOSE=--verbose
  fi

  ARGS=
  for arg in $* ; do
    ARGS="${ARGS} --arg ${arg}"
  done

  if [ "x$1" == "x" -o "x$1" == "x-" -o -d "$1" ]; then

    # Outgoing stuff
    [ -d "$HOME/.cdhooks/outgoing/pre-local" ] && run-parts $VERBOSE $ARGS $HOME/.cdhooks/outgoing/pre-local
    [ -d ".cdhooks/outgoing" ] && run-parts $VERBOSE $ARGS .cdhooks/outgoing
    [ -d "$HOME/.cdhooks/outgoing/post-local" ] && run-parts $VERBOSE $ARGS $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 $ARGS $HOME/.cdhooks/incoming/pre-local
    [ -d ".cdhooks/incoming" ] && run-parts $VERBOSE $ARGS .cdhooks/incoming
    [ -d "$HOME/.cdhooks/incoming/post-local" ] && run-parts $VERBOSE $ARGS $HOME/.cdhooks/incoming/post-local

  else

    echo "[cdhooks] No such directory: $1"

  fi
}