Last active
June 8, 2025 16:58
-
-
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 | |
## | |
# Ruby script to update the installed version of the kitty terminal and update | |
# the default logo and icons to the custom versions I prefer. | |
# | |
# GIST URL: https://gist.github.com/trueheart78/223b2874bd495b6c9d73befd3a1aa416 | |
## | |
CUSTOM_ICONS = true | |
CUSTOM_ICON_LOGO_PATH = "/Users/josh/dotfiles/files/kitty/icons/emoji_kitty.icns" | |
CUSTOM_ICON_128_PATH = "/Users/josh/dotfiles/files/kitty/icons/kitty-128x128.png" | |
CUSTOM_ICON_256_PATH = "/Users/josh/dotfiles/files/kitty/icons/kitty-256x256.png" | |
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 install regardless if an update is available") 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", "--icons", "Update the app to use the custom icon files (defined in the script)") do |i| | |
options[:icons] = 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_icons? | |
options[:icons] == 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_icons? | |
CUSTOM_ICONS && CUSTOM_ICON_LOGO_PATH.length > 0 && CUSTOM_ICON_128_PATH.length > 0 && CUSTOM_ICON_256_PATH.length > 0 | |
end | |
def check_icons_exist! | |
return unless custom_icons? | |
raise RuntimeError.new("File does not exist: #{CUSTOM_ICON_LOGO_PATH}") unless File.exist? CUSTOM_ICON_LOGO_PATH | |
raise RuntimeError.new("File does not exist: #{CUSTOM_ICON_128_PATH}") unless File.exist? CUSTOM_ICON_128_PATH | |
raise RuntimeError.new("File does not exist: #{CUSTOM_ICON_256_PATH}") unless File.exist? CUSTOM_ICON_256_PATH | |
end | |
# Updates the kitty app's Info.plist to point to a custom file (copied to its app install location) | |
def update_icons | |
check_icons_exist! | |
## Backup the logo and icons | |
puts "==> Backing up the logo and icon files...".blue | |
system "mv /Applications/kitty.app/Contents/Resources/kitty.icns{,-bak.icns}" | |
system "mv /Applications/kitty.app/Contents/Resources/kitty/logo/kitty-128.png{,-bak.png}" | |
system "mv /Applications/kitty.app/Contents/Resources/kitty/logo/kitty.png{,-bak.png}" | |
puts "==> Backup complete!".blue | |
## Copy the preferred logo and icons into the expected location | |
puts "==> Updating the logo and icons to use your custom files...".blue | |
system "cp #{CUSTOM_ICON_LOGO_PATH} /Applications/kitty.app/Contents/Resources/kitty.icns" | |
system "cp #{CUSTOM_ICON_128_PATH} /Applications/kitty.app/Contents/Resources/kitty/logo/kitty-128.png" | |
system "cp #{CUSTOM_ICON_256_PATH} /Applications/kitty.app/Contents/Resources/kitty/logo/kitty.png" | |
puts "==> Update complete!".blue | |
end | |
if perform_install? | |
inform_user | |
if forcing? || user_consents? | |
install_app | |
end | |
elsif updating_icons? | |
if !custom_icons? | |
puts "=> Custom ICONS are not currently setup (see top of file for settings)".red | |
exit 1 | |
end | |
update_icons | |
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