ralias 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -fs --color
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ralias.gemspec
4
+ gemspec
@@ -0,0 +1,81 @@
1
+ # Ralias
2
+
3
+ This library is extended so that it can be used to rich your shell more :)
4
+
5
+ ## Build Status
6
+
7
+ <img src="https://secure.travis-ci.org/daic-h/ralias.png"/>
8
+
9
+ ## Supported versions
10
+
11
+ * Ruby 1.8.7, 1.9.x, ree
12
+
13
+ ## Install
14
+
15
+ $ gem install ralias
16
+
17
+ ## How to use
18
+
19
+ you type
20
+
21
+ $ ralias
22
+
23
+ help will be output.
24
+
25
+ help -> print help
26
+ init -> create ~/.raliasrc
27
+ list -> print defined aliase command
28
+ define -> define new aliase command (TODO)
29
+
30
+ ## Ralias init
31
+
32
+ create .raliasrc file.
33
+
34
+ $ ralias init
35
+
36
+ ## .raliasrc
37
+
38
+ ### An example of how editing
39
+
40
+ normal alias definition.
41
+
42
+ define("lsA") { "ls -al" }
43
+
44
+ please use this way.
45
+
46
+ $ ralias lsA
47
+
48
+ if you want to use the arguments to the alias
49
+
50
+ define("github") do |user_name, repository|
51
+ "git clone https://github.com/#{user_name}/#{repository}.git"
52
+ end
53
+
54
+ in that case, you use it in this manner.
55
+
56
+ $ ralias github user_name repository
57
+
58
+ result is
59
+
60
+ load ~/.raliasrc
61
+ Cloning into repository...
62
+ ...
63
+
64
+ ## $ ralias list
65
+
66
+ print defined aliase command.
67
+
68
+ if the initial state,
69
+
70
+ help
71
+ init
72
+ define
73
+ list
74
+
75
+ if after you define the command.
76
+
77
+ help
78
+ init
79
+ define
80
+ list
81
+ github :user_name :repository
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pathname"
4
+ bin_file = Pathname.new(__FILE__).realpath
5
+
6
+ $:.unshift File.expand_path("../../lib", bin_file)
7
+
8
+ require 'ralias'
9
+ Ralias::CLI.start(ARGV)
10
+
@@ -0,0 +1,8 @@
1
+ require "ralias/version"
2
+ require "ralias/color"
3
+ require "ralias/cli"
4
+ require "ralias/command"
5
+
6
+ module Ralias
7
+ class CommandNotFound < StandardError; end
8
+ end
@@ -0,0 +1,10 @@
1
+ module Ralias
2
+ module CLI
3
+ def self.start(args)
4
+ command = args.shift.strip rescue "help"
5
+ Ralias::Command.load
6
+ Ralias::Command.run(command, args)
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,13 @@
1
+ module Ralias
2
+ module Color
3
+ def colors
4
+ { :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35,
5
+ :cyan => 36, :white => 27, :default => 39 }
6
+ end
7
+
8
+ def with_color(state = :default)
9
+ puts "\e[#{colors[state]}m#{yield}\e[0m"
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,73 @@
1
+ module Ralias
2
+ module Command
3
+ extend Color
4
+
5
+ class << self
6
+
7
+ def rc_path
8
+ File.expand_path("~/.raliasrc")
9
+ end
10
+
11
+ def clear
12
+ @@commands = {}
13
+ end
14
+
15
+ def commands
16
+ @@commands ||= {}
17
+ end
18
+
19
+ def built_in_commands
20
+ @@built_in_commands ||= []
21
+ end
22
+
23
+ def define(name, &block)
24
+ return if commands[name]
25
+ commands[name] = block
26
+ end
27
+
28
+ def load
29
+ require 'ralias/define_commands'
30
+
31
+ begin
32
+ if File.exist?(rc_path)
33
+ class_eval(File.open(rc_path).read)
34
+ with_color(:cyan) { "load ~/.raliasrc" }
35
+ end
36
+ rescue NameError
37
+ with_color(:red) { "could not be load ~/.raliasrc" }
38
+ rescue
39
+ nil
40
+ end
41
+ end
42
+
43
+ def run(_cmd, args)
44
+ cmd = commands[_cmd]
45
+ required_args = cmd.parameters
46
+
47
+ begin
48
+ if required_args.size == args.size
49
+ if built_in_commands.include?(_cmd)
50
+ cmd.call(*args)
51
+ else
52
+ system cmd.call(*args)
53
+ end
54
+ else
55
+ with_color(:red) do
56
+ "wrong number of arguments (#{args.size} for #{required_args.size}) (ArgumentError)"
57
+ end
58
+
59
+ required_args.each do |arg|
60
+ with_color { "argumets: " + arg[1].to_s }
61
+ end
62
+ raise CommandNotFound
63
+ end
64
+
65
+ rescue CommandNotFound
66
+ with_color(:red) { "command not found." }
67
+ rescue
68
+ with_color(:red) { "error in the definition file." }
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,58 @@
1
+ module Ralias::Command
2
+ define("help") do
3
+ with_color(:red) do
4
+ <<-HELP
5
+ help -> print help
6
+ init -> create ~/.raliasrc
7
+ list -> print defined aliase command
8
+ define -> define new aliase command (TODO)
9
+ HELP
10
+ end
11
+ end
12
+ built_in_commands << "help"
13
+
14
+ define("init") do
15
+ unless File.exist?(rc_path)
16
+ File.open(rc_path, "w") do |rc_file|
17
+ rc_file.puts <<-'EXAMPLE'
18
+ # -*- coding: utf-8; mode: ruby; -*-
19
+ #
20
+ # Example
21
+ #
22
+ # normal alias definition
23
+ #
24
+ # define("lsA") { "ls -al" }
25
+ #
26
+ # if you want to use the arguments to the alias
27
+ #
28
+ # define("github") do |user_name, repository|
29
+ # "git clone https://github.com/#{user_name}/#{repository}.git"
30
+ # end
31
+ #
32
+ EXAMPLE
33
+ end
34
+ with_color(:yellow) { "create file #{rc_path}" }
35
+ else
36
+ with_color(:green) { "exist file #{rc_path}" }
37
+ end
38
+ end
39
+ built_in_commands << "init"
40
+
41
+ define("define") do
42
+ with_color(:red) { "TODO" }
43
+ end
44
+ built_in_commands << "define"
45
+
46
+ define("list") do
47
+ commands.each do |command, block|
48
+ unless block.parameters.empty?
49
+ block.parameters.each do |param|
50
+ command += (" :" +param[1].to_s)
51
+ end
52
+ end
53
+
54
+ with_color(:green) { command }
55
+ end
56
+ end
57
+ built_in_commands << "list"
58
+ end
@@ -0,0 +1,3 @@
1
+ module Ralias
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ralias/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ralias"
7
+ s.version = Ralias::VERSION
8
+ s.authors = ["Daic_h"]
9
+ s.email = ["bunny.hop.md@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = 'to extend the alias of shell in ruby'
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "ralias"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'rake', '>= 0.9.2.2'
22
+ s.add_development_dependency 'rspec', '>= 2.7.0'
23
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'ralias/define_commands'
3
+
4
+ describe Ralias::Command do
5
+ context 'when the initial state' do
6
+ it 'We can find help' do
7
+ Ralias::Command.commands.should include('help')
8
+ end
9
+
10
+ it 'We can find init' do
11
+ Ralias::Command.commands.should include('init')
12
+ end
13
+
14
+ it 'We can find define' do
15
+ Ralias::Command.commands.should include('define')
16
+ end
17
+
18
+ it 'We can find list' do
19
+ Ralias::Command.commands.should include('list')
20
+ end
21
+ end
22
+
23
+ context 'when define a command' do
24
+ before do
25
+ Ralias::Command.clear
26
+ @block = lambda {}
27
+ Ralias::Command.define('mock_command', &@block)
28
+ end
29
+
30
+ it 'We can find it' do
31
+ Ralias::Command.commands.should include('mock_command')
32
+ end
33
+
34
+ it 'We can find nil with wrong name' do
35
+ Ralias::Command.commands.should_not include('mock_sub_command')
36
+ end
37
+
38
+ describe 'Command.[]' do
39
+ it 'can get a command' do
40
+ Ralias::Command.commands['mock_command'].should eq(@block)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require 'ralias'
6
+ require 'rspec'
7
+
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ralias
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daic_h
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70329175865900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70329175865900
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70329175851220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70329175851220
36
+ description: to extend the alias of shell in ruby
37
+ email:
38
+ - bunny.hop.md@gmail.com
39
+ executables:
40
+ - ralias
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - .rspec
46
+ - .travis.yml
47
+ - Gemfile
48
+ - README.md
49
+ - Rakefile
50
+ - bin/ralias
51
+ - lib/ralias.rb
52
+ - lib/ralias/cli.rb
53
+ - lib/ralias/color.rb
54
+ - lib/ralias/command.rb
55
+ - lib/ralias/define_commands.rb
56
+ - lib/ralias/version.rb
57
+ - ralias.gemspec
58
+ - spec/command_spec.rb
59
+ - spec/spec_helper.rb
60
+ homepage: ''
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project: ralias
80
+ rubygems_version: 1.8.10
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: to extend the alias of shell in ruby
84
+ test_files:
85
+ - spec/command_spec.rb
86
+ - spec/spec_helper.rb
87
+ has_rdoc: