Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created April 16, 2013 01:21
Show Gist options
  • Save pasberth/5392632 to your computer and use it in GitHub Desktop.
Save pasberth/5392632 to your computer and use it in GitHub Desktop.
zsh で OOP 的な記法をする感じ
# -*- 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