halfshell 0.1.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f81da790a9f850290e57b23ede4f175a1212a4636117abc0f6d9c5136cfb5986
4
+ data.tar.gz: ec5e4e9b34a1165c047c254107e4d35e9fc101d6cca1dffcc5fd785ff2f02192
5
+ SHA512:
6
+ metadata.gz: f5979dbcdd2d7ee6c78fa9d0d28bbf017ea5d589236c9f0e5c890931c5e73eeac69592806aaffbeb9dc5625b20ce737733f80b5bcf66d20aeeb39d69beb9c3b1
7
+ data.tar.gz: d9512b0c688b5d713a270fbd508dad9475bdd444a731420addc7fd7ba4e2538100c64506347a1700ecc450c49328c78f862fe84875d03b46467010bc6b615677
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
14
+ .ruby-version
15
+ /spike/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.6
7
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in halfshell.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Halfshell
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/halfshell`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'halfshell'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install halfshell
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/halfshell.
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "halfshell"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "pry"
14
+ Pry.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/halfshell.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "halfshell/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "halfshell"
7
+ spec.version = HalfShell::VERSION
8
+ spec.authors = ["andydna"]
9
+
10
+ spec.summary = %q{simplified, unsurprising interface for subshells}
11
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
12
+ spec.homepage = "https://github.com/andydna/halfshell"
13
+
14
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
15
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
16
+ # if spec.respond_to?(:metadata)
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+
19
+ # spec.metadata["homepage_uri"] = spec.homepage
20
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+ # else
23
+ # raise "RubyGems 2.0 or newer is required to protect against " \
24
+ # "public gem pushes."
25
+ # end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ # spec.bindir = "exe"
33
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler"
37
+ spec.add_development_dependency "rake"
38
+ spec.add_development_dependency "rspec"
39
+
40
+ spec.add_development_dependency "pry"
41
+ spec.add_development_dependency "pry-doc"
42
+
43
+ spec.add_dependency "open4", "~> 1.3.4"
44
+
45
+ spec.required_ruby_version = ">= 2.6"
46
+ end
data/lib/halfshell.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'halfshell/version'
2
+ require 'halfshell/terminal'
3
+ require 'halfshell/typist'
4
+
5
+ module Halfshell
6
+ class Error < StandardError; end
7
+
8
+ def Halfshell.new
9
+ Typist.new(terminal: Terminal.default)
10
+ end
11
+
12
+ def Halfshell.<<(command)
13
+ new << command
14
+ end
15
+ end
16
+
17
+ def hs
18
+ Halfshell
19
+ end
20
+
21
+ alias :sh :hs
@@ -0,0 +1,62 @@
1
+ require "open4"
2
+
3
+ module Halfshell
4
+ class Terminal
5
+
6
+ def Terminal.default
7
+ Terminal.popen4
8
+ end
9
+
10
+ OPEN4_RETURNS = [:pid, :stdin, :stdout, :stderr]
11
+
12
+ def Terminal.popen4
13
+ Terminal.new(**OPEN4_RETURNS.zip(Open4::popen4("sh 2>&1")).to_h)
14
+ end
15
+
16
+ def initialize(stdin:, stdout:, stderr:, pid:)
17
+ @stdin, @stdout, @stderr, @pid = stdin, stdout, stderr, pid
18
+
19
+ @try = 0
20
+ @limit = 1000
21
+ end
22
+
23
+ def puts(what)
24
+ @stdin.puts what
25
+ end
26
+
27
+ def gets
28
+ read_nonblock_loop(@stdout)
29
+ end
30
+
31
+ def gets_err
32
+ read_nonblock_loop(@stderr)
33
+ end
34
+
35
+ def read_nonblock_loop(io)
36
+ got = ""
37
+ loop do
38
+ begin
39
+ got << io.read_nonblock(1)
40
+ rescue IO::EAGAINWaitReadable
41
+ raise_error if too_many_tries?
42
+ if got.empty?
43
+ sleep(1.0/1000) #sleep(WAIT*@backoff.next)
44
+ return read_nonblock_loop(io)
45
+ else
46
+ @try = 0
47
+ return got
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def too_many_tries?
54
+ @try >= @limit
55
+ end
56
+
57
+ def raise_error
58
+ binding.pry if $testing
59
+ raise Error
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,65 @@
1
+ module Halfshell
2
+
3
+ class Typist
4
+ def initialize(terminal: Terminal.default)
5
+ @terminal = terminal;
6
+
7
+ @try = 0
8
+ @limit = 20
9
+ end
10
+
11
+ def type(*what)
12
+ @terminal.puts(*what)
13
+ self
14
+ end
15
+
16
+ def <<(command)
17
+ @terminal.puts command
18
+ gets
19
+ end
20
+
21
+ def gets
22
+ @terminal.gets
23
+ end
24
+
25
+ def login?
26
+ @terminal.puts "echo $0"
27
+ @terminal.gets[0] == "-"
28
+ end
29
+
30
+ def cd(*args)
31
+ @terminal.puts "cd #{args.join(' ')}"
32
+ end
33
+
34
+ def pwd
35
+ self.<< "pwd"
36
+ end
37
+
38
+ def ls(*args)
39
+ self.<< "ls #{args.join(' ')}"
40
+ end
41
+
42
+ def ll(*args)
43
+ self.<< "ls -l #{args.join(' ')}"
44
+ end
45
+
46
+ def lsh; end
47
+ def su; end
48
+ def clear; end
49
+ def exit; end
50
+
51
+ alias :old_inspect :inspect
52
+ def inspect
53
+ "#<#Typist:#{object_id}>"
54
+ end
55
+
56
+ def method_missing(mthd, *args, &block)
57
+ super(mthd, *args, &block)
58
+ end
59
+
60
+ def respond_to_missing?(mthd, include_private = false) # DO NOT USE THIS DIRECTLY.
61
+ mthd.to_s.match? /ls|tar|ps/ || super
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,3 @@
1
+ module HalfShell
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: halfshell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - andydna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: open4
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.4
97
+ description:
98
+ email:
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".rspec"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - bin/console
110
+ - bin/setup
111
+ - halfshell.gemspec
112
+ - lib/halfshell.rb
113
+ - lib/halfshell/terminal.rb
114
+ - lib/halfshell/typist.rb
115
+ - lib/halfshell/version.rb
116
+ homepage: https://github.com/andydna/halfshell
117
+ licenses: []
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '2.6'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubygems_version: 3.0.3
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: simplified, unsurprising interface for subshells
138
+ test_files: []