Created
April 16, 2013 01:21
-
-
Save pasberth/5392632 to your computer and use it in GitHub Desktop.
zsh で OOP 的な記法をする感じ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- sh -*- | |
# objective.zsh | |
# $ pwd | |
# /Users/pasberth | |
# $ pwd.dirname | |
# /Users | |
# $ pwd.basename | |
# pasberth | |
# $ pwd.ls -Ahl --color=auto | |
# lrwxr-xr-x 1 pasberth staff 38 8 22 2012 .zlogin -> /Users/pasberth/.dotfiles/home/.zlogin | |
# lrwxr-xr-x 1 pasberth staff 39 8 22 2012 .zlogout -> /Users/pasberth/.dotfiles/home/.zlogout | |
# lrwxr-xr-x 1 pasberth staff 40 9 9 2012 .zprofile -> /Users/pasberth/.dotfiles/home/.zprofile | |
# lrwxr-xr-x 1 pasberth staff 38 8 22 2012 .zshenv -> /Users/pasberth/.dotfiles/home/.zshenv | |
function command_not_found_handler { | |
local -a instrs cmd arg i | |
instrs=($(echo "$0" | sed 's/\./\n/g')) | |
shift | |
for cmd in $instrs | |
do | |
type $cmd > /dev/null 2>&1 || return 127 | |
done | |
for i in `seq $#instrs | head -n -1` | |
do | |
cmd=$instrs[$i] | |
arg=$($cmd $arg) || return $? | |
done | |
cmd=$instrs[-1] | |
$cmd $* $arg | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment