elscripto 0.5.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 +8 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +2 -0
- data/bin/elscripto +44 -0
- data/config/elscripto.conf.yml +10 -0
- data/config/elscripto.init.yml +20 -0
- data/elscripto.gemspec +24 -0
- data/lib/elscripto/app.rb +193 -0
- data/lib/elscripto/command.rb +25 -0
- data/lib/elscripto/version.rb +3 -0
- data/lib/elscripto.rb +3 -0
- data/spec/command_spec.rb +19 -0
- data/spec/elscripto_spec.rb +71 -0
- data/spec/files/custom.conf +2 -0
- data/spec/files/empty.yml +2 -0
- data/spec/files/gnome-script.txt +1 -0
- data/spec/files/kde-script.txt +13 -0
- data/spec/files/new_definition.yml +5 -0
- data/spec/files/nonexistent_command.yml +5 -0
- data/spec/files/osascript.txt +11 -0
- data/spec/files/sample_options.yml +6 -0
- metadata +103 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- "1.8.7"
|
4
|
+
- "1.9.2"
|
5
|
+
- "1.9.3"
|
6
|
+
- jruby-18mode # JRuby in 1.8 mode
|
7
|
+
- jruby-19mode # JRuby in 1.9 mode
|
8
|
+
- rbx-18mode
|
9
|
+
- rbx-19mode
|
10
|
+
# uncomment this line if your project needs to run something other than `rake`:
|
11
|
+
script: bundle exec rspec spec
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012-2013 Achilles Charmpilas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# El Scripto Spectacularrr [](https://travis-ci.org/Achillefs/elscripto)
|
2
|
+
|
3
|
+
elscripto is a command line automator. It was initially written to start up a few OSX Terminal tabs that I used for Rails development. At first it was just a ruby script with a few hardcoded commands, but it slowly evolved into the nifty little configurable command line utility you see here.
|
4
|
+
|
5
|
+
## Platforms
|
6
|
+
|
7
|
+
This gem currently works on Mac OSX, and Linux with Gnome or KDE desktops.
|
8
|
+
It uses Applescript, gnome-terminal and konsole automation via qdbus depending on the platform.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'elscripto'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install elscripto
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
From within a project directory, run the following command to bootstrap Elscripto.
|
27
|
+
|
28
|
+
$ elscripto init
|
29
|
+
|
30
|
+
This will create an `.elscripto` file, containing a few command definitions that you can edit to your liking.
|
31
|
+
From then on, every time you call `elscripto` from within that folder, the specified commands will be ran in different tabs. [This is an example configuration](https://github.com/Achillefs/elscripto/blob/master/config/elscripto.init.yml) file that also tells you how to add your own definitions in a project.
|
32
|
+
|
33
|
+
### Command Definitions
|
34
|
+
|
35
|
+
Elscripto comes with a few built-in shell commands; Upon first run, a default configuration file is installed in a platform-dependent directory
|
36
|
+
|
37
|
+
* **OSX**: `/usr/local/etc/elscripto/_default.conf`
|
38
|
+
* **Linux**: `<your home dir>/.config/elscripto/_default.conf`
|
39
|
+
|
40
|
+
Have a look at the bundled [elscripto.conf.yml](https://github.com/Achillefs/elscripto/blob/master/config/elscripto.conf.yml) for a list of built-in commands.
|
41
|
+
|
42
|
+
You can drop in more files in there and as long as the file extension is conf, Elscripto will attempt to load the definitions. Bear in mind the following:
|
43
|
+
|
44
|
+
* Definition files are loaded alphabetically, so you can overwrite a default definition (or one of yours for that matter) by re-defining it in a latter custom configuration file
|
45
|
+
* Overwriting `default.conf` is not a good idea, your changes are probably gonna get overwritten by a gem update
|
46
|
+
|
47
|
+
## Suggestions, comments, bugs, whatever
|
48
|
+
|
49
|
+
Feel free to use Issues to submit bugs, suggestions or feature requests.
|
50
|
+
Elscripto should work on all major platforms (yes, even Windows), let not my limited knowledge / experience and time stand in the way!
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
59
|
+
|
60
|
+
## Changelog
|
61
|
+
|
62
|
+
* 0.5.0 KDE support
|
63
|
+
* 0.4.0 Custom configuration files support
|
64
|
+
* 0.3.0 GNOME support
|
65
|
+
* 0.2.0 OSX support
|
66
|
+
* 0.1.0 Initial release
|
data/Rakefile
ADDED
data/bin/elscripto
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'elscripto'
|
4
|
+
require 'nutrun-string'
|
5
|
+
|
6
|
+
def run(command)
|
7
|
+
executable_name = File.basename($PROGRAM_NAME)
|
8
|
+
|
9
|
+
if command != nil and %{init start --version}.include?(command) # valid command?
|
10
|
+
case command
|
11
|
+
when 'init'
|
12
|
+
print "\nInitializing elscripto...".yellow
|
13
|
+
begin
|
14
|
+
Elscripto::App.init!
|
15
|
+
puts " done."
|
16
|
+
puts "Before continuing, update ./.elscripto with the desired script definitions\n\n".yellow
|
17
|
+
rescue Elscripto::AlreadyInitializedError
|
18
|
+
puts " nah, it's already there!\n".green
|
19
|
+
end
|
20
|
+
when 'start'
|
21
|
+
if File.exists? Elscripto::App::CONFIG_FILE
|
22
|
+
begin
|
23
|
+
app = Elscripto::App.new(Elscripto::App::CONFIG_FILE)
|
24
|
+
puts 'Starting ElScripto Spctacularrr!'.green
|
25
|
+
app.exec!
|
26
|
+
rescue Elscripto::NoDefinitionsError,Elscripto::UnsupportedOSError,Elscripto::LaunchFailedError => e
|
27
|
+
puts "\n#{e.message}\n".red
|
28
|
+
end
|
29
|
+
else
|
30
|
+
print "No configuration found, initializing...".yellow
|
31
|
+
Elscripto::App.init!
|
32
|
+
puts "done.".green
|
33
|
+
puts "Before continuing, update ./.elscripto with the desired script definitions".yellow
|
34
|
+
end
|
35
|
+
when '--version', '-v'
|
36
|
+
puts "\n#{executable_name.capitalize} version #{Elscripto::VERSION}".white
|
37
|
+
puts "(c) 2012, Achillefs Charmpilas\n".green
|
38
|
+
end
|
39
|
+
else # valid command?
|
40
|
+
puts "\nUsage: #{executable_name} init|start\n".white
|
41
|
+
end # valid command?
|
42
|
+
end
|
43
|
+
|
44
|
+
run(ARGV[0]) unless ENV['NO_RUN']
|
@@ -0,0 +1,10 @@
|
|
1
|
+
---
|
2
|
+
spork: spork
|
3
|
+
spork:unit: spork testunit
|
4
|
+
autotest: autotest
|
5
|
+
rails:server: 'rails s'
|
6
|
+
rails:console: 'rails c'
|
7
|
+
rails:logtail: 'rake log:clear && tail -f log/development.log'
|
8
|
+
rails:compass: 'compass watch'
|
9
|
+
rails:watchr: 'watchr ./config/specs.watchr'
|
10
|
+
test: "echo 'SPECTACULARRR!'"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This is file generated by elscripto for you.
|
2
|
+
# The following are a few frequently used commands already built-in.
|
3
|
+
# You should enable the commands you want elscripto to run for this project.
|
4
|
+
---
|
5
|
+
commands:
|
6
|
+
# - spork # https://github.com/sporkrb/spork
|
7
|
+
# - spork:unit # https://rubygems.org/gems/spork-testunit
|
8
|
+
# - autotest # https://github.com/grosser/autotest
|
9
|
+
# - rails:server # runs `rails server`
|
10
|
+
# - rails:console # runs `rails console`
|
11
|
+
# - rails:logtail # runs `rake log:clear && tail -f log/development.log`
|
12
|
+
# - rails:compass # runs `compass watch`
|
13
|
+
# - rails:watchr # runs a default rails watchr command: watchr ./config/specs.watchr
|
14
|
+
#
|
15
|
+
# While elscripto was initially developed for Rails development, it can be used to automate any console window group
|
16
|
+
# Here is an example command specification:
|
17
|
+
# - name: customlogtail
|
18
|
+
# command: tail -f log/custom/errors.log
|
19
|
+
# If you find yourself specifying a rule again and again,
|
20
|
+
# why not add it to {{GLOBAL_CONF_PATH}}, thus making them globally available
|
data/elscripto.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "elscripto/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "elscripto"
|
7
|
+
s.version = Elscripto::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Achilles Charmpilas"]
|
10
|
+
s.email = ["ac@humbuckercode.co.uk"]
|
11
|
+
s.homepage = "http://github.com/Achillefs/elscripto"
|
12
|
+
s.summary = %q{Console window group automation for developers}
|
13
|
+
s.description = %q{Console window group automation for developers}
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.rubyforge_project = "elscripto"
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency('nutrun-string')
|
23
|
+
s.add_development_dependency('rspec')
|
24
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'rbconfig'
|
3
|
+
require 'nutrun-string'
|
4
|
+
|
5
|
+
module Elscripto # :nodoc:
|
6
|
+
GLOBAL_CONF_PATHS = {
|
7
|
+
:osx => File.join('/usr','local','etc','elscripto'),
|
8
|
+
:linux => File.join(ENV['HOME'],'.config','elscripto')
|
9
|
+
}
|
10
|
+
|
11
|
+
class LaunchFailedError < Exception # :nodoc:
|
12
|
+
def initialize
|
13
|
+
super "Your windows have failed to launch. Please check your command definitions"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class AlreadyInitializedError < Exception # :nodoc:
|
18
|
+
def initialize
|
19
|
+
super "The configuration file already exists"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class NoDefinitionsError < Exception # :nodoc:
|
24
|
+
def initialize
|
25
|
+
super "No definitions in your configuration file. What's the deal, guy?"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class UnsupportedOSError < Exception # :nodoc:
|
30
|
+
def initialize(os)
|
31
|
+
super "Sorry, Elscripto does not currently support #{os}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# This is the application class used by the elscripto binary
|
36
|
+
# Initialize it by passing a config file to it.
|
37
|
+
# Default file path is <current_dir>/.elscripto
|
38
|
+
class App
|
39
|
+
attr_accessor :commands, :platform, :enviroment, :generated_script
|
40
|
+
CONFIG_FILE = File.join('.','.elscripto')
|
41
|
+
|
42
|
+
def initialize opts_file, opts = {}
|
43
|
+
@commands = []
|
44
|
+
@generated_script = ""
|
45
|
+
@platform = self.class.get_platform(RbConfig::CONFIG['host_os'])
|
46
|
+
first_run?
|
47
|
+
@enviroment = opts.delete(:enviroment) || :production
|
48
|
+
config_file = opts_file ? opts_file : CONFIG_FILE
|
49
|
+
raise ArgumentError.new "Elscripto needs a config file spectacularrr" unless File.exists?(config_file)
|
50
|
+
opts = YAML.load_file(config_file)
|
51
|
+
raise Elscripto::NoDefinitionsError.new unless opts['commands'].class == Array
|
52
|
+
opts['commands'].each do |cmd|
|
53
|
+
case cmd.class.to_s
|
54
|
+
when 'Hash'
|
55
|
+
@commands << Command.new(cmd['name'], :command => cmd['command'])
|
56
|
+
when 'String'
|
57
|
+
@commands << Command.new(cmd)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def exec!
|
63
|
+
raise Elscripto::NoDefinitionsError.new if self.commands.size == 0
|
64
|
+
case self.platform
|
65
|
+
# tell application "Terminal"
|
66
|
+
# activate
|
67
|
+
# delay 1
|
68
|
+
# do script "clear && echo \"--STARTING SPORK SERVER--\" && cd Sites/tabbo/ && spork" in front window
|
69
|
+
# tell application "System Events" to keystroke "t" using command down
|
70
|
+
# do script "clear && echo \"--STARTING RAILS SERVER--\" && cd Sites/tabbo/ && rails c" in front window
|
71
|
+
# tell application "System Events" to keystroke "t" using command down
|
72
|
+
# do script "clear && echo \"--STARTING AUTOTEST--\" && cd Sites/tabbo/ && autotest" in front window
|
73
|
+
# end tell
|
74
|
+
when :osx
|
75
|
+
@generated_script = %{tell application "Terminal"\n}
|
76
|
+
@generated_script<< %{activate\n}
|
77
|
+
@generated_script<< commands.map { |cmd| %{tell application "System Events" to keystroke "t" using command down\ndelay 0.5\ndo script "clear && echo \\"-- Running #{cmd.name} Spectacularrr --\\" && #{cmd.system_call}" in front window} }.join("\n")
|
78
|
+
@generated_script<< "\nend tell"
|
79
|
+
if self.enviroment == :production
|
80
|
+
begin
|
81
|
+
tempfile = File.join(ENV['TMPDIR'],'elscripto.tmp')
|
82
|
+
File.open(tempfile,'w') { |f| f.write(@generated_script) }
|
83
|
+
raise Elscripto::LaunchFailedError.new unless system("osascript #{tempfile}")
|
84
|
+
ensure
|
85
|
+
File.delete(tempfile)
|
86
|
+
end
|
87
|
+
else
|
88
|
+
@generated_script
|
89
|
+
end
|
90
|
+
when :linux
|
91
|
+
# Gnome desktops
|
92
|
+
# Example script: gnome-terminal --tab -e "tail -f somefile" --tab -e "some_other_command"
|
93
|
+
if self.class.is_gnome?
|
94
|
+
@generated_script = %{gnome-terminal }
|
95
|
+
@generated_script<< commands.map { |cmd| %{--tab --title '#{cmd.name}' -e '#{cmd.system_call}'} }.join(" ")
|
96
|
+
if self.enviroment == :production
|
97
|
+
raise Elscripto::LaunchFailedError.new unless system(@generated_script)
|
98
|
+
else
|
99
|
+
@generated_script
|
100
|
+
end
|
101
|
+
# KDE Desktops, using qdbus
|
102
|
+
# CDCMD='cd ~/elscripto'
|
103
|
+
# elCommands=('htop' 'tail -f LICENSE.txt' 'tail -f README.md');
|
104
|
+
# for i in "${elCommands[@]}"
|
105
|
+
# do
|
106
|
+
# session=$(qdbus org.kde.konsole /Konsole newSession)
|
107
|
+
# qdbus org.kde.konsole /Sessions/${session} sendText "${CDCMD}"
|
108
|
+
# qdbus org.kde.konsole /Sessions/${session} sendText $'\n'
|
109
|
+
# qdbus org.kde.konsole /Sessions/${session} sendText "${i}"
|
110
|
+
# qdbus org.kde.konsole /Sessions/${session} sendText $'\n'
|
111
|
+
# qdbus org.kde.konsole /Sessions/${session} setMonitorActivity true
|
112
|
+
# done
|
113
|
+
elsif self.class.is_kde?
|
114
|
+
@generated_script = %{CDCMD='cd #{Dir.pwd}'\n}
|
115
|
+
@generated_script<< "elCommands=("
|
116
|
+
@generated_script<< commands.map { |cmd| %{'#{cmd.system_call}'} }.join(" ")
|
117
|
+
@generated_script<< ")\n"
|
118
|
+
@generated_script<< %{for i in "${elCommands[@]}"
|
119
|
+
do
|
120
|
+
session=$(qdbus org.kde.konsole /Konsole newSession)
|
121
|
+
qdbus org.kde.konsole /Sessions/${session} sendText "${CDCMD}"
|
122
|
+
qdbus org.kde.konsole /Sessions/${session} sendText $'\n'
|
123
|
+
qdbus org.kde.konsole /Sessions/${session} sendText "${i}"
|
124
|
+
qdbus org.kde.konsole /Sessions/${session} sendText $'\n'
|
125
|
+
qdbus org.kde.konsole /Sessions/${session} setMonitorActivity true
|
126
|
+
done}
|
127
|
+
if self.enviroment == :production
|
128
|
+
begin
|
129
|
+
tempfile = File.join('/','tmp','elscripto.tmp')
|
130
|
+
File.open(tempfile,'w') { |f| f.write(@generated_script) }
|
131
|
+
raise Elscripto::LaunchFailedError.new unless system("/bin/bash #{tempfile}")
|
132
|
+
ensure
|
133
|
+
File.delete(tempfile)
|
134
|
+
end
|
135
|
+
@generated_script
|
136
|
+
end
|
137
|
+
else
|
138
|
+
Elscripto::UnsupportedOSError.new('your flavour of linux')
|
139
|
+
end
|
140
|
+
else
|
141
|
+
raise Elscripto::UnsupportedOSError.new(self.platform)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def first_run?
|
146
|
+
global_conf_file = File.join(GLOBAL_CONF_PATHS[platform],'_default.conf')
|
147
|
+
|
148
|
+
case platform
|
149
|
+
when :osx,:linux
|
150
|
+
unless File.exists?(global_conf_file)
|
151
|
+
require 'fileutils'
|
152
|
+
FileUtils.mkdir_p(GLOBAL_CONF_PATHS[platform])
|
153
|
+
File.open(global_conf_file,'w') do |f|
|
154
|
+
f.write(File.read(File.join(File.dirname(__FILE__),'..','..','config','elscripto.conf.yml')))
|
155
|
+
end
|
156
|
+
puts "Wrote global configuration to #{global_conf_file}".yellow
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
class << self
|
162
|
+
def init!
|
163
|
+
if File.exists?(CONFIG_FILE)
|
164
|
+
raise Elscripto::AlreadyInitializedError.new
|
165
|
+
else
|
166
|
+
File.open(CONFIG_FILE,'w') do |f|
|
167
|
+
f.write File.read(File.join(File.dirname(__FILE__),'..','..','config','elscripto.init.yml')).gsub('{{GLOBAL_CONF_PATH}}',self.global_conf_path)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def is_gnome?
|
173
|
+
system('which gnome-terminal > /dev/null')
|
174
|
+
end
|
175
|
+
|
176
|
+
def is_kde?
|
177
|
+
system('which konsole > /dev/null')
|
178
|
+
end
|
179
|
+
|
180
|
+
def global_conf_path
|
181
|
+
Elscripto::GLOBAL_CONF_PATHS[self.get_platform(RbConfig::CONFIG['host_os'])]
|
182
|
+
end
|
183
|
+
|
184
|
+
# Determine the platform we're running on
|
185
|
+
def get_platform(host_os)
|
186
|
+
return :osx if host_os =~ /darwin/
|
187
|
+
return :linux if host_os =~ /linux/
|
188
|
+
return :windows if host_os =~ /mingw32|mswin32/
|
189
|
+
return :unknown
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Elscripto
|
2
|
+
class Command
|
3
|
+
attr_reader :name, :system_call
|
4
|
+
|
5
|
+
def initialize name, options = {}
|
6
|
+
raise ArgumentError.new 'Elscripto commands need a name spectacularrr' if blank? name
|
7
|
+
@name = name
|
8
|
+
@system_call = blank?(options[:command]) ? builtin_commands[name] : options.delete(:command)
|
9
|
+
raise ArgumentError.new 'Elscripto commands need a command spectacularrr' if blank? @system_call
|
10
|
+
end
|
11
|
+
protected
|
12
|
+
def builtin_commands
|
13
|
+
return @commands if @commands
|
14
|
+
@commands = {}
|
15
|
+
Dir[File.join(Elscripto::App.global_conf_path,'*.conf')].each do |file|
|
16
|
+
@commands.merge! YAML.load_file(file)
|
17
|
+
end
|
18
|
+
@commands
|
19
|
+
end
|
20
|
+
|
21
|
+
def blank? var
|
22
|
+
var == '' or var.nil? or var == []
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/elscripto.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'elscripto'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
describe Elscripto::Command do
|
5
|
+
before {
|
6
|
+
@platform = Elscripto::App.get_platform(RbConfig::CONFIG['host_os'])
|
7
|
+
FileUtils.mkdir_p(Elscripto::GLOBAL_CONF_PATHS[@platform])
|
8
|
+
@custom_config_path = File.join(Elscripto::GLOBAL_CONF_PATHS[@platform],'custom.conf')
|
9
|
+
|
10
|
+
File.open(@custom_config_path,'w') do |f|
|
11
|
+
f.write(File.read(File.join('spec','files','custom.conf')))
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
after { File.delete(@custom_config_path) }
|
16
|
+
|
17
|
+
it { expect { Elscripto::Command.new('test_custom_conf_files') }.to_not raise_error }
|
18
|
+
it { Elscripto::Command.new('test_custom_conf_files').system_call.should eq('this is a command') }
|
19
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'elscripto'
|
2
|
+
describe Elscripto::App do
|
3
|
+
describe 'init!' do
|
4
|
+
before {
|
5
|
+
@conf_file = File.join('.','.elscripto')
|
6
|
+
Elscripto::App.init!
|
7
|
+
}
|
8
|
+
after { File.delete(@conf_file) }
|
9
|
+
|
10
|
+
it { File.exists?(@conf_file) }
|
11
|
+
it { expect { YAML.load(@conf_file) }.to_not raise_error }
|
12
|
+
it { File.read(@conf_file).include?(Elscripto::App.global_conf_path).should eq(true) }
|
13
|
+
|
14
|
+
it 'should not initialize twice' do
|
15
|
+
expect { Elscripto::App.init! }.to raise_error(Elscripto::AlreadyInitializedError)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { Elscripto::App.new 'spec/files/sample_options.yml', :enviroment => :development }
|
20
|
+
|
21
|
+
describe 'with valid options' do
|
22
|
+
it { subject.commands.size.should eq(4) }
|
23
|
+
it { subject.commands.first.system_call.should eq('spork') }
|
24
|
+
it { subject.commands[1].system_call.should eq('autotest') }
|
25
|
+
it { subject.commands[2].system_call.should eq('rails s') }
|
26
|
+
it { subject.commands.last.system_call.should eq('rails c') }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'with invalid options' do
|
30
|
+
subject { Elscripto::App.new 'spec/files/nonexistent_command.yml' }
|
31
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'with inline command input' do
|
35
|
+
subject { Elscripto::App.new 'spec/files/new_definition.yml' }
|
36
|
+
it { subject.commands.last.system_call.should eq('rake log:clear') }
|
37
|
+
it { subject.commands.last.name.should eq('rails:logs') }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'platform recongition' do
|
41
|
+
it { subject.class.get_platform("darwin10.8.0").should eq(:osx) }
|
42
|
+
it { subject.class.get_platform("x86_64-linux").should eq(:linux) }
|
43
|
+
it { subject.class.get_platform("mswin32").should eq(:windows) }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'exec!' do
|
47
|
+
before { subject.exec! }
|
48
|
+
it 'generate the correct output depending on platform' do
|
49
|
+
platform = Elscripto::App.get_platform(RbConfig::CONFIG['host_os'])
|
50
|
+
case platform
|
51
|
+
when :os
|
52
|
+
subject.generated_script.should eq(File.read('spec/files/osascript.txt'))
|
53
|
+
when :linux
|
54
|
+
if Elscripto::App.is_gnome?
|
55
|
+
subject.generated_script.should eq(File.read('spec/files/gnome-script.txt'))
|
56
|
+
elsif Elscripto::App.is_kde?
|
57
|
+
subject.generated_script.should eq(File.read('spec/files/kde-script.txt'))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'on an unsupported platform' do
|
63
|
+
before { subject.platform = :windows }
|
64
|
+
it { expect { subject.exec! }.to raise_error(Elscripto::UnsupportedOSError) }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "with no definitions" do
|
68
|
+
it { expect { Elscripto::App.new('spec/files/empty.yml') }.to raise_error(Elscripto::NoDefinitionsError) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
gnome-terminal --tab --title 'spork' -e 'spork' --tab --title 'autotest' -e 'autotest' --tab --title 'rails:server' -e 'rails s' --tab --title 'rails:console' -e 'rails c'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
CDCMD='cd /home/achilles/elscripto'
|
2
|
+
elCommands=('spork' 'autotest' 'rails s' 'rails c')
|
3
|
+
for i in "${elCommands[@]}"
|
4
|
+
do
|
5
|
+
session=$(qdbus org.kde.konsole /Konsole newSession)
|
6
|
+
qdbus org.kde.konsole /Sessions/${session} sendText "${CDCMD}"
|
7
|
+
qdbus org.kde.konsole /Sessions/${session} sendText $'
|
8
|
+
'
|
9
|
+
qdbus org.kde.konsole /Sessions/${session} sendText "${i}"
|
10
|
+
qdbus org.kde.konsole /Sessions/${session} sendText $'
|
11
|
+
'
|
12
|
+
qdbus org.kde.konsole /Sessions/${session} setMonitorActivity true
|
13
|
+
done
|
@@ -0,0 +1,11 @@
|
|
1
|
+
tell application "Terminal"
|
2
|
+
activate
|
3
|
+
tell application "System Events" to keystroke "t" using command down
|
4
|
+
do script "clear && echo \"-- Running spork Spectacularrr --\" && spork" in front window
|
5
|
+
tell application "System Events" to keystroke "t" using command down
|
6
|
+
do script "clear && echo \"-- Running autotest Spectacularrr --\" && autotest" in front window
|
7
|
+
tell application "System Events" to keystroke "t" using command down
|
8
|
+
do script "clear && echo \"-- Running rails:server Spectacularrr --\" && rails s" in front window
|
9
|
+
tell application "System Events" to keystroke "t" using command down
|
10
|
+
do script "clear && echo \"-- Running rails:console Spectacularrr --\" && rails c" in front window
|
11
|
+
end tell
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elscripto
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Achilles Charmpilas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-01 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nutrun-string
|
16
|
+
requirement: &2152682660 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152682660
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2164735980 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2164735980
|
36
|
+
description: Console window group automation for developers
|
37
|
+
email:
|
38
|
+
- ac@humbuckercode.co.uk
|
39
|
+
executables:
|
40
|
+
- elscripto
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- .travis.yml
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE.txt
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- bin/elscripto
|
51
|
+
- config/elscripto.conf.yml
|
52
|
+
- config/elscripto.init.yml
|
53
|
+
- elscripto.gemspec
|
54
|
+
- lib/elscripto.rb
|
55
|
+
- lib/elscripto/app.rb
|
56
|
+
- lib/elscripto/command.rb
|
57
|
+
- lib/elscripto/version.rb
|
58
|
+
- spec/command_spec.rb
|
59
|
+
- spec/elscripto_spec.rb
|
60
|
+
- spec/files/custom.conf
|
61
|
+
- spec/files/empty.yml
|
62
|
+
- spec/files/gnome-script.txt
|
63
|
+
- spec/files/kde-script.txt
|
64
|
+
- spec/files/new_definition.yml
|
65
|
+
- spec/files/nonexistent_command.yml
|
66
|
+
- spec/files/osascript.txt
|
67
|
+
- spec/files/sample_options.yml
|
68
|
+
homepage: http://github.com/Achillefs/elscripto
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project: elscripto
|
89
|
+
rubygems_version: 1.8.10
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Console window group automation for developers
|
93
|
+
test_files:
|
94
|
+
- spec/command_spec.rb
|
95
|
+
- spec/elscripto_spec.rb
|
96
|
+
- spec/files/custom.conf
|
97
|
+
- spec/files/empty.yml
|
98
|
+
- spec/files/gnome-script.txt
|
99
|
+
- spec/files/kde-script.txt
|
100
|
+
- spec/files/new_definition.yml
|
101
|
+
- spec/files/nonexistent_command.yml
|
102
|
+
- spec/files/osascript.txt
|
103
|
+
- spec/files/sample_options.yml
|