Last active
April 21, 2016 19:48
-
-
Save MatteoRagni/568b1d6fb40abb474e0c39bdd3eec998 to your computer and use it in GitHub Desktop.
Update "shell-variable" in "manifest.json" for Gnome Extensions
This file contains 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 "json" | |
# Changes the shell-version variable for all local active extensions | |
$EXTENSIONS_LIST = eval(`gsettings get org.gnome.shell enabled-extensions`) | |
if not $EXTENSIONS_LIST.is_a?(Array) | |
raise RuntimeError "Cannot read extension list" | |
end | |
$SHELL_VERSION = `gnome-shell --version` | |
if $SHELL_VERSION =~ /GNOME\s+Shell\s+(\d+\.\d+)\../ | |
$SHELL_VERSION = $1 | |
else | |
puts $SHELL_VERSION | |
raise RuntimeError, "Cannot get gnome-shell version" | |
end | |
$EXTENSIONS_LOCATION = "~/.local/share/gnome-shell/extensions/" | |
# Updates the local manifest file | |
def update_manifest | |
if File.exist? "manifest.json" | |
manifest = JSON.parse(IO.read("metadata.json")) | |
if not manifest['shell-version'].include?($SHELL_VERSION) | |
manifest['shell-version'] += [$SHELL_VERSION] | |
end | |
File.open("metadata.json", "w") do |f| | |
f.write JSON.dump(manifest) | |
end | |
puts "DONE!" | |
else | |
puts "Warning: file manifest.json not found. skipping" | |
end | |
end | |
# Update a single extension | |
def update_ext(name) | |
loc = $EXTENSIONS_LOCATION + name) | |
if Dir.exist? loc | |
Dir.chdir loc do | |
print "Updating #{name}... " | |
update_manifest | |
end | |
else | |
puts "Extension #{name} not found, skipping" | |
end | |
end | |
# MAIN | |
puts "Updating extensions for version: #{$SHELL_VERSION}" | |
$EXTENSIONS_LIST.each do |name| | |
update_ext(name) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment