elephant 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/Rakefile +1 -0
- data/bin/e +4 -0
- data/bin/elephant +8 -0
- data/elephant.gemspec +24 -0
- data/lib/elephant/brain.rb +37 -0
- data/lib/elephant/command.rb +25 -0
- data/lib/elephant/commands/all.rb +13 -0
- data/lib/elephant/commands/execute.rb +20 -0
- data/lib/elephant/commands/forget.rb +16 -0
- data/lib/elephant/commands/remember.rb +16 -0
- data/lib/elephant/shell.rb +18 -0
- data/lib/elephant/version.rb +3 -0
- data/lib/elephant.rb +9 -0
- metadata +62 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/e
ADDED
data/bin/elephant
ADDED
data/elephant.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "elephant/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "elephant"
|
|
7
|
+
s.version = Elephant::VERSION
|
|
8
|
+
s.authors = ["Martin Rue"]
|
|
9
|
+
s.email = ["hello@martinrue.com"]
|
|
10
|
+
s.homepage = "https://github.com/martinrue/elephant"
|
|
11
|
+
s.summary = %q{Elephant helps you remember commands you run frequently}
|
|
12
|
+
s.description = %q{Elephant helps you remember commands you run frequently}
|
|
13
|
+
|
|
14
|
+
s.rubyforge_project = "elephant"
|
|
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
|
+
# specify any dependencies here; for example:
|
|
22
|
+
# s.add_development_dependency "rspec"
|
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
|
24
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Elephant
|
|
2
|
+
class Brain
|
|
3
|
+
def initialize
|
|
4
|
+
@commands = {}
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def remember_command(name, command)
|
|
8
|
+
@commands[name] = command
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def recall_command(name)
|
|
12
|
+
@commands[name]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def forget_command(name)
|
|
16
|
+
@commands.delete name
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def all_commands
|
|
20
|
+
@commands
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.load
|
|
24
|
+
brain_path = File.expand_path '~/.elephant_brain'
|
|
25
|
+
File.exists?(brain_path) ? YAML::load(File.open brain_path) : Brain.new
|
|
26
|
+
rescue
|
|
27
|
+
puts 'Error: elephant has brain damage - try removing ~/.elephant_brain'
|
|
28
|
+
exit
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def save
|
|
32
|
+
File.open File.expand_path('~/.elephant_brain'), 'w' do |file|
|
|
33
|
+
YAML.dump self, file
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Elephant
|
|
2
|
+
module Command
|
|
3
|
+
@@commands = {}
|
|
4
|
+
|
|
5
|
+
def on(*matchers, &block)
|
|
6
|
+
@@commands[matchers] = block
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.run(*args)
|
|
10
|
+
requested_command = args.shift || :all
|
|
11
|
+
matched_commands = @@commands.select { |command| command.include?(requested_command.to_sym) }
|
|
12
|
+
return usage if matched_commands.empty?
|
|
13
|
+
matched_commands.each { |command| command.last.call args }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.usage
|
|
17
|
+
puts "usage: elephant <command>\n\n"
|
|
18
|
+
puts "The following commands are supported:\n\n"
|
|
19
|
+
puts " r, remember [name]\t remembers the last command as [name]"
|
|
20
|
+
puts " f, forget [name]\t forgets the command named [name]"
|
|
21
|
+
puts " x, execute [name]\t executes the command named [name]"
|
|
22
|
+
puts " a, all\t\t shows the current list of remembered commands"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Elephant
|
|
2
|
+
class ExecuteCommand
|
|
3
|
+
extend Command
|
|
4
|
+
|
|
5
|
+
on :x, :execute do |args|
|
|
6
|
+
name = args.shift
|
|
7
|
+
unless name.nil?
|
|
8
|
+
brain = Brain.load
|
|
9
|
+
command = brain.recall_command name
|
|
10
|
+
unless command.nil?
|
|
11
|
+
system command
|
|
12
|
+
else
|
|
13
|
+
puts "Elephant doesn't remember command #{name}"
|
|
14
|
+
end
|
|
15
|
+
else
|
|
16
|
+
puts 'Usage: elephant x|execute [name]'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Elephant
|
|
2
|
+
class ForgetCommand
|
|
3
|
+
extend Command
|
|
4
|
+
|
|
5
|
+
on :f, :forget do |args|
|
|
6
|
+
name = args.shift
|
|
7
|
+
unless name.nil?
|
|
8
|
+
brain = Brain.load
|
|
9
|
+
brain.forget_command name
|
|
10
|
+
brain.save
|
|
11
|
+
else
|
|
12
|
+
puts 'Usage: elephant f|forget [name]'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Elephant
|
|
2
|
+
class RememberCommand
|
|
3
|
+
extend Command
|
|
4
|
+
|
|
5
|
+
on :r, :remember do |args|
|
|
6
|
+
name = args.shift
|
|
7
|
+
unless name.nil?
|
|
8
|
+
brain = Brain.load
|
|
9
|
+
brain.remember_command name, Shell.last_command
|
|
10
|
+
brain.save
|
|
11
|
+
else
|
|
12
|
+
puts 'Usage: elephant r|remember [name]'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Elephant
|
|
2
|
+
class Shell
|
|
3
|
+
class << self
|
|
4
|
+
def last_command
|
|
5
|
+
shell_type = ENV['SHELL'] =~ /zsh/ ? :zsh : :bash
|
|
6
|
+
send "last_#{shell_type}_command"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def last_zsh_command
|
|
10
|
+
`cat ~/.zsh_history | tail -n 2 | tail -r | tail -n 1 | cut -d ";" -f 2-`
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def last_bash_command
|
|
14
|
+
`cat ~/.bash_history | tail -n 1`
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/elephant.rb
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require 'elephant/version'
|
|
3
|
+
require 'elephant/command'
|
|
4
|
+
require 'elephant/shell'
|
|
5
|
+
require 'elephant/brain'
|
|
6
|
+
require 'elephant/commands/all'
|
|
7
|
+
require 'elephant/commands/execute'
|
|
8
|
+
require 'elephant/commands/forget'
|
|
9
|
+
require 'elephant/commands/remember'
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: elephant
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Martin Rue
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2011-11-01 00:00:00.000000000Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: Elephant helps you remember commands you run frequently
|
|
15
|
+
email:
|
|
16
|
+
- hello@martinrue.com
|
|
17
|
+
executables:
|
|
18
|
+
- e
|
|
19
|
+
- elephant
|
|
20
|
+
extensions: []
|
|
21
|
+
extra_rdoc_files: []
|
|
22
|
+
files:
|
|
23
|
+
- .gitignore
|
|
24
|
+
- Gemfile
|
|
25
|
+
- Rakefile
|
|
26
|
+
- bin/e
|
|
27
|
+
- bin/elephant
|
|
28
|
+
- elephant.gemspec
|
|
29
|
+
- lib/elephant.rb
|
|
30
|
+
- lib/elephant/brain.rb
|
|
31
|
+
- lib/elephant/command.rb
|
|
32
|
+
- lib/elephant/commands/all.rb
|
|
33
|
+
- lib/elephant/commands/execute.rb
|
|
34
|
+
- lib/elephant/commands/forget.rb
|
|
35
|
+
- lib/elephant/commands/remember.rb
|
|
36
|
+
- lib/elephant/shell.rb
|
|
37
|
+
- lib/elephant/version.rb
|
|
38
|
+
homepage: https://github.com/martinrue/elephant
|
|
39
|
+
licenses: []
|
|
40
|
+
post_install_message:
|
|
41
|
+
rdoc_options: []
|
|
42
|
+
require_paths:
|
|
43
|
+
- lib
|
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
|
+
none: false
|
|
46
|
+
requirements:
|
|
47
|
+
- - ! '>='
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
none: false
|
|
52
|
+
requirements:
|
|
53
|
+
- - ! '>='
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
requirements: []
|
|
57
|
+
rubyforge_project: elephant
|
|
58
|
+
rubygems_version: 1.8.6
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 3
|
|
61
|
+
summary: Elephant helps you remember commands you run frequently
|
|
62
|
+
test_files: []
|