Last active
April 20, 2025 01:06
-
-
Save trueheart78/223b2874bd495b6c9d73befd3a1aa416 to your computer and use it in GitHub Desktop.
Kitty version checker πββ¬
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 | |
# full path to a custom icns file | |
CUSTOM_ICNS = false | |
CUSTOM_ICNS_FILE = "" | |
require "colorize" | |
require "optparse" | |
def options | |
return @options unless @options.nil? | |
@options = {} | |
OptionParser.new do |parser| | |
parser.banner = "Usage: kitty-update-check [options]" | |
parser.on("-f", "--force", "Force the update install regardless of version mismatch") do |f| | |
options[:force] = f | |
end | |
parser.on("-d", "--dry-run", "Perform a dry run without installing or updating anything") do |d| | |
options[:dry_run] = d | |
end | |
parser.on("-i", "--icns", "Update the app to use the custom icns file (defined in the script)") do |i| | |
options[:icns] = i | |
end | |
parser.on("-h", "--help", "Prints this help") do | |
puts parser | |
exit | |
end | |
end.parse! | |
@options | |
end | |
def dry_run? | |
options[:dry_run] == true | |
end | |
def forcing? | |
options[:force] == true | |
end | |
def updating_icns? | |
options[:icns] == true | |
end | |
# => "0.40.1" | |
def installed_version | |
@installed_version ||= `command kitty --version`.match(%r:(\d+\.\d+\.\d+):)[1] | |
end | |
# => "0.41.0" | |
def current_version | |
@constants_py ||= `command curl --silent https://raw.githubusercontent.com/kovidgoyal/kitty/master/kitty/constants.py` | |
@constants_py.match(%r:Version\((\d+, \d+, \d+)\)$:)[1].split(',').map(&:to_i).join('.') | |
end | |
def perform_install? | |
return true if forcing? | |
installed_version != current_version | |
end | |
def inform_user | |
puts "=> New kitty version available! (v#{current_version}) [installed: v#{installed_version}] π".light_blue | |
puts "=> Changelog: https://sw.kovidgoyal.net/kitty/changelog/".light_blue | |
puts | |
end | |
def user_consents? | |
print "=> Update? (Y/N) ".blue | |
answer = "" | |
while answer.length == 0 | |
answer = gets.chomp | |
end | |
answer[0].upcase == "Y" | |
end | |
def install_app | |
puts "==> Downloading and installing v#{current_version}...".blue | |
if dry_run? | |
puts "===> Skipping install command [dry run]".cyan | |
else | |
system "command curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin" | |
end | |
puts "==> Update complete!".blue | |
end | |
def custom_icns? | |
CUSTOM_ICNS && CUSTOM_ICNS_FILE.length > 0 | |
end | |
def check_icns_exists! | |
return unless custom_icns? | |
raise RuntimeError.new("File does not exist: #{CUSTOM_ICNS_FILE}") unless File.exist? CUSTOM_ICNS_FILE | |
end | |
# Updates the kitty app's Info.plist to point to a custom file (copied to its app install location) | |
def update_icns | |
check_icns_exists! | |
basename = File.basename(CUSTOM_ICNS_FILE) | |
plist_path = "/Applications/kitty.app/Contents/Info.plist" | |
puts "==> Updating the Info.plist to use your custom icns file [#{basename}]...".blue | |
system("cp #{CUSTOM_ICNS_FILE} /Applications/kitty.app/Contents/Resources/#{basename}") | |
puts "===> Custom icns file copied to the app's install location".cyan | |
system("cp #{plist_path}{,-bak.plist}") | |
puts "===> Backed up the app's Info.plist".cyan | |
friendly_basename = Regexp.escape(basename) | |
if system("sed -i 's/kitty\.icns/#{friendly_basename}/g' #{plist_path}") | |
puts "===> Changed the Info.plist to point to your custom icns file".cyan | |
puts "==> Update complete!".blue | |
else | |
puts "==> Error updating the Info.plist with your #{basename} file path".red | |
end | |
end | |
if perform_install? | |
inform_user | |
if forcing? || user_consents? | |
install_app | |
end | |
elsif updating_icns? | |
if !custom_icns? | |
puts "=> Custom ICNS not currently setup (see top of file for settings)".red | |
exit 1 | |
end | |
update_icns | |
else | |
puts "=> Kitty is up to date! (v#{installed_version}) π".blue | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment