Browse Source

Move nord terminal gnome out into top level gnome directory

master
Taylor Bockman 2 years ago
parent
commit
8461a9df0a
  1. 16
      gnome/CHANGELOG.md
  2. 22
      gnome/LICENSE.md
  3. 129
      gnome/README.md
  4. 22322
      gnome/assets/nord-gnome-terminal-banner.ai
  5. 9
      gnome/assets/nord-gnome-terminal-banner.svg
  6. BIN
      gnome/assets/scrot-colortest.png
  7. BIN
      gnome/assets/scrot-htop.png
  8. BIN
      gnome/assets/scrot-readme-default-profile.png
  9. BIN
      gnome/assets/scrot-readme-lazy-profile-change.png
  10. 1
      gnome/nord-gnome-terminal
  11. 447
      gnome/src/nord.sh

16
gnome/CHANGELOG.md

@ -0,0 +1,16 @@
<p align="center"><img src="https://cdn.rawgit.com/arcticicestudio/nord-gnome-terminal/develop/assets/nord-gnome-terminal-banner.svg"/></p>
<p align="center"><img src="https://assets-cdn.github.com/favicon.ico" width=24 height=24/> <a href="https://github.com/arcticicestudio/nord-gnome-terminal/releases/latest"><img src="https://img.shields.io/github/release/arcticicestudio/nord-gnome-terminal.svg?style=flat-square"/></a> <a href="https://github.com/arcticicestudio/nord/releases/tag/v0.2.0"><img src="https://img.shields.io/badge/Nord-v0.2.0-88C0D0.svg?style=flat-square"/></a></p>
---
# 0.1.0 (2016-12-24)
## Features
Implemented the main shell script theme file [`nord.sh`](https://github.com/arcticicestudio/nord-gnome-terminal/blob/develop/src/sh/nord.sh). (@arcticicestudio, #1, c2282cd9)
Detailed information about features and install instructions can be found in the [README](https://github.com/arcticicestudio/nord-gnome-terminal/blob/develop/README.md#installation) and in the [project wiki](https://github.com/arcticicestudio/nord-gnome-terminal/wiki).
<p align="center"><img src="https://raw.githubusercontent.com/arcticicestudio/nord-gnome-terminal/develop/assets/scrot-colortest.png"/><br><strong>htop</strong><br><img src="https://raw.githubusercontent.com/arcticicestudio/nord-gnome-terminal/develop/assets/scrot-htop.png"/></p>
# 0.0.0 (2016-12-22)
**Project Initialization**

22
gnome/LICENSE.md

@ -0,0 +1,22 @@
MIT License (MIT)
Copyright (c) 2016-present Arctic Ice Studio <development@arcticicestudio.com> (http://arcticicestudio.com)
Copyright (c) 2016-present Sven Greb <code@svengreb.de> (http://svengreb.de)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

129
gnome/README.md

@ -0,0 +1,129 @@
<p align="center"><img src="https://cdn.rawgit.com/arcticicestudio/nord-gnome-terminal/develop/assets/nord-gnome-terminal-banner.svg"/></p>
<p align="center"><a href="https://github.com/arcticicestudio/nord-gnome-terminal/releases/latest"><img src="https://img.shields.io/github/v/release/arcticicestudio/nord-gnome-terminal.svg?style=flat-square&color=88C0D0&label=Release"/></a> <a href="https://github.com/arcticicestudio/nord/releases/tag/v0.2.0"><img src="https://img.shields.io/badge/Nord-v0.2.0-88C0D0.svg?style=flat-square"/></a></p>
<p align="center">An arctic, north-bluish clean and elegant <a href="https://wiki.gnome.org/Apps/Terminal">GNOME Terminal</a> color theme.</p>
<p align="center">Designed for a fluent and clear workflow.<br>
Based on the <a href="https://github.com/arcticicestudio/nord">Nord</a> color palette.</p>
---
<p align="center"><img src="https://raw.githubusercontent.com/arcticicestudio/nord-gnome-terminal/develop/assets/scrot-colortest.png"/><blockquote>Font: <a href="https://adobe-fonts.github.io/source-code-pro">Source Code Pro</a> 12px.</blockquote></p>
## Getting started
### Requirements
The installation script requires [`dconf`][dconf] and `uuidgen` ([`util-linux`][util-linux]) to be available on your *PATH* to create a new profile and generate a random profile UUID.
Some distributions may require additional package(s):
* `dconf-tools` - transitional package for `dconf-cli` and `dconf-editor` ([Debian][debian-dconf-tools], [Mint][mint-dconf-tools], [Ubuntu][ubuntu-dconf-tools])
* `dconf-gsettings-backend` to ensure *GSettings* compatibility ([Debian][debian-dconf-gsettings-backend], [Mint][mint-dconf-gsettings-backend], [Ubuntu][ubuntu-dconf-gsettings-backend])
* `dconf-cli` to ensure full CLI support ([Debian][debian-dconf-cli], [Mint][mint-dconf-cli], [Ubuntu][ubuntu-dconf-cli])
* `dconf-service` to ensure D-Bus support for the *GSettings* backend ([Debian][debian-dconf-service], [Mint][mint-dconf-service], [Ubuntu][ubuntu-dconf-service])
* `uuid-runtime` to provide runtime components for the Universally Unique ID library ([Debian][debian-uuid-runtime], [Mint][mint-uuid-runtime], [Ubuntu][ubuntu-uuid-runtime])
The packages should be available for all distributions using the GNOME Terminal by default.
### Installation
1. Clone this repository
```sh
git clone https://github.com/arcticicestudio/nord-gnome-terminal.git
cd nord-gnome-terminal/src
```
2. Run the [`nord.sh`](https://github.com/arcticicestudio/nord-gnome-terminal/blob/develop/src/nord.sh) shell script to start the automated installation.
A list of available options can be shown with `-h`, `--help`.
```sh
./nord.sh --help
```
**Usage**: `nord.sh [OPTIONS]`
* `-h`, `--help` - Shows the help
* `-l`, `--loglevel <LOG_LEVEL>`, `--loglevel=<LOG_LEVEL>` - Set the log level
* `0` *ERROR*
* `1` *WARNING*
* `2` *SUCCESS* (default)
* `3` *INFO*
* `4` *DEBUG*
* `-p`, `--profile <PROFILE_NAME>`, `--profile=<PROFILE_NAME>` - The name of the profile to install the theme to. If not specified a new profile as clone of the *default* profile will be created.
<!-- TODO: It will create a `Nord` GNOME Terminal profile. -->
### Profile Handling
The script detects available profiles and
* **clones the default profile if no specific profile has been specified** - this ensures that no custom profile colors are overriden
* **allows to install the theme for a specific profile** - the name of the profile the theme should be installed to can be passed using the `-p`/`--profile` option
* **handles already existing Nord profiles via version comparison** - if the *Nord* profile already exists and the script version is less than the installed version a confirmation is shown whether to override the theme of abort the installation, otherwise the profile will be
* **updated** if the script version is **greater than** the installed version
* **reinstalled** if the installed version is **equal to** the script version
### Log Level
The script provides a `-l`/`--loglevel` option to allow to define the log level. Available levels are
* `0` *ERROR* - The script will run in *silent mode*, only error messages are shown
* `1` *WARNING* - Shows *warning* messages
* `2` *SUCCESS* (default) - Shows *success* messages
* `3` *INFO* - Shows additional *information* messages
* `4` *DEBUG* - Runs the script in *debug mode* showing additional debug messages
### Activation
#### Set as default profile
1. Open the *Preferences*
2. Switch to the *Profiles* tab
3. Select `Nord` from the drop-down menu labeled with *Profile used when launching a new terminal*
![][scrot-readme-default-profile]
#### Lazy profile change
1. Right-click anywhere inside the terminal window to open the context menu
2. Hover over *Profiles* and select `Nord`
![][scrot-readme-lazy-profile-change]
## Screenshots
<p align="center"><strong>htop</strong><br><img src="https://raw.githubusercontent.com/arcticicestudio/nord-gnome-terminal/develop/assets/scrot-htop.png"/></p>
## Development
[![](https://img.shields.io/badge/Changelog-0.1.0-81A1C1.svg?style=flat-square)](https://github.com/arcticicestudio/nord-gnome-terminal/blob/v0.1.0/CHANGELOG.md) [![](https://img.shields.io/badge/Workflow-gitflow--branching--model-81A1C1.svg?style=flat-square)](http://nvie.com/posts/a-successful-git-branching-model) [![](https://img.shields.io/badge/Versioning-ArcVer_0.8.0-81A1C1.svg?style=flat-square)](https://github.com/arcticicestudio/arcver)
### Contribution
Please report issues/bugs, feature requests and suggestions for improvements to the [issue tracker](https://github.com/arcticicestudio/nord-gnome-terminal/issues).
<p align="center"><img src="https://raw.githubusercontent.com/arcticicestudio/nord-docs/develop/assets/images/nord/repository-footer-separator.svg?sanitize=true" /></p>
<p align="center">Copyright &copy; 2016-present Arctic Ice Studio</p>
<p align="center"><a href="https://github.com/arcticicestudio/nord-gnome-terminal/blob/develop/LICENSE.md"><img src="https://img.shields.io/badge/License-MIT-5E81AC.svg?style=flat-square"/></a> <a href="https://creativecommons.org/licenses/by-sa/4.0"><img src="https://img.shields.io/badge/License-CC_BY--SA_4.0-5E81AC.svg?style=flat-square"/></a></p>
[dconf]: https://wiki.gnome.org/Projects/dconf
[debian-dconf-cli]: https://packages.debian.org/search?keywords=dconf-cli
[debian-dconf-gsettings-backend]: https://packages.debian.org/search?keywords=dconf-gsettings-backend
[debian-dconf-service]: https://packages.debian.org/search?keywords=dconf-service
[debian-dconf-tools]: https://packages.debian.org/search?keywords=dconf-tools
[debian-uuid-runtime]: https://packages.debian.org/search?keywords=uuid-runtime
[mint-dconf-cli]: https://community.linuxmint.com/software/view/dconf-cli
[mint-dconf-gsettings-backend]: https://community.linuxmint.com/software/view/dconf-gsettings-backend
[mint-dconf-service]: https://community.linuxmint.com/software/view/dconf-service
[mint-dconf-tools]: https://community.linuxmint.com/software/view/dconf-tools
[mint-uuid-runtime]: https://community.linuxmint.com/software/view/uuid-runtime
[scrot-readme-default-profile]: https://raw.githubusercontent.com/arcticicestudio/nord-gnome-terminal/develop/assets/scrot-readme-default-profile.png
[scrot-readme-lazy-profile-change]: https://raw.githubusercontent.com/arcticicestudio/nord-gnome-terminal/develop/assets/scrot-readme-lazy-profile-change.png
[ubuntu-dconf-cli]: https://packages.ubuntu.com/search?keywords=dconf-cli
[ubuntu-dconf-gsettings-backend]: https://packages.ubuntu.com/search?keywords=dconf-gsettings-backend
[ubuntu-dconf-service]: https://packages.ubuntu.com/search?keywords=dconf-service
[ubuntu-dconf-tools]: https://packages.ubuntu.com/search?keywords=dconf-tools
[ubuntu-uuid-runtime]: https://packages.ubuntu.com/search?keywords=uuid-runtime
[util-linux]: https://www.kernel.org/pub/linux/utils/util-linux

22322
gnome/assets/nord-gnome-terminal-banner.ai

File diff suppressed because one or more lines are too long

9
gnome/assets/nord-gnome-terminal-banner.svg

@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" width="888" height="200" viewBox="0 0 888 200">
<path fill="none" d="M226.429 144.596h435.143v34.538H226.429z"/>
<path fill="#88C0D0" d="M228.858 144.596h1.35l21.959 31.004h.09v-31.004h.9v32.129h-1.35l-21.959-31.004h-.09v31.004h-.9v-32.129zm38.43 8.461c6.75 0 10.395 5.805 10.395 12.104 0 6.346-3.645 12.105-10.44 12.105-6.75 0-10.395-5.76-10.395-12.105 0-6.3 3.645-12.104 10.44-12.104zm0 23.308c6.165 0 9.495-5.355 9.495-11.205 0-5.76-3.33-11.205-9.495-11.205-6.255 0-9.54 5.445-9.54 11.205.001 5.85 3.285 11.205 9.54 11.205zm15.03.36h-.9v-23.129h.9v5.715h.09c.855-3.42 3.555-6.434 9.09-6.254v.898c-6.345-.314-9.18 4.637-9.18 9.676v13.094zm28.754-32.129h.9v32.129h-.9v-6.479h-.09c-1.17 4.049-4.545 7.02-9.27 7.02-6.12 0-9.855-5.086-9.855-12.061 0-6.479 3.465-12.148 9.855-12.148 4.905 0 8.189 2.834 9.27 7.02h.09v-15.481zm-9.36 9.359c-6.345 0-8.955 5.896-8.955 11.25 0 5.939 2.97 11.16 8.955 11.16 5.939 0 9.359-5.176 9.359-11.16.001-7.154-3.734-11.25-9.359-11.25z"/>
<path fill="#2E3440" d="M357.96 176.725h-2.205l-.405-5.85h-.09c-2.16 4.59-6.479 6.525-11.114 6.525-10.125 0-15.165-7.965-15.165-16.74 0-8.773 5.04-16.738 15.165-16.738 6.75 0 12.239 3.645 13.41 10.664h-3.06c-.405-3.689-4.23-8.055-10.35-8.055-8.505 0-12.104 7.109-12.104 14.129s3.6 14.131 12.104 14.131c7.109 0 11.25-4.996 11.114-11.791h-10.935v-2.609h13.634v16.334zm5.852-32.129h3.419l18.72 27.18h.09v-27.18h3.06v32.129h-3.419l-18.72-27.178h-.09v27.178h-3.06v-32.129zm45.179-.674c10.079 0 15.119 7.965 15.119 16.738 0 8.775-5.04 16.74-15.119 16.74-10.125 0-15.164-7.965-15.164-16.74 0-8.773 5.039-16.738 15.164-16.738zm0 30.869c8.46 0 12.06-7.111 12.06-14.131s-3.6-14.129-12.06-14.129c-8.505 0-12.104 7.109-12.104 14.129s3.599 14.131 12.104 14.131zm19.8-30.195h4.5l11.115 28.17 11.069-28.17h4.5v32.129h-3.061v-27.764h-.09l-10.979 27.764h-2.88l-11.024-27.764h-.09v27.764h-3.061v-32.129zm37.574 0h22.184v2.611h-19.123v11.609h17.908v2.609h-17.908v12.689h19.35v2.609h-22.41v-32.127zm35.731 0h25.469v2.611H516.36v29.518h-3.061v-29.518h-11.203v-2.611zm24.613 21.285c.045 4.139 2.205 9.135 7.65 9.135 4.139 0 6.389-2.43 7.289-5.939h2.834c-1.215 5.264-4.273 8.324-10.123 8.324-7.381 0-10.484-5.67-10.484-12.285 0-6.119 3.104-12.283 10.484-12.283 7.469 0 10.439 6.523 10.215 13.049h-17.865zm15.029-2.385c-.135-4.275-2.789-8.279-7.379-8.279-4.635 0-7.201 4.049-7.65 8.279h15.029zm6.66-9.99h2.609v5.445h.09c1.441-3.734 4.59-5.939 8.775-5.76v2.834c-5.129-.27-8.639 3.51-8.639 8.326v12.373h-2.836v-23.218zm14.176 0h2.609v3.914h.135c1.484-2.789 3.914-4.588 7.605-4.588 3.059 0 5.805 1.484 6.658 4.543 1.396-3.059 4.32-4.543 7.381-4.543 5.084 0 7.693 2.654 7.693 8.145v15.748h-2.834v-15.613c0-3.826-1.439-5.895-5.49-5.895-4.904 0-6.299 4.049-6.299 8.369v13.139h-2.836v-15.748c.045-3.15-1.26-5.76-4.859-5.76-4.904 0-6.885 3.689-6.93 8.549v12.959h-2.834v-23.219zm37.53-8.91h2.834v4.545h-2.834v-4.545zm0 8.91h2.834v23.219h-2.834v-23.219zm8.234 0h2.836v4.006h.09c1.033-2.791 4.139-4.68 7.424-4.68 6.525 0 8.504 3.418 8.504 8.953v14.939h-2.834v-14.488c0-4.006-1.305-7.02-5.895-7.02-4.5 0-7.199 3.42-7.289 7.963v13.545h-2.836v-23.218zm23.939 7.109c.27-5.443 4.094-7.783 9.404-7.783 4.096 0 8.549 1.26 8.549 7.469v12.33c0 1.08.541 1.709 1.666 1.709.314 0 .674-.09.9-.18v2.385c-.631.135-1.08.18-1.846.18-2.879 0-3.33-1.619-3.33-4.049h-.09c-1.98 3.014-4.004 4.725-8.459 4.725-4.275 0-7.785-2.115-7.785-6.795 0-6.525 6.346-6.75 12.465-7.471 2.34-.27 3.645-.584 3.645-3.148 0-3.826-2.744-4.77-6.074-4.77-3.51 0-6.121 1.619-6.211 5.398h-2.834zm15.119 3.42h-.09c-.359.676-1.619.9-2.385 1.035-4.814.855-10.801.811-10.801 5.355 0 2.834 2.521 4.59 5.176 4.59 4.32 0 8.145-2.746 8.1-7.291v-3.689zm8.551-19.439h2.834v32.129h-2.834v-32.129z"/>
<g fill="#2E3440">
<path d="M466.561 126.596l-43.393-55.545V55.64l48.092 62.171h25.844V30.266h-43.465l-9.397-9.399H506.5v105.729z"/>
<path d="M421.439 20.867l43.395 55.541v15.41L416.741 29.65h-25.843v87.545h43.464l9.4 9.401H381.5V20.867z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
gnome/assets/scrot-colortest.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

BIN
gnome/assets/scrot-htop.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

BIN
gnome/assets/scrot-readme-default-profile.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
gnome/assets/scrot-readme-lazy-profile-change.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

1
gnome/nord-gnome-terminal

@ -1 +0,0 @@
Subproject commit ddbdb24729711d00ef813b616c4c253f126a0023

447
gnome/src/nord.sh

@ -0,0 +1,447 @@
#!/usr/bin/env bash
# Copyright (c) 2016-present Arctic Ice Studio <development@arcticicestudio.com>
# Copyright (c) 2016-present Sven Greb <code@svengreb.de>
# Project: Nord GNOME Terminal
# Repository: https://github.com/arcticicestudio/nord-gnome-terminal
# License: MIT
set -e
# Appends the given profile UUID to the profile list.
#
# @param $1 the UUID to be appended
# @return none
# @since 0.2.0
append_profile_uuid_to_list() {
local uuid list
uuid="$1"
list=$(gsettings get "$GSETTINGS_PROFILELIST_PATH" list)
gsettings set "$GSETTINGS_PROFILELIST_PATH" list "${list%]*}, '$uuid']"
}
# Writes the Nord GNOME Terminal theme colors and configurations as dconf key-value pairs to the target profile.
#
# @globread profile_name
# @return none
# @since 0.2.0
apply() {
local \
nord0="#2E3440" \
nord1="#3B4252" \
nord3="#4C566A" \
nord4="#D8DEE9" \
nord5="#E5E9F0" \
nord6="#ECEFF4" \
nord7="#8FBCBB" \
nord8="#88C0D0" \
nord9="#81A1C1" \
nord11="#BF616A" \
nord13="#EBCB8B" \
nord14="#A3BE8C" \
nord15="#B48EAD"
local \
nord0_rgb="rgb(46,52,64)"
nord1_rgb="rgb(59,66,82)"
nord4_rgb="rgb(216,222,233)"
nord8_rgb="rgb(136,192,208)"
_write palette "['$nord1', '$nord11', '$nord14', '$nord13', '$nord9', '$nord15', '$nord8', '$nord5', '$nord3', '$nord11', '$nord14', '$nord13', '$nord9', '$nord15', '$nord7', '$nord6']"
log 4 "Applied Nord color palette"
_write background-color "'$nord0'"
_write foreground-color "'$nord4'"
_write use-transparent-background "false"
log 4 "Applied background- and foreground colors"
_write bold-color "'$nord4'"
_write bold-color-same-as-fg "true"
log 4 "Applied bold color and configuration"
_write use-theme-colors "false"
_write use-theme-background "false"
_write use-theme-transparency "false"
log 4 "Applied system theme compability configuration"
_write cursor-colors-set "true"
_write cursor-foreground-color "'$nord1_rgb'"
_write cursor-background-color "'$nord4_rgb'"
log 4 "Applied cursor colors and configuration"
_write highlight-colors-set "true"
_write highlight-foreground-color "'$nord0_rgb'"
_write highlight-background-color "'$nord8_rgb'"
log 4 "Applied highlight colors and configuration"
_write "$NORD_GNOME_TERMINAL_VERSION_DCONF_KEY" "'$NORD_GNOME_TERMINAL_VERSION'"
log 4 "Set Nord GNOME Terminal version key of the '$profile_name' profile"
log 3 "Applied theme colors and configurations"
}
# Applies the Nord GNOME Terminal theme with version comparison.
#
# @param $1 the version string to compare against
# @return none
# @since 0.2.0
apply_version_compared() {
local version
version=$1
case "$(vercomp "$NORD_GNOME_TERMINAL_VERSION" "$version"; echo $?)" in
0)
log 3 "Reinstalling Nord GNOME Terminal since the version equaled the version of the '$profile_name' profile!";
apply;
log 2 "Reinstalled Nord GNOME Terminal version $NORD_GNOME_TERMINAL_VERSION for the '$profile_name' profile!";
exit 0;;
1)
log 4 "The script version is newer than the currently installed theme ($NORD_GNOME_TERMINAL_VERSION > $version)"
apply;
log 2 "The '$profile_name' profile has been updated successfully from version $version to $NORD_GNOME_TERMINAL_VERSION";
exit 0;;
2)
log 1 "The detected Nord GNOME Terminal version $version of the '$profile_name' profile is greater than the version that will be applied!";
printf "${_ctb}> [?]${_ct} Override current profile version %s with script version %s? (${_ctb}y${_cr}/${_ctb}n${_cr})" "$version" "$NORD_GNOME_TERMINAL_VERSION"
read -r -n 1 -s confirmation;
echo
case $confirmation in
[Yy]* )
apply;
log 2 "Nord GNOME Terminal version $NORD_GNOME_TERMINAL_VERSION has been successfully applied!";
exit 0;;
[Nn]* )
log 0 "Installation canceled by user!";
exit 1;;
* )
log 0 "'$confirmation' is not a valid input!";
exit 1;;
esac
esac
}
# Checks the GNOME Terminal version for the required migration compability (>= 3.8).
#
# @globwrite gnome_terminal_version
# @return 0 if the version is compatible (>= 3.8), 1 otherwise
# @since 0.2.0
check_migrated_version_comp() {
gnome_terminal_version="$(expr "$(LANGUAGE=en_US.UTF-8 gnome-terminal --version)" : '^[^[:digit:]]* \(\([[:digit:]]*\.*\)*\)')"
if [[ ("$(echo "$gnome_terminal_version" | cut -d"." -f1)" = "3" && \
"$(echo "$gnome_terminal_version" | cut -d"." -f2)" -ge 8) || \
"$(echo "$gnome_terminal_version" | cut -d"." -f1)" -ge 4 ]]; then
log 3 "Detected compatible GNOME Terminal version $gnome_terminal_version (>= 3.8 dconf migrated)"
return 0
else
log 1 "Detected incompatible GNOME Terminal version $gnome_terminal_version (< 3.8)"
return 1
fi
}
# Cleans up the script execution by unsetting declared functions and variables.
#
# @return none
# @since 0.2.0
cleanup() {
log 4 "Cleaning up script execution by unsetting declared functions and variables"
unset -v _cr _ct _ctb _ct_highlight _ct_primary _ctb_error _ctb_highlight _ctb_primary _ctb_success _ctb_warning
unset -v NORD_GNOME_TERMINAL_SCRIPT_OPTS NORD_GNOME_TERMINAL_VERSION NORD_GNOME_TERMINAL_VERSION_DCONF_KEY NORD_PROFILE_VISIBLE_NAME log_level DEPENDENCIES DCONF_PROFILE_BASE_PATH GSETTINGS_PROFILELIST_PATH gnome_terminal_version profile_name profile_uuid
unset -f append_profile_uuid_to_list apply check_migrated_version_comp cleanup clone_default_profile get_profiles get_profile_uuid_by_name log print_help validate_dependencies vercomp _write
}
# Clones the default profile, generates and saves the new UUID and adds it to the profile list.
#
# @globwrite profile_uuid
# @since 0.2.0
clone_default_profile() {
local uuid
uuid="$(gsettings get "$GSETTINGS_PROFILELIST_PATH" default | tr -d \')"
profile_uuid="$(uuidgen)"
dconf dump "$DCONF_PROFILE_BASE_PATH"/:"$uuid"/ | dconf load "$DCONF_PROFILE_BASE_PATH"/:"$profile_uuid"/
dconf write "$DCONF_PROFILE_BASE_PATH"/:"$profile_uuid"/visible-name "'$NORD_PROFILE_VISIBLE_NAME'"
append_profile_uuid_to_list "$profile_uuid"
log 3 "Cloned the default profile '$uuid' with new UUID '$profile_uuid'"
}
# Gets the current Nord GNOME Terminal version.
#
# @globread NORD_GNOME_TERMINAL_VERSION_DCONF_KEY DCONF_PROFILE_BASE_PATH
# @param $1 the UUID of the profile to check
# @since 0.2.0
get_current_version() {
local uuid version
uuid=$1
version=
printf "$(dconf read $DCONF_PROFILE_BASE_PATH/:"$uuid"/$NORD_GNOME_TERMINAL_VERSION_DCONF_KEY | tr -d "'")"
return 0
}
# Gets the available GNOME Terminal profiles.
#
# @globwrite profiles
# @return none
# @since 0.2.0
get_profiles() {
profiles=($(gsettings get "$GSETTINGS_PROFILELIST_PATH" list | tr -d "[]\',"))
log 3 "Available profile UUIDs: ${profiles[*]}"
}
# Gets the UUID for the given profile name.
#
# @param $1 the name of the profile to get the UUID from
# @return the UUID of the profile, none otherwise
# @since 0.2.0
get_profile_uuid_by_name() {
local name=$1
for idx in "${!profiles[@]}"; do
if [[ "$(dconf read "$DCONF_PROFILE_BASE_PATH"/:"${profiles[idx]}"/visible-name)" == "'$name'" ]]; then
printf "%s" "${profiles[idx]}"
return 0
fi
done
}
# Prints a message with a prefixed label to STDOUT/STDERR for the given log level.
#
# When no log level is specified, "DEFAULT" is used.
# The minimum log level is defined by the "log_level" global.
#
# Log Levels:
# 0 ERROR
# 1 WARNING
# 2 SUCCESS
# 3 INFO
# 4 DEBUG
#
# @globread
# log_level
# _cr
# _ct
# _ctb
# _ctb_error
# _ctb_highlight
# _ctb_primary
# _ctb_success
# _ctb_warning
# @return none
# @since 0.2.0
log () {
declare -a label color
local num_regex='^[0-9]+$'
local level=$1
label=([0]="[ERR]" [1]="[WARN]" [2]="[SUCCESS]" [3]="[INFO]" [4]="[DEBUG]")
color=([0]="$_ctb_error" [1]="$_ctb_warning" [2]="$_ctb_success" [3]="$_ctb_primary" [4]="$_ctb_highlight")
if [[ $level =~ $num_regex ]]; then
shift
if [[ -n ${log_level} && ${log_level} -ge ${level} ]]; then
printf "${color[$level]}${label[$level]} ${_ct}%s${_cr}\n" "$@"
fi
else
printf "${_ctb}> ${_ct}%s${_cr}\n" "$@"
fi
}
# Prints the help- and usage information.
#
# @return none
# @since 0.2.0
print_help() {
echo -e -n "\
\r${_ctb}Usage: ${_ct_primary}${0##*/} ${_ctb_subtle}[OPTIONS]
${_ctb_highlight}-h${_ct},${_ctb_highlight} --help ${_ct}
Show the help
${_ctb_highlight}-l${_ct},${_ctb_highlight} --loglevel <LOG_LEVEL>${_ct},${_ctb_highlight} --loglevel=<LOG_LEVEL> ${_ct}
Set the log level
${_ctb_primary}0 ${_ctb}ERROR${_cr} The script will run in silent mode, only error messages are shown
${_ctb_primary}1 ${_ctb}WARNING${_cr} Shows warning messages
${_ctb_primary}2 ${_ctb}SUCCESS${_cr} Shows success messages (default)
${_ctb_primary}3 ${_ctb}INFO${_cr} Shows additional information messages
${_ctb_primary}4 ${_ctb}DEBUG${_cr} Runs the script in debug mode showing additional debug messages
${_ctb_highlight}-p${_ct},${_ctb_highlight} --profile <PROFILE_NAME>${_ct},${_ctb_highlight} --profile=<PROFILE_NAME>${_ct}
The name of the profile to install the theme to. If not specified a new profile as clone of the 'default' profile will be created.${_cr}\n"
}
# Validates all required dependencies.
#
# @param $1 array of required dependencies to validate
# @return 0 if all required dependencies are validated, 1 otherwise
# @since 0.2.0
validate_dependencies() {
declare -a missing_deps deps=("${!1}")
for exec in "${deps[@]}"; do
if ! command -v "${exec}" > /dev/null 2>&1; then
missing_deps+=(${exec})
fi
done
if [ ${#missing_deps[*]} -eq 0 ]; then
log 3 "Validated required dependencies: ${deps[*]}"
return 0
else
log 1 "Missing required dependencies: ${_ct_highlight}${missing_deps[*]}${_cr}"
return 1
fi
}
# Compares whether the given version string is greater than, equal to or less than the given comparative version string.
#
# @param $1 the version string to be compared
# @param $2 the version string to compare against
# @return 0 if the versions are equal, 1 if the version is greater or 2 if the version is less than the comparative
# version
# @ since 0.2.0
vercomp() {
# v1 equals v2
if [[ "$1" == "$2" ]]; then
return 0
fi
local IFS=.
local i v1=($1) v2=($2)
# Fill empty fields with zeros
for ((i=${#v1[@]}; i<${#v2[@]}; i++)); do
v1[i]=0
done
for ((i=0; i<${#v1[@]}; i++)); do
if [[ -z ${v2[i]} ]]; then
# Fill empty fields with zeros
v2[i]=0
fi
# v1 is greater than v2
if ((10#${v1[i]} > 10#${v2[i]})); then
return 1
fi
# v1 is less than v2
if ((10#${v1[i]} < 10#${v2[i]})); then
return 2
fi
done
return 0
}
# Shorthand function to write the given key-value pair to the profile.
#
# @globread DCONF_PROFILE_BASE_PATH profile_uuid
# @param $1 the profile key to be written
# @param $2 the value to be assigned to the given profile key
# @return none
# @since 0.2.0
_write() {
local key="$1"
local value="$2"
dconf write "$DCONF_PROFILE_BASE_PATH/:$profile_uuid/$key" "$value"
}
# Catches terminal interrupt- and termination signals and prints a message before exiting the script execution.
#
# @return 1
# @since 0.2.0
trap 'printf "${_ctb_error}User aborted.${_cr}\n" && exit 1' SIGINT SIGTERM
# Exit hook that runs the 'cleanup' function before exiting the script.
#
# @since 0.2.0
trap cleanup EXIT
declare -a DEPENDENCIES profiles
_cr="\e[0m"
_ct="\e[0;37m"
_ctb="\e[1;37m"
_ct_highlight="\e[0;34m"
_ct_primary="\e[0;36m"
_ctb_error="\e[1;31m"
_ctb_highlight="\e[1;34m"
_ctb_primary="\e[1;36m"
_ctb_subtle="\e[1;30m"
_ctb_success="\e[1;32m"
_ctb_warning="\e[1;33m"
NORD_GNOME_TERMINAL_SCRIPT_OPTS=$(getopt -o hl:p: --long help,loglevel:,profile: -n 'nord.sh' -- "$@")
NORD_GNOME_TERMINAL_VERSION=0.1.0
NORD_GNOME_TERMINAL_VERSION_DCONF_KEY=nord-gnome-terminal-version
NORD_PROFILE_VISIBLE_NAME="Nord"
log_level=2
# List of required executable dependencies
DEPENDENCIES=(dconf expr gsettings uuidgen)
# The dconf- and GSettings paths
DCONF_PROFILE_BASE_PATH=/org/gnome/terminal/legacy/profiles:
GSETTINGS_PROFILELIST_PATH=org.gnome.Terminal.ProfilesList
# The detected GNOME Terminal version
gnome_terminal_version=
# The profile name and UUID to apply the theme on
profile_name=
profile_uuid=
eval set -- "$NORD_GNOME_TERMINAL_SCRIPT_OPTS"
while true; do
case "$1" in
--loglevel=* ) log_level=${1#*=}; shift ;;
-l | --loglevel ) log_level=$2; shift ;;
-h | --help ) print_help; exit 0; break ;;
--profile=* ) profile_name=${1#*=}; shift ;;
-p | --profile ) profile_name=$2; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
shift
done
if validate_dependencies DEPENDENCIES[@]; then
if ! check_migrated_version_comp; then
log 0 "The installed GNOME Terminal version '$gnome_terminal_version' is not compatible with the required (dconf migrated) version >= 3.8!"
exit 1
fi
# Check for available profiles and validate that at least the default profile is available
get_profiles
if [[ ${#profiles[*]} -eq 0 ]]; then
log 1 "No profiles found!"
log 0 "There must be at least one default profile!"
exit 1
fi
# Validate- and resolve the UUID if a profile name has been passed
if [[ -n $profile_name ]]; then
profile_uuid="$(get_profile_uuid_by_name "$profile_name")"
if [[ -n $profile_uuid ]]; then
log 3 "Resolved profile '$profile_name' to UUID '$profile_uuid'"
curr_ver="$(get_current_version "$profile_uuid")"
if [[ -n $curr_ver ]]; then
apply_version_compared "$curr_ver"
else
apply
log 2 "Nord GNOME Terminal version $NORD_GNOME_TERMINAL_VERSION has been successfully applied to the '$profile_name' profile"
exit 0
fi
else
log 0 "$profile_name is not a valid profile name!";
exit 1
fi
fi
# Check for an already existing 'Nord' profile and update it
profile_uuid="$(get_profile_uuid_by_name $NORD_PROFILE_VISIBLE_NAME)"
if [[ -n $profile_uuid ]]; then
profile_name="$NORD_PROFILE_VISIBLE_NAME"
log 4 "Found already existing '$NORD_PROFILE_VISIBLE_NAME' profile with UUID '$profile_uuid'"
log "Updating already existing '$NORD_PROFILE_VISIBLE_NAME' profile"
apply_version_compared "$(get_current_version $profile_uuid)"
fi
clone_default_profile
apply
log 2 "Nord GNOME Terminal version $NORD_GNOME_TERMINAL_VERSION has been successfully applied to the newly created '$NORD_PROFILE_VISIBLE_NAME' profile"
exit 0
else
log 0 "Required dependencies were not fulfilled: ${DEPENDENCIES[*]}"
exit 1
fi
Loading…
Cancel
Save