Skip to content

Commit

Permalink
Use gnome-extensions-cli instead of gnome-shell-extension-installer
Browse files Browse the repository at this point in the history
Closes #100
  • Loading branch information
felipecrs committed Apr 27, 2024
1 parent 6f4d266 commit b2b20ea
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 43 deletions.
9 changes: 0 additions & 9 deletions home/.chezmoiexternal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@
type: file
{{ $codeNautilusRevision := includeTemplate "get-github-head-revision" (list "harry-cpp/code-nautilus" $cache) }}
url: "https://raw.githubusercontent.com/harry-cpp/code-nautilus/{{ $codeNautilusRevision }}/code-nautilus.py"

{{ if not .is_wsl -}}
".local/bin/gnome-shell-extension-installer":
type: file
{{ $gnomeExtInstallerRevision := includeTemplate "get-github-head-revision" (list "brunelli/gnome-shell-extension-installer" $cache) }}
url: "https://raw.githubusercontent.com/brunelli/gnome-shell-extension-installer/{{ $gnomeExtInstallerRevision }}/gnome-shell-extension-installer"
executable: true
{{- end }}

{{- end }}

".local/bin/skopeo":
Expand Down
4 changes: 3 additions & 1 deletion home/.chezmoiremove
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
# use werf helm upgrade --wait instead
.local/bin/helm-upgrade-logs

# now we use gext instead
.local/bin/gnome-shell-extension-installer

# tea got renamed to pkgx
.local/bin/tea
.tea

.local/share/gnome-shell/extensions/[email protected]
.docker/cli-plugins/docker-compose
.docker/cli-plugins/docker-buildx

Expand Down
81 changes: 51 additions & 30 deletions home/.chezmoiscripts/run_after_81-install-gnome-extensions.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,71 @@ ensure_path_entry "${HOME}/.local/bin"
function is_gnome_extension_installed() {
local extension="$1"

if [[ -d "${HOME}/.local/share/gnome-shell/extensions/${extension}" ]]; then
return 0
else
return 1
fi
gext list --all | grep --quiet "(${extension})"
}

function enable_extension() {
function is_gnome_extension_enabled() {
local extension="$1"

local current_enabled_extensions
current_enabled_extensions="$(gsettings get org.gnome.shell enabled-extensions)"

if [[ "${current_enabled_extensions}" != *"'${extension}'"* ]]; then
log_task "Enabling GNOME extension: ${extension}"
if [[ "${current_enabled_extensions}" == *"[]"* ]]; then
new_enabled_extensions="['${extension}']"
else
new_enabled_extensions="${current_enabled_extensions%]*}, '${extension}']"
fi
gsettings set org.gnome.shell enabled-extensions "${new_enabled_extensions}"
fi
gext list | grep --quiet "(${extension})"
}

declare -A extension_codes
wanted_extensions=(
[email protected]
[email protected]
# {{ if semverCompare "<22.04" .chezmoi.osRelease.versionID }}
# Ubuntu 22.04+ comes with a nice (already dark) default shell theme
[email protected]
# {{ end }}
)

unwanted_extensions=(
[email protected]
# {{ if semverCompare "<22.04" .chezmoi.osRelease.versionID }}
[email protected]
# {{ end }}
)

extension_codes["[email protected]"]=19
extension_codes["[email protected].com"]=1160
extension_codes["[email protected]"]=3628
disabled_extensions=(
ubuntu-dock@ubuntu.com
)

missing_extensions=()

for extension in "${!extension_codes[@]}"; do
enable_extension "${extension}"
if ! command -v gext >/dev/null; then
log_task "Installing gnome-extensions-cli"
c pipx install gnome-extensions-cli
fi

for extension in "${wanted_extensions[@]}"; do
# shellcheck disable=SC2310
if ! is_gnome_extension_installed "${extension}"; then
missing_extensions+=("${extension_codes["${extension}"]}")
missing_extensions+=("${extension}")
fi
done

if [[ ${#missing_extensions[@]} -gt 0 ]]; then
log_task "Installing GNOME extensions"
extra_args=()
if [[ -n "${DISPLAY:-}" ]]; then
extra_args=("--restart-shell")
fi
gnome-shell-extension-installer --yes "${extra_args[@]}" "${missing_extensions[@]}"
gext install "${missing_extensions[@]}"
fi

for extension in "${disabled_extensions[@]}"; do
if is_gnome_extension_enabled "${extension}"; then
log_task "Disabling GNOME extension: ${extension}"
gext disable "${extension}"
fi
done

for extension in "${wanted_extensions[@]}"; do
if ! is_gnome_extension_enabled "${extension}"; then
log_task "Enabling GNOME extension: ${extension}"
gext enable "${extension}"
fi
done

for extension in "${unwanted_extensions[@]}"; do
if is_gnome_extension_installed "${extension}"; then
log_task "Uninstalling GNOME extension: ${extension}"
gext uninstall "${extension}"
fi
done
6 changes: 5 additions & 1 deletion home/.chezmoiscripts/run_after_82-configure-gnome.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ gsettings_ensure org.gnome.desktop.interface gtk-theme "Yaru-dark"
gsettings_ensure org.gnome.desktop.interface icon-theme "Yaru"
gsettings_ensure org.gnome.desktop.interface cursor-theme "Yaru"
gsettings_ensure org.gnome.desktop.sound theme-name "Yaru"
# {{ if not .is_wsl }}
# {{ if semverCompare ">=22.04" .chezmoi.osRelease.versionID }}
gsettings_ensure org.gnome.desktop.interface color-scheme "prefer-dark"
# {{ else }}
# {{ if not .is_wsl }}
gsettings_ensure org.gnome.shell.extensions.user-theme name "Yaru-dark" [email protected]
# {{ end }}
# {{ end }}

# Configuring miscellaneous settings
Expand Down
4 changes: 2 additions & 2 deletions home/dot_local/bin/executable_full-upgrade.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ if flatpak --version &>/dev/null; then
c sudo flatpak update --assumeyes
fi

if command -v gnome-shell-extension-installer >/dev/null; then
if gext --version >/dev/null; then
log_task "Updating gnome extensions"
c gnome-shell-extension-installer --update --yes
c gext update --yes --user
fi

if pipx --version >/dev/null; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ readonly wanted_packages=(
code
google-chrome-stable
python3-nautilus
pipx
# {{ if not .is_wsl }}
yaru-theme-gnome-shell
libsecret-1-0
Expand Down

0 comments on commit b2b20ea

Please sign in to comment.