xcselect 0.0.6

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 ADDED
@@ -0,0 +1,2 @@
1
+ .bundle
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in xcselect.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ Basic usage
2
+
3
+ $ xcselect
4
+ Please Select an Xcode install ?
5
+
6
+ [1] Xcode 4.1 (4B110) /Developer
7
+ [2] Xcode 4.2 (4D5163b) /Xcode42 [current]
8
+
9
+ Selection:
10
+
11
+
12
+ Use -a to switch to the next xcode
13
+
14
+ xcselect -a
15
+
16
+ use show -s to print info about the current xcode
17
+
18
+ xcselect -s
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/xcselect ADDED
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'xcselect'
6
+ require 'optparse'
7
+
8
+ class String
9
+ def red; colorize(self, "\e[1m\e[31m"); end
10
+ def dark_red; colorize(self, "\e\[31m"); end
11
+ def green; colorize(self, "\e[1m\e[32m"); end
12
+ def dark_green; colorize(self, "\e[32m"); end
13
+ def yellow; colorize(self, "\e[1m\e[33m"); end
14
+ def dark_yellow; colorize(self, "\e[33m"); end
15
+ def blue; colorize(self, "\e[1m\e[34m"); end
16
+ def dark_blue; colorize(self, "\e[34m"); end
17
+ def pur; colorize(self, "\e[1m\e[35m"); end
18
+ def dark_pur; colorize(self, "\e[35m"); end
19
+ def colorize(text, color_code)
20
+ (STDIN.tty?) ? "#{color_code}#{text}\e[0m" : text
21
+ end
22
+
23
+ def numeric?
24
+ true if Float(self) rescue false
25
+ end
26
+ end
27
+
28
+ include Xcselect
29
+
30
+ class Main
31
+ attr_accessor :xcodes, :current
32
+ attr_reader :exit_code
33
+ def initialize
34
+ @exit_code = 0
35
+ optparse = OptionParser.new do |opts|
36
+ opts.on('-h', '--help', "Display this !!") { puts opts; exit }
37
+ opts.on('-a', '--alt' , "Alternate through all installs") { select_next() ;exit}
38
+ opts.on('-s', '--show' , "Show Current") { show_current(); exit }
39
+ opts.on('-o', '--open' , "Open *.xcodeproj") { open_xcode(); exit }
40
+ end
41
+ begin
42
+ optparse.parse!
43
+ rescue OptionParser::InvalidOption => e
44
+ puts "Invalid Option"
45
+ puts optparse
46
+ exit 2
47
+ end
48
+
49
+ optparse.parse!
50
+
51
+ begin
52
+ load_xcodes
53
+ show_menu
54
+ rescue OptionParser::MissingArgument => e
55
+ puts e
56
+ return nil
57
+ rescue Exception => e
58
+ puts e
59
+ puts e.backtrace
60
+ return
61
+ end
62
+ end
63
+
64
+ def select_next
65
+ load_xcodes
66
+ if xcodes.size > 1
67
+ cur_index = xcodes.index(current)
68
+ next_index = (cur_index + 1) % xcodes.size
69
+ set_current xcodes[next_index]
70
+ end
71
+
72
+ exit
73
+ end
74
+
75
+ def open_xcode
76
+ xcodepath = "#{Xcode.current_xcode}/Applications/Xcode.app"
77
+ puts "Opening Xcode in #{Xcode.current_xcode}"
78
+ `open -a #{xcodepath} *.xcodeproj`
79
+ end
80
+
81
+ # don't show line to ask for sudo pass
82
+ def self.require_sudo_pass?
83
+ `sudo -n echo 1 2>&1`.chomp != "1"
84
+ end
85
+
86
+ def set_current xc
87
+ cmd = "sudo xcode-select -switch #{xc.folder}"
88
+ if Main.require_sudo_pass?
89
+ puts "Enter sudo password to select #{xc}"
90
+ puts "$ #{cmd}"
91
+ end
92
+ `#{cmd}`
93
+ puts "Set Xcode to #{xc}"
94
+ end
95
+
96
+ def show_current()
97
+ cur = Xcode.new(Xcode.current_xcode)
98
+ puts cur
99
+ puts cur.sdks
100
+ end
101
+
102
+ def console_availale
103
+ STDIN.tty?
104
+ end
105
+
106
+ def select_line x
107
+ "#{x.version} (#{x.build}) #{x.folder} #{'[current]'.red if x.eql? current}"
108
+ end
109
+ def show_menu
110
+ puts "Please Select an Xcode install ?\n\n"
111
+ i = 0;
112
+ xopts = xcodes.each do |x|
113
+ select_no = "[#{i+=1}]"
114
+ puts " #{select_no} Xcode #{select_line x}"
115
+ end
116
+ print "\nSelection: "
117
+ begin
118
+ return unless console_availale
119
+ input = STDIN.gets
120
+ input = input.to_i
121
+
122
+ if input.zero? or input > xcodes.size
123
+ puts "Invalid Selection"
124
+ @exit_code = 1
125
+ elsif xcodes[input - 1].eql?(current)
126
+ puts "Already Current"
127
+ @exit_code = 2
128
+ else
129
+ set_current xcodes[input - 1]
130
+ end
131
+ rescue SystemExit, Interrupt
132
+ puts ""
133
+ return
134
+ end
135
+ end
136
+
137
+ def find_all_with_activity_indicator
138
+ tmp_xcodes = nil;
139
+ search_thread = Thread.new { tmp_xcodes = Xcode.find_all }
140
+ display_thread = Thread.new do
141
+ sleep 0.4
142
+ if tmp_xcodes.nil?
143
+ print "Searching Spotlight "
144
+ while tmp_xcodes.nil?
145
+ print "."
146
+ sleep 0.4
147
+ end
148
+ print "\n"
149
+ end
150
+ end
151
+
152
+ search_thread.join
153
+ display_thread.join
154
+
155
+ return tmp_xcodes
156
+ end
157
+
158
+ def load_xcodes
159
+ @xcodes = find_all_with_activity_indicator
160
+ @current = xcodes.select {|x| x.folder == Xcode.current_xcode}.first
161
+ end
162
+
163
+ def to_s
164
+ "xcodes = #{xcodes}\n current = #{current}"
165
+ end
166
+
167
+
168
+ end
169
+
170
+ main = Main.new
171
+
172
+ exit main.exit_code
@@ -0,0 +1,3 @@
1
+ module Xcselect
2
+ VERSION = "0.0.6"
3
+ end
@@ -0,0 +1,54 @@
1
+
2
+ module Xcselect
3
+
4
+
5
+ class Xcode
6
+ include Comparable
7
+ attr_accessor :folder, :version, :build
8
+ def initialize(fld)
9
+ @folder = fld
10
+ ver_output = `#{xcodebuild_path} -version`
11
+ @version = ver_output.match(/Xcode (.*)$/)[1]
12
+ @build = ver_output.match(/Build version (.*)$/)[1]
13
+ end
14
+
15
+ def xcodebuild_path
16
+ "#{folder}/usr/bin/xcodebuild"
17
+ end
18
+
19
+ def to_s
20
+ "Xcode: #{folder} - #{version} (#{build})"
21
+ end
22
+
23
+ # Get an array of all installed xcode objects
24
+ def self.find_all
25
+ xcode_builds = `mdfind -name xcodebuild`.chomp.split
26
+ #TODO: move this checking to init method
27
+ xcode_builds = xcode_builds.select {|x| x =~ /\/xcodebuild$/ && !(x =~ /^\/(Volumes|usr\/bin\/)/) && File.exists?(x) }
28
+ xcode_objs = xcode_builds.map {|p| Xcode.new p.sub( /\/usr\/bin.*/, '').chomp.strip }
29
+ xcode_objs.sort
30
+ end
31
+
32
+ def self.current_xcode
33
+ `xcode-select -print-path`.chomp
34
+ end
35
+
36
+ def eql?(o)
37
+ return false if o.nil?
38
+ return (o.folder == folder && o.version == version && o.build == build)
39
+ end
40
+
41
+ def sdks
42
+ `#{xcodebuild_path} -showsdks`
43
+ end
44
+
45
+ # sort by version number and fallback to build number after
46
+ def <=>(o)
47
+ res = version.to_f <=> o.version.to_f
48
+ return res == 0 ? o.build <=> build : res;
49
+ end
50
+
51
+ end
52
+
53
+
54
+ end
data/lib/xcselect.rb ADDED
@@ -0,0 +1,7 @@
1
+
2
+ module Xcselect
3
+
4
+ require "xcselect/xcode"
5
+ require "xcselect/version"
6
+
7
+ end
Binary file
Binary file
Binary file
Binary file
data/xcselect.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "xcselect/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "xcselect"
7
+ s.version = Xcselect::VERSION
8
+ s.authors = ["Kim Hunter"]
9
+ s.email = ["bigkm1@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{xcselect - Xcode Select}
12
+ s.description = %q{A more user friendly interface to the xcode-select command showing more info}
13
+
14
+ s.rubyforge_project = "xcselect"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xcselect
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 6
9
+ version: 0.0.6
10
+ platform: ruby
11
+ authors:
12
+ - Kim Hunter
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-11-30 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A more user friendly interface to the xcode-select command showing more info
22
+ email:
23
+ - bigkm1@gmail.com
24
+ executables:
25
+ - xcselect
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.md
34
+ - Rakefile
35
+ - bin/xcselect
36
+ - lib/xcselect.rb
37
+ - lib/xcselect/version.rb
38
+ - lib/xcselect/xcode.rb
39
+ - pkg/xcselect-0.0.1.gem
40
+ - pkg/xcselect-0.0.3.gem
41
+ - pkg/xcselect-0.0.4.gem
42
+ - pkg/xcselect-0.0.5.gem
43
+ - xcselect.gemspec
44
+ has_rdoc: true
45
+ homepage: ""
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project: xcselect
72
+ rubygems_version: 1.3.7
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: xcselect - Xcode Select
76
+ test_files: []
77
+