# -*- sh -*- # Useful functions mcd () { mkdir -p "$1"; cd "$1"; } odx () { od -t x4 -A x "$@" ; } odx1 () { od -t x1 -A x "$@" ; } fch () { find . -type f -name "*.[ch]" | xargs grep "$@" } fchs () { find . -type f -name "*.[chsS]" | xargs grep "$@" } # Git related handy-handy stuff make-project () { mcd "$1"; git init; cp /usr/share/common-licenses/$2 COPYING; git add COPYING; git commit -m "This project is under the $2 licence at this time"; } # Haskell related handy stuff cabal-dev-here () { CABAL_SANDBOX="$(pwd)/cabal-dev"; export CABAL_SANDBOX; } # We prevented ^D == EOF earlier (30-settings) so now, let's have a clever # ^D handler which does normal ^D behaviour, and also turns exit into popd # if the stack isn't empty... clever_logout_widget () { if test "x$BUFFER" != "x"; then # Buffer is non-empty, need to do usual ^D behaviour # CURSOR is the offer into BUFFER, we need to remove the character # at CURSOR in BUFFER local BUFLEFT BUFRIGHT BUFLEFT="$BUFFER[0,$CURSOR]" BUFRIGHT="$BUFFER[$((CURSOR + 2)),-1]" BUFFER="${BUFLEFT}${BUFRIGHT}" zle -R elif test "x$dirstack" != "x"; then # Need to popd popd 2>/dev/null >/dev/null zle -I zle -R else # Need to exit exit fi } zle -N clever_logout_widget bindkey '^D' clever_logout_widget