Skip to content

Instantly share code, notes, and snippets.

@dev4dev
Last active April 26, 2022 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dev4dev/c39049f3707263acaaebd3f28ae1e531 to your computer and use it in GitHub Desktop.
Save dev4dev/c39049f3707263acaaebd3f28ae1e531 to your computer and use it in GitHub Desktop.
omzsh xcode verison
#!/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