Last active
April 26, 2022 12:05
-
-
Save dev4dev/c39049f3707263acaaebd3f28ae1e531 to your computer and use it in GitHub Desktop.
omzsh xcode verison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open3' | |
# swift version | |
def swift_version(format = "Swift %{v}") | |
output, _, _ = Open3.capture3('swift --version') | |
match = output.split("\n").first.match('version (\d\.\d)') | |
if match.size > 0 | |
format % {v: match[match.size - 1]} | |
else | |
"" | |
end | |
end | |
# xcode version | |
def xcode_version(format = "Xcode %{v}") | |
path, _, _ = Open3.capture3('xcode-select -p') | |
info = File.absolute_path("#{path.strip}/../Info.plist") | |
version, _, _ = Open3.capture3("defaults read #{info} CFBundleShortVersionString") | |
version.strip! | |
if version.empty? | |
"" | |
else | |
format % {v: version} | |
end | |
end | |
fmt = ARGV.first || "full" | |
case fmt | |
when "short" | |
xc_fmt = "%{v}" | |
sw_fmt = "%{v}" | |
when "medium" | |
xc_fmt = "xc %{v}" | |
sw_fmt = "sw %{v}" | |
when "full" | |
xc_fmt = "Xcode %{v}" | |
sw_fmt = "Swift %{v}" | |
end | |
puts [xcode_version(xc_fmt), swift_version(sw_fmt)].map(&:strip).filter { |v| !v.empty? }.join("/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment