Created
February 10, 2012 11:55
-
-
Save daichirata/1789042 to your computer and use it in GitHub Desktop.
alias
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
#!/usr/bin/env ruby | |
COLORS = | |
{ :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36, :white => 27, :default => 39 } | |
@@command_list = {} | |
def with_color(state = :default) | |
puts "\e[#{COLORS[state]}m#{yield}\e[0m" | |
end | |
def define(name, &block) | |
@@command_list[name] = lambda(&block) | |
end | |
begin | |
load "~/.rubyaliaserc" | |
with_color(:cyan) { "load rubyaliaserc" } | |
rescue LoadError | |
nil | |
end | |
# | |
# Example | |
# | |
# define("github") do |user_name, repository| | |
# "git clone https://github.com/#{user_name}/#{repository}.git" | |
# end | |
# | |
args = ARGV | |
command = args.shift | |
required_args = @@command_list[command].parameters | |
unless required_args == args.size | |
with_color(:red){ "wrong number of arguments (#{args.size} for #{required_args.size}) (ArgumentError)" } | |
required_args.each do |arg| | |
with_color { "argumets: " + arg[1].to_s } | |
end | |
else | |
system @@command_list[command].call(*args) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment