forked from antono/shelr
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
205 additions
and
7 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
diff-lcs (1.1.2) | ||
extlib (0.9.15) | ||
git (1.2.5) | ||
jeweler (1.5.1) | ||
bundler (~> 1.0.0) | ||
git (>= 1.2.5) | ||
rake | ||
json (1.4.6) | ||
mixlib-cli (1.2.0) | ||
mixlib-config (1.1.2) | ||
mixlib-log (1.2.0) | ||
ohai (0.5.8) | ||
extlib | ||
json (>= 1.4.4, <= 1.4.6) | ||
mixlib-cli | ||
mixlib-config | ||
mixlib-log | ||
systemu | ||
rake (0.8.7) | ||
rcov (0.9.9) | ||
rspec (2.1.0) | ||
rspec-core (~> 2.1.0) | ||
rspec-expectations (~> 2.1.0) | ||
rspec-mocks (~> 2.1.0) | ||
rspec-core (2.1.0) | ||
rspec-expectations (2.1.0) | ||
diff-lcs (~> 1.1.2) | ||
rspec-mocks (2.1.0) | ||
systemu (1.2.0) | ||
xdg (1.0.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler (~> 1.0.0) | ||
jeweler (~> 1.5.1) | ||
ohai | ||
rcov | ||
rspec (~> 2.1.0) | ||
xdg |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__)) | ||
|
||
require 'rubygems' | ||
require 'shellcast' | ||
|
||
case ARGV[0] | ||
when 'record' | ||
ShellCast::Recorder.record! | ||
when 'list' | ||
ShellCast::Player.list | ||
when 'play' | ||
if ARGV[1] | ||
ShellCast::Player.play(ARGV[1]) | ||
else | ||
puts "Missing id for shellcast" | ||
ShellCast::Player.list | ||
puts "Select one..." | ||
exit | ||
end | ||
else | ||
puts "Usage: #{__FILE__} command [shellcast_id]" | ||
puts "Commands: record, list, play, publish, get" | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'rubygems' | ||
require 'fileutils' | ||
require 'xdg' | ||
require 'yaml' | ||
|
||
module ShellCast | ||
|
||
APP_NAME = 'shellcast' | ||
DATA_DIR = File.join(XDG::Data.home, APP_NAME) | ||
|
||
def shellcast_dir(shellcast_id) | ||
File.join(ShellCast::DATA_DIR, shellcast_id) | ||
end | ||
module_function :shellcast_dir | ||
|
||
autoload :Recorder, 'shellcast/recorder.rb' | ||
autoload :Player, 'shellcast/player.rb' | ||
autoload :Publisher, 'shellcast/publisher.rb' | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module ShellCast | ||
class Player | ||
def self.play(id) | ||
new(id).play | ||
end | ||
|
||
def self.list | ||
Dir[File.join(ShellCast::DATA_DIR, "**", 'meta')].each do |path| | ||
metadata = YAML.load_file(path) | ||
puts "#{metadata["id"]}: #{metadata["title"]}" | ||
end | ||
end | ||
|
||
def initialize(id) | ||
@shellcast_id = id | ||
end | ||
|
||
def play | ||
puts "" | ||
puts "Playback started" | ||
puts "-" * 80 | ||
system(scriptreplay_cmd) | ||
puts | ||
puts "-" * 80 | ||
puts "Playback finished" | ||
end | ||
|
||
private | ||
|
||
def shellcast_file(name) | ||
File.join(ShellCast.shellcast_dir(@shellcast_id), name) | ||
end | ||
|
||
def scriptreplay_cmd | ||
"scriptreplay #{shellcast_file('timing')} #{shellcast_file('data')}" | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module ShellCast | ||
class Publisher | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module ShellCast | ||
class Recorder | ||
|
||
def self.record! | ||
new.record! | ||
end | ||
|
||
def initialize | ||
@meta = {} | ||
end | ||
|
||
def record! | ||
FileUtils.mkdir_p(shellcast_dir) unless File.exists?(shellcast_dir) | ||
request_metadata | ||
puts "Your session started" | ||
puts "Type Ctrl+D or exit to finish recording" | ||
puts "-" * 80 | ||
system(script_cmd) | ||
puts "-" * 80 | ||
puts "Session finihed!" | ||
puts "Shellcast ID:\t #{shellcast_id}" | ||
puts "Shellcast path:\t #{shellcast_dir}" | ||
end | ||
|
||
def request_metadata | ||
puts "Provide name for Your shellcast: " | ||
@meta["title"] = STDIN.gets.strip | ||
@meta["id"] = shellcast_id | ||
puts shellcast_file('meta') | ||
File.open(shellcast_file('meta'), 'w+') do |meta| | ||
meta.puts @meta.to_yaml | ||
end | ||
end | ||
|
||
private | ||
|
||
def shellcast_dir | ||
@shellcast_dir ||= ShellCast.shellcast_dir(shellcast_id) | ||
end | ||
|
||
def shellcast_id | ||
@shellcast_id ||= Time.now.to_i.to_s | ||
end | ||
|
||
def shellcast_file(name) | ||
File.join(ShellCast.shellcast_dir(shellcast_id), name) | ||
end | ||
|
||
def script_cmd | ||
"script -c 'bash' #{shellcast_file('data')} -t 2> #{shellcast_file('timing')}" | ||
end | ||
end | ||
end |
Empty file.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'spec_helper' | ||
|
||
describe ShellCast::Recorder do | ||
describe "#record!" do | ||
it "should start script session" do | ||
subject.should_receive("system").with(anything) | ||
subject.record! | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
require 'spec_helper' | ||
|
||
describe "Shellcast" do | ||
it "fails" do | ||
fail "hey buddy, you should probably rename this file and start specing for real" | ||
describe ShellCast do | ||
it "should have ::APP_NAME defined" do | ||
ShellCast::APP_NAME.should == 'shellcast' | ||
end | ||
|
||
it "should provide XDG and APP_NAME based ::DATA_DIR" do | ||
ShellCast::DATA_DIR.should == File.join(XDG::Data.home, ShellCast::APP_NAME) | ||
end | ||
end |