dotrun 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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +78 -0
  3. data/bin/dotrun +4 -0
  4. data/lib/dotrun.rb +108 -0
  5. metadata +65 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d30a89973859aef0fcbddae7d70afa665fdf4d0
4
+ data.tar.gz: d3c63f1014c587e9ddd182e6880daf1e25cb7d73
5
+ SHA512:
6
+ metadata.gz: 376b7ad9fa17b681cee2c7e76ff3be0177a76ec2340889364c1572d2f71338297c192bced49cf43dbcb58282b9f05c8fec9b486b6b0a39da5057b973d4b40fe3
7
+ data.tar.gz: f4ddfe997fb2e639a6f60642e311cee4f561e68caa57f5b8d3a67062bffdcfa45bddb8292b58e1d125561f19c85d50c4a6930c3a3490abdd9d5836c435f2eefd
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # dotrun
2
+ A super simple app runner script
3
+
4
+ ## The Problem
5
+ Every app I work on seems to have a different way of running it, and I couldn't keep track. I wanted to be able to navigate to any app directory in the terminal and run a simple command to launch the app in focus.
6
+
7
+ ## The Solution
8
+ This simple ruby script expects a file called `.run` in the current directory with an instruction to execute. Put the script somewhere on your machine, make it executable with `chmod +x` and symlink it to somewhere in your path (e.g., `ln -s /usr/local/dotrun /path/to/dotrun.rb`) and you can run it from anywhere that you've defined a `.run` file.
9
+
10
+ Simply navigate to the directory of your app, and run
11
+ ```
12
+ dotrun
13
+ ```
14
+ and it will run the command you've specified. It will also clear your terminal and tell you some useful information like the current git branch, and hitting `Ctrl+C` will terminate the process (gracefully, hopefully).
15
+
16
+ For even more usefulness, you can provide multiple commands in the file to specify different things to launch. For example:
17
+
18
+ ```yaml
19
+ server: unicorn_rails --host 127.0.0.1
20
+ console: rails c
21
+ sidekiq: bundle exec sidekiq
22
+ log: tail -f log/development.log
23
+ ```
24
+
25
+ You can then run
26
+ ```
27
+ dotrun server
28
+ ```
29
+ to run the unicorn script above.
30
+
31
+ ### List directives
32
+ To get a list of possible directives for the current directory:
33
+ ```
34
+ dotrun -?
35
+ ```
36
+
37
+ ### Run multiple commands at once
38
+ **This feature requires that [ttab](https://www.npmjs.com/package/ttab) is installed.** Run multiple commands in different tabs of your terminal window by specifying an array of commands in your `.run` directives file. For example:
39
+
40
+ ```yaml
41
+ default:
42
+ - server
43
+ - log
44
+ - console
45
+ server: unicorn_rails --host 127.0.0.1
46
+ console: rails c
47
+ log: tail -f log/development.log
48
+ ```
49
+
50
+ When you run `dotrun` in this case, each command will open up in a new terminal tab. You can also specify many of these multi-directives by including other array items in the yaml configuration.
51
+
52
+ ---
53
+
54
+ ## License
55
+ Feel free to use this if you think it might be valuable to you! This is free and unencumbered software released into the public domain.
56
+
57
+ Anyone is free to copy, modify, publish, use, compile, sell, or
58
+ distribute this software, either in source code form or as a compiled
59
+ binary, for any purpose, commercial or non-commercial, and by any
60
+ means.
61
+
62
+ In jurisdictions that recognize copyright laws, the author or authors
63
+ of this software dedicate any and all copyright interest in the
64
+ software to the public domain. We make this dedication for the benefit
65
+ of the public at large and to the detriment of our heirs and
66
+ successors. We intend this dedication to be an overt act of
67
+ relinquishment in perpetuity of all present and future rights to this
68
+ software under copyright law.
69
+
70
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
71
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
73
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
74
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
75
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
76
+ OTHER DEALINGS IN THE SOFTWARE.
77
+
78
+ For more information, please refer to <http://unlicense.org>
data/bin/dotrun ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dotrun'
4
+ Dotrun.new.run(ARGV[0])
data/lib/dotrun.rb ADDED
@@ -0,0 +1,108 @@
1
+ require 'yaml'
2
+ require 'colorize'
3
+
4
+ class Dotrun
5
+
6
+ DIRECTIVES_PATH = ".run"
7
+
8
+ # The main operation method. This is called when running `dotrun` from the command line.
9
+ def run(*args)
10
+ print_help_and_exit if args.first == "-?"
11
+ directive = args.first || "default"
12
+ command = command_for(directive)
13
+
14
+ if command.is_a?(Array)
15
+ exec_multiple_directives directive, command
16
+ else
17
+ exec_directive directive, command
18
+ end
19
+ end
20
+
21
+ protected
22
+
23
+ # Prints out the usage instructions and available command directives for the current directory.
24
+ def print_help_and_exit
25
+ puts "Usage: dotrun [directive]\n".light_black
26
+ print "Available directives for ".blue
27
+ print "#{File.basename(File.expand_path("."))}".blue.bold
28
+ puts ":".blue
29
+ for key, command in directives
30
+ print " #{key.to_s.ljust(10)}".magenta
31
+ print " -> ".light_black
32
+ command_string = "#{command.length > 60 ? (command[0..60] + "...".light_black) : command}"
33
+ puts command.is_a?(Array) ? command.join(", ").magenta : command_string
34
+ end
35
+ puts ""
36
+ exit
37
+ end
38
+
39
+ # Clears the screen, prints a header, and the git branch (if available).
40
+ def prep_screen
41
+ system("clear")
42
+ print "Current project is ".blue
43
+ print "#{File.basename(File.expand_path("."))}".blue.on_light_white
44
+
45
+ if File.exist?(".git")
46
+ branch = `git rev-parse --abbrev-ref HEAD`
47
+ print " (current branch: ".blue
48
+ print branch.strip.blue.on_light_white
49
+ print ")".blue
50
+ end
51
+ puts ""
52
+ end
53
+
54
+ # Execute one of the directives in the list from the `.run` file.
55
+ def exec_directive(directive, command)
56
+ prep_screen
57
+ puts "Running #{directive} directive: \"#{command}\"...".green
58
+ puts "Use Ctrl-C to stop".green
59
+ puts ""
60
+ trap( :INT ) { puts "Terminating...".magenta }
61
+
62
+ fork { exec command }
63
+ Process.wait
64
+ puts "All done.\r\n".light_blue
65
+ end
66
+
67
+ # Execute multiple commands in multiple tabs using `ttab`
68
+ def exec_multiple_directives(directive, command)
69
+ check_for_ttab
70
+ prep_screen
71
+ puts "\n\n\n"
72
+ puts "Running multiple directives in separate tabs:".green
73
+ for d in command
74
+ print " #{d}".ljust(20).magenta
75
+ sleep 2
76
+ system %(ttab -G eval "dotrun #{d}; exit")
77
+ puts " ✔︎".magenta
78
+ end
79
+ puts ""
80
+ puts "Running!\r\n".light_blue
81
+ end
82
+
83
+ # Returns all of the directives as a Ruby object.
84
+ def directives
85
+ @directives ||= load_directives
86
+ end
87
+
88
+ # Convenience method for fetching the command designated for the specified directive.
89
+ def command_for(directive)
90
+ directives[directive] || abort("Couldn't find the `#{directive}` directive in your config.\r\n".red)
91
+ end
92
+
93
+ # Load up the `.run` file from the current directory and populate the @directives instance variable.
94
+ def load_directives
95
+ abort("No .run file detected in current directory.\r\n".red) unless File.exist?(DIRECTIVES_PATH)
96
+ loaded = YAML.load_file(DIRECTIVES_PATH)
97
+ @directives = loaded.is_a?(String) ? { default: loaded } : loaded
98
+ end
99
+
100
+ # Checks if the `ttab` utility exists on the machine and errors out if not.
101
+ def check_for_ttab
102
+ msg = "It doesn't appear that ttab is installed. Please run "
103
+ msg << "npm install ttab -g ".bold
104
+ msg << "\r\nto install the utility in order to use the multi-command feature."
105
+ abort(msg.red) unless system("which ttab")
106
+ end
107
+
108
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotrun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Harris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A simple app runner tool
28
+ email: matt@dreamsis.com
29
+ executables:
30
+ - dotrun
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - bin/dotrun
36
+ - lib/dotrun.rb
37
+ homepage: https://github.com/mattharris5/dotrun
38
+ licenses:
39
+ - Unlicense
40
+ metadata: {}
41
+ post_install_message: "\e[1;94;49m\r\n** Important dependency note for dotrun gem**\e[0m\r\n\e[0;94;49mIf
42
+ you want to load multiple commands in separate tabs, you need to install ttab first.
43
+ For simplicity, this tool is not included in this package. (Sorry! If anyone makes
44
+ a ruby port let me know.) Use `npm install ttab -g` to easily install this useful
45
+ utility.\r\n\e[0m"
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.4.8
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Simply run your app
65
+ test_files: []