workon 0.0.12 → 0.0.13

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 CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .redcar/
6
+ tags
data/lib/workon.rb CHANGED
@@ -5,7 +5,7 @@ require 'workon/actor'
5
5
  require "workon/version"
6
6
 
7
7
  module Workon
8
- WORK_DIRS = '/Users/mike/Work/*/*'
8
+ WORK_DIRS = (ENV['WORKON_ROOT'] || ENV['HOME'] + '/Work') + '/*/*'
9
9
 
10
10
  def self.all_directories
11
11
  @_all_directories ||= Dir[WORK_DIRS]
@@ -38,8 +38,6 @@ module Workon
38
38
  Workon::Actor.ordered.each do |klass|
39
39
  klass.new(project_path).commit
40
40
  end
41
-
42
- Workon::CLI::Commands::InstallHelper.helper_message(project_path)
43
41
  end
44
42
 
45
43
  def self.load_configuration(args)
data/lib/workon/actor.rb CHANGED
@@ -36,7 +36,7 @@ module Workon
36
36
  end
37
37
 
38
38
  require 'workon/actor/base'
39
- require 'workon/actor/text_mate'
39
+ require 'workon/actor/editor'
40
40
  require 'workon/actor/web_browser'
41
41
  require 'workon/actor/finder'
42
42
  require 'workon/actor/git'
@@ -52,19 +52,19 @@ module Workon
52
52
  end
53
53
 
54
54
  def commit
55
- run command
55
+ run command unless command.nil? || command.empty?
56
56
  end
57
57
 
58
- def system(command)
58
+ def run(command)
59
59
  puts "Running #{command}"
60
- Kernel.system command
60
+ Kernel.system command unless options[:dry_run]
61
61
  end
62
62
 
63
63
  def has_command?(command)
64
- !`command -v #{command}`.empty?
64
+ !`command -v '#{command}'`.empty?
65
65
  end
66
66
 
67
- def run(command)
67
+ def capture(command)
68
68
  puts "Running #{command}"
69
69
  output = %x(#{command}) unless options[:dry_run]
70
70
  return output
@@ -116,6 +116,12 @@ module Workon
116
116
  def tmux_window
117
117
  self.class.actor_name.downcase
118
118
  end
119
+
120
+ def open_with_default(thing)
121
+ $open_command ||= has_command?('xdg-open') ? 'xdg-open' : 'open'
122
+
123
+ "#{$open_command} #{thing}"
124
+ end
119
125
  end
120
126
  end
121
127
  end
@@ -0,0 +1,10 @@
1
+ module Workon
2
+ module Actor
3
+ class Editor < Base
4
+ def command
5
+ editor = [ ENV['WORKON_EDITOR'], ENV['EDITOR'] ].find {|e| !e.nil? && !e.empty? }
6
+ "#{editor} #{path}" if editor
7
+ end
8
+ end
9
+ end
10
+ end
@@ -2,7 +2,7 @@ module Workon
2
2
  module Actor
3
3
  class Finder < Base
4
4
  def command
5
- "open #{path}"
5
+ open_with_default path
6
6
  end
7
7
  end
8
8
  end
@@ -8,8 +8,9 @@ module Workon
8
8
  host_name = fetch_option :host, %{#{project}.local}
9
9
  port_number = fetch_option :port, nil
10
10
 
11
- command, qualified = port_number.nil? ? ping_test(host_name) : netstat_test(port_number)
12
- %{#{command} && open http://#{qualified}}
11
+ command, qualified = port_number.nil? ? ping_test(host_name) : netstat_test(port_number)
12
+ opener = open_with_default "http://#{qualified}"
13
+ %(#{command} && #{opener})
13
14
  end
14
15
 
15
16
  private
data/lib/workon/cli.rb CHANGED
@@ -20,6 +20,11 @@ module Workon
20
20
 
21
21
  Workon.find_project
22
22
 
23
+ if config[:show_project]
24
+ puts Workon.project_path
25
+ exit
26
+ end
27
+
23
28
  if config[:dump_configuration]
24
29
  Workon::Configuration.instance.dump_to_project_rc
25
30
  exit
@@ -30,35 +30,21 @@ module Workon
30
30
  end
31
31
 
32
32
  def self.finder
33
- "# Created by workon version #{Workon::VERSION}\n"
33
+ "# Created by workon\n"
34
34
  end
35
35
 
36
36
  def self.installed?
37
37
  !(File.read(bash_profile_path) =~ /#{finder}/).nil?
38
38
  end
39
39
 
40
- def self.helper_message(path)
41
- lines = [ "This is for the bash helper function",
42
- "cd #{path}" ]
43
-
44
- lines.each {|l| puts l } if installed?
45
- end
46
-
47
40
  def self.helper_function
48
41
  <<'BASH'
49
42
  wo () {
50
- OLDIFS=$IFS
51
- IFS=$'\n'
52
-
53
- workon_bin=$(which workon)
54
- output=$($workon_bin $@)
55
-
56
- for line in $output; do
57
- echo $line
58
- done
43
+ PROJECT=${!#}
44
+ PROJECT_PATH=$(workon -P ${PROJECT})
59
45
 
60
- eval $line
61
- IFS=$OLDIFS
46
+ workon $@
47
+ eval "cd $PROJECT_PATH"
62
48
  }
63
49
  BASH
64
50
  end
@@ -11,7 +11,7 @@ module Workon
11
11
  end
12
12
 
13
13
  def initialize(*args)
14
- @options = { without: [], only: [], install_helper: false, dump_configuration: false, project: nil, show_help: false }
14
+ @options = { show_project: false, without: [], only: [], install_helper: false, dump_configuration: false, project: nil, show_help: false }
15
15
  parse_options args.first unless args.empty?
16
16
  end
17
17
 
@@ -68,6 +68,10 @@ module Workon
68
68
  options[:install_helper] = true
69
69
  end
70
70
 
71
+ o.on_tail('-P', '--show-project', TrueClass, "Echo project's directory") do
72
+ options[:show_project] = true
73
+ end
74
+
71
75
  o.on_tail('-n', '--dry-run', 'Do not run any commands') do
72
76
  options[:dry_run] = true
73
77
  end
@@ -1,3 +1,3 @@
1
1
  module Workon
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: workon
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.12
5
+ version: 0.0.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mike Wyatt
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-10 00:00:00 Z
13
+ date: 2011-05-29 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: Runs actions based on directories
@@ -31,11 +31,11 @@ files:
31
31
  - lib/workon.rb
32
32
  - lib/workon/actor.rb
33
33
  - lib/workon/actor/base.rb
34
+ - lib/workon/actor/editor.rb
34
35
  - lib/workon/actor/finder.rb
35
36
  - lib/workon/actor/git.rb
36
37
  - lib/workon/actor/middleman.rb
37
38
  - lib/workon/actor/passenger.rb
38
- - lib/workon/actor/text_mate.rb
39
39
  - lib/workon/actor/watchr.rb
40
40
  - lib/workon/actor/web_browser.rb
41
41
  - lib/workon/cli.rb
@@ -1,9 +0,0 @@
1
- module Workon
2
- module Actor
3
- class TextMate < Base
4
- def command
5
- "mate #{path}"
6
- end
7
- end
8
- end
9
- end