You are not logged in.

#1 2021-09-20 19:11:45

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Suggestions wanted for a script that toggles betwn gtk theme modes

I'm trying to write a script that toggles between the light and dark variants of GTK themes. The script so far works for themes that have a simple naming scheme of just having a -light or -dark suffix to their names. The way the script toggles themes is by checking its name. If a theme's name ends in either -dark or -Dark, it replaces that suffix with '', or -light, or -Light, and vice-versa for light to dark conversion. This works for most themes (Ex: "Arc", "Adwaita", "ZorinBlue")... Basically those that follow that naming scheme. But for themes that have more variation in their names like Adapta ↔ Adapta-Nokto, Plata-Lumine ↔ Plata-Noir, Qogir-win ↔ Qogit-dark, Arc-Darker ↔ Arc-Dark the script currently exits with an error.

The current code can be viewed here on the GitHub repo or on paste.rs. Just glancing over the main function should be enough.

I really don't want to add hardcoded checks for all themes that get discovered by me or the script's users, which is how the popular Gnome Shell Extension Night Theme Switcher seems to be doing.

Therefore, I would really like some suggestions of the folks in the Arch forums here.

I am thinking, instead of going the hardcoded way (having all theme names/variant right there in the script itself), rather why not let the users themselves choose the mapping of themes they would like. Perhaps a configuration file will store the mappings of the dark vs. light variants of the theme. And when the script finds a theme from the user provided (configured) mapping, it will just refer to the mapping it self for making the theme transition. An example of a conf file having such a mapping can be perhaps:

# Conf script for dark-toggle
theme_mappings="Adapta-Eta:Adapta-Nokto,Qogir-win:Qogir-dark,Plata-Lumine:Plata-Noir"

I can then run a sed command to parse the configuration file (if a configuration file is found) and then use that mapping for changing the theme, instead of my script's source code itself getting smeared with more and more theme names.

If I go the configuration way, I can perhaps add other configurations like having a fallback theme name provided in case a conversion cannot be found.

Or is there a better way to do this by improving my switch statement perhaps, or some completely another way? I am also not aware of any APIs that can do this if there is any.

I would really like some suggestions regarding this, and any help is very, very appreciated.

Offline

#2 2021-09-20 19:32:31

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,912
Website

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

I think the config file approach sounds great.  If I were writing it, I'd likely just have one pair of themes per line separated by a tab.  This makes it easy for user's to write / edit and dead-simple for your script to parse (e.g., `newtheme=$(sed -n "s/\t*$oldtheme\t*//p")`).

But I suspect another approach would be to check the theme file(s) themselves for a background color, and use that to categorize it as light or dark ... or course that'd tell you which if any theme was a good alternative on the other side of the dark/light divide.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2021-09-20 20:48:58

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

Your idea for having one mapping per line makes sense for the reasons you stated (simpler for user to write and for the script to parse). But I might have more config options added in the future like one for specifying a fallback_dark or fallback_light theme. I guess if I were to extend your idea of the theme mappings and the new fallback options, I can put the pair of themes in a key assignment and an example of that may be:

theme_mappings="theme1    theme1-dark
theme2-light    theme2-dark
theme3-White    theme3-Black"

fallback_light_theme="Arc"
fallback_dark_theme="Arc-Dark"

And thus the simplicity breaks, imo. Also, I wouldn't prefer venturing far away from config patterns that already exist (like ini, toml, yaml). At the same time, I do not want to make writing the config too complex. Any idea for a more or less standard config file approach I can use? I don't want to put hard constraints like YAML, I don't want the extra syntactic overhead of using JSON, and I don't think I will need to divide the config file into sections so TOML also seems like something I should pass...

I would really like something that is simple as having key value pairs, but also supporting an array like stucture or dictionary like structure for supporting multiple theme pairs in one key (maybe I can name the key theme_mappings but that's besides the point).

On the second approach, I think it would raise ambiguities as to which "dark" background color the user would like. The theme variant with the darker "dark" value, or the one with the less "dark" value... And, which css selector's background-color should I check? I admit I do not have much idea about theme creation, but a theme like "Arc-Darker" and "Arc-Dark" have the exact same background-color for the sidebar and topbar in nautilus, and only the main body of the app has a darker color in "Arc-Dark". And this also introduces having to parse css files to figure out the theme variant.

Also, I think letting the user decide on the pairings can allow them to have weird light-dark theme combos as they like (that are not default). For example, a user will be able to state that: for Adwaita (which is light), the dark theme they would prefer is "Arc-Dark" (not "Adwaita-dark" which is the default one), and for light theme "Qogir", they would like to use "Zorin-Dark" or something.

Offline

#4 2021-09-20 21:48:03

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,912
Website

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

rifaz_n wrote:

I would really like something that is simple as having key value pairs, but also supporting an array like stucture or dictionary like structure for supporting multiple theme pairs in one key

Have you used python?  It sounds like most of your goals would be pretty simple if you were using that rather than shell script.

But if you stick with shell script, then really the best config is just shell script.  Source the user config from your script and you get whatever is there*.  This also then allows the user to use shell syntax for their settings like defining their own variables to be used in settings, etc.  It's also a format / syntax that would be familiar to most.

*note: of course this means they can also put things in their config that would cause your script to fail.  But in reality this is true of most simple configuration options.

Last edited by Trilby (2021-09-24 23:19:55)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2021-10-01 10:25:44

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

Trilby wrote:

Have you used python?  It sounds like most of your goals would be pretty simple if you were using that rather than shell script.

Parsing a config file does seem more appropriate for Python but I would like to stick to shell script as there really isn't much complexity to the program (other than this parsing the config file). ALSO, I'm trying to improve my relationship with Shell here too! ✌️

Trilby wrote:

But if you stick with shell script, then really the best config is just shell script. [...] *note: of course this means they can also put things in their config that would cause your script to fail.  But in reality this is true of most simple configuration options.

I'm afraid of exactly that scenario that an unaware user might fall victim to hazards that it implies. So... I've chosen to validate and parse the config file manually! I will add a separate comment on how I chose to parse the config. Please do let me know what you think!

Last edited by rifaz_n (2021-10-01 10:35:24)

Offline

#6 2021-10-01 10:42:27

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

This is how I chose to parse a line of config that specifies mappings between two alternate variant of themes. Such a config line currently looks like this:

theme_mappings="theme1-variantA: theme1-variantB, ..., theme99VariantX: theme99VariantY, exotic-name-A: exotic-name-B"

At first, I thought of using sed to parse the line this way:

sed 's/theme_mappings=//' config \
	| sed 's/^"//' | sed 's/"$//' \
	| sed 'y/,/\n/' \
	| sed 's/[[:space:]]*//' \
	| sed -n "s/:*$current_theme:*//p"

The steps (each represented by new sed call on each line):

1. Remove the part 'theme_mappings=' from the line.
2. The line should now be surrounded by double quotes. Remove them from start and end of the line.
3. Replace all comma characters (,) with a new line so that each pair of theme is on a line of its own.
4. Remove any white-spaces.
5. Then print out the theme that is written next to the $current_theme (as you had suggested earlier).

But then some "phase" shifted in my mind, and I thought of going full on built-in shell features and tried a holistic approach of using the shell's parameter expansions only.

With bash, I tried this:

mappings="$line"  # A line having theme_mappings="..."
mappings="${mappings//theme_mappings=}"  # remove the 'theme_mappings=' part
mappings="${mappings// /}"  # Remove any white-space
mappings="${mappings//\"/}"  # Remove the surrounding double quotes

# Since, each mapping is seperated by comma, I'm changing IFS before looping
IFS=,
for pair in $mappings; do
    read -r left right <<< "${pair//:/$IFS}"  # Read left and right side of colon (:) character
    [ "$left" = "$current_theme" ] && new_theme="$right"
    [ "$right" = "$current_theme" ] && new_theme="$left"

done
unset IFS

echo "$new_theme"

I honestly liked how it looked better than my sed solution, so I proceeded to make it POSIX compatible... and faced much trouble, but nonetheless, this is what I came up with:

# line="${line//[ \"]/}"
line="$(printf "$line" | tr --delete '[:space:]\"')"  # Remove white-space and double-quotes from line
line="${line#theme_mappings=}"

IFS=,
for pair in $line; do
	# IFS=: read left right <<< "$pair"
	# IFS=: read left right < <(printf "$pair")
	IFS=: read left right <<-EOF
		$pair
	EOF
	[ "$left" = "$current_theme" ] && new_theme="$right" && variant=dark
	[ "$right" = "$current_theme" ] && new_theme="$left" && variant=light
done
unset IFS
printf "%s %s" "$new_theme" "$variant"

And, currently I have the above code as parser for the theme_mappings. I run a validator before trying to parse this line so syntax checking while parsing is not really needed. Please let me know how it looks and any improvements (or perhaps total rewrites) I can make... Much, much appreciated of your help with this!

Edit: A smal note... I plan to not use awk for this... mainly because I would prefer sticking to built-in shell features as much as possible and I don't have much practice with it yet.
¯\_( ツ )_/¯

Last edited by rifaz_n (2021-10-01 14:51:07)

Offline

#7 2021-10-01 12:07:33

Raynman
Member
Registered: 2011-10-22
Posts: 1,338

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

You could just call the file "theme_mapping.conf" and forget about theme_mapping="..".

If you do one mapping per line, the config becomes more readable and easier to parse with standard line-oriented tools.

Last edited by Raynman (2021-10-01 12:08:11)

Offline

#8 2021-10-01 14:45:22

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

@Raynman, I will have to add more options in the config like having a fallback theme specified in case a valid alternative theme is not found. Also, a current user suggested that it would be better if the icon theme changed along with the application theme. In which case, another key in the config file can be added that maps between application themes and an icon theme. The config file with these keys added might look like this:

theme_mappings = "theme1-A:theme1-B, ..."
icon_mappings="theme2-A: icon2, ..."

fallback_light_theme="Arc"
fallback_dark_theme="Arc-Dark"

I plan to implement adding command line options to the script, which will override the options set in the config file, but I would love to keep the config file as it enables the user to just launch dark-toggle from a menu program like dmenu without passing any options and have it behave like the user wants.

Offline

#9 2021-10-01 16:23:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,912
Website

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

You could have a one-line per entry file and still cover all of that by structuring the data well.  For example, each line could have 4 fields: dark, light, dark icons, light icons.  You could then define the first line to be the default / fallback options.  A single sed command could then get the appropriate theme and icon given an optional "match" variable for the current theme:

# This assumes columns in the config are colon separated

sed -n '
1h
s/^'"$match"':\([^:]*\):[^:]*/\1/
t swap
s/:'"$match"':\([^:]*\):.*/:\1/
t swap
b end
:swap
x
:end
$ {
	x
	p
}
' config

Or as an ugly one-liner:

sed -n '1h;s/^'"$match"':\([^:]*\):[^:]*/\1/;tx;s/:'"$match"':\([^:]*\):.*/:\1/;tx;be;:x;x;:e;${x;p;}' config

Last edited by Trilby (2021-10-01 21:41:10)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2021-10-01 18:25:33

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

@Trilby

This is quite a terrific idea. Let me have a think on it.

Offline

#11 2021-10-02 19:49:36

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

@Trilby

That config file's idea is excellent! Much better than the original idea I had implemented. This one is tabular and much easier to incorporate the theme pairs and corresponding icon pairs. So that's we'll have for the config file's entry format, I'm thinking.

Also, that sed script is so fine too!

I think we should allow comments in the config file. 1) A comment line can be added at the first line of the file, so the user can remember which column represents what. 2) The user can  comment out a line of mappings that they would like to ignore at times.

I was also thinking of having a line of suggested column command (example below) so the user can maintain a readable structure within the file.

However, regarding parsing the file, I will still root for built-in shell features as I would like to have one less dependency to the script (let's see how far I can push that) and the code is more readable.

The following example config and the code to parse it currently works okay, but please do suggest me if I can improve it further.

Config

# Use `column -t -s : -o ' : '` on the file to maintain a tabular look
# Theme 1  :  Theme 2      :  Icon 1  :  Icon 2
Arc        : Arc-Dark      : Icon1    : Icon2
Adwaita    : Adwaita-dark  : Icon1    : Icon2
Plata      : Plata-Noir    : Icon1    : Icon2
ZorinBlue  : ZorinRed-Dark :          : 

Parser

while read line; do
	starts_with "$line" "#" && continue
	IFS=: read theme_l theme_r icon_l icon_r <<-EOF
		$(echo $line | tr --delete [:blank:])
	EOF
	[ "$theme_l" = "$match" ] && alt_theme="$theme_r" && alt_icon="$icon_r"
	[ "$theme_r" = "$match" ] && alt_theme="$theme_l" && alt_icon="$icon_l"
done < config2

printf "%s %s\n" "$alt_theme" "$alt_icon"

Is having something like a table header a good idea? Also, on that route of thinking, I also tried using white-space as a seperator for the config file, instead of using colons. In which case, the config file like this:

Config

# Use `column -t -s :` on the file to maintain a tabular look
# Theme 1    Theme 2        Icon 1    Icon 2
Arc         Arc-Dark       Icon1     Icon2
Adwaita     Adwaita-dark   Icon1     Icon2
Plata       Plata-Noir     Icon1     Icon2
ZorinBlue   ZorinRed-Dark            

Which of the seperators (colon, or white-space) should be more prefered in this case? Does it need a validator written (with slightly helpful warning messages) which can be called before parsing the config? Also, how may I improve the parser that I wrote above for this config?

Offline

#12 2021-10-02 23:17:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,912
Website

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

The sub command in the here document is a great idea - I've struggled before using 'read' from a pipe and having to cope with the read variables only being in scope of the last sub-shell of the pipeline (so it can't be used afterwards) - that's a great way to avoid that.

It'd certainly be more efficient though to put the `tr` command outside the loop and have it work on the whole file.  You'd could also then 'grep' out the comment lines at the same point, e.g.:

grep -v '^#' config | tr -d [:blank:] \
   | while read theme_l theme_r icon_l icon_r; do
      [ "$theme_l" = "$match" ] && ...
      ...
   done

## OR ... same process, different coding style:

while read theme_l theme_r icon_l icon_r; do
   [ "$theme_l" = ...
   ...
done <<-EOF
   $(grep -v '^#' config | tr -d [:blank:])
EOF

Last edited by Trilby (2021-10-02 23:20:37)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#13 2021-10-03 11:21:40

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

Hmm, I much prefer the bottom one.

Have any thoughts about which field separator to use? Colons, or spaces? To me the spaces look comparatively cleaner (though not by much). But will using spaces affect the manageability of the config in terms of the user?

Edit: I just came across a useful side-effect. When using white-spaces as delimiter, the script does not need to perform any extra check for comment lines.

Code

while read theme_l theme_r icon_l icon_r; do
	[ "$theme_l" = "$match" ] && alt_theme="$theme_r" && alt_icon="$icon_r"
	[ "$theme_r" = "$match" ] && alt_theme="$theme_l" && alt_icon="$icon_l"
done <<-EOF
	$(tr -s '[:blank:]' < config2)
EOF

printf "%s %s\n" "$alt_theme" "$alt_icon"

Lines that start with a # are already getting ignored (kind of). The #... gets assigned to theme_l which does not equal to the $match anyway!

However, this does cause a problem when the Theme 2 column has an # in it's name, like the following:

Config

...
Plata       #Plata-Noir     Icon1     Icon2

then running that code with match=Plata gives us, #Plata-Noir Icon2. But this shouldn't really be a problem at all anyway, as before applying the theme change, I check whether the theme exists or not (while reporting the user if it doesn't). What do you think though?

theme_check is just a simple function by the way:

theme_check () {
	local user_theme="$HOME/.themes/$1"
	local system_theme="/usr/share/themes/$1"
	[ -f "$user_theme/gtk-3.0/gtk.css" ] || [ -f "$system_theme/gtk-3.0/gtk.css" ]
}

Last edited by rifaz_n (2021-10-03 11:48:47)

Offline

#14 2021-10-03 11:35:06

Slithery
Forum Moderator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 4,755

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

Ideally you want to use a separator that doesn't appear in any of the fields. Can you have theme names with spaces in them?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#15 2021-10-03 11:56:30

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

Slithery wrote:

Ideally you want to use a separator that doesn't appear in any of the fields. Can you have theme names with spaces in them?

Quoting from the Free Desktop Icon Naming Specification: https://specifications.freedesktop.org/ … guidelines

Spaces, colons, slashes, and backslashes are not allowed.

So both spaces and colons seem to be on the safe side.

I could not find ANY specification for gtk/gnome shell themes however. I assume the same rules will apply.

Offline

#16 2021-10-03 15:10:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,912
Website

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

Whitespace makes the most sense to me.  I only used colons in one example as it made the sed script a little easier to read - I expected that it'd be changed to something else.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#17 2021-10-03 16:10:39

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

@Trilby

Alright. I'm coding something up for handling the config files then.

Just in case, for if anyone might be curious... I'll be updating the code in the devel branch of the repo. Until they are at least a little satisfactory to be put in the master.

Plugging the link: https://github.com/rifazn/dark-toggle

Offline

#18 2021-10-16 18:35:44

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

Hi all! Back from the depths!

I have implemented the config format that we last discussed, and the code is actually very short and simple. So I'll paste it here:

parse_config () {
	local config="$1"
	local current_theme="$2"

	while read left right __; do
		[ "$left" = "$current_theme" ] && alt_theme="$right" && variant="dark"
		[ "$right" = "$current_theme" ] && alt_theme="$left" && variant="light"
	done <<-EOF
		$(sed 's/#.*//' "$config" | tr --squeeze-repeats '[:blank:]')
	EOF

	printf "$alt_theme $variant"
}

# Example
parse_config ~/.config/dark-toggle/config Adwaita

The config file for this parser only has two columns for light and dark theme name (as can be guessed, of course) on each line for the user-defined (and other exotic) theme names. Example config just in case:

# Config file for dark-toggle.
# By default, this file has mappings for light/dark variants that cannot be guessed.
# But the user can have any light/dark theme combo.

# Light		Dark
Adapta		Adapta-Nokto
Plata		Plata-Noir
Qogir-win	Qogir-dark

Regarding having icon mappings along with the theme names (where the config has four columns; as was discussed before), I figured that the icon-theme name can be guessed from the gtk theme name quite accurately, instead of having manual mappings in the config file like before... Just choosing the listing from /usr/share/icons (which is the default icon-theme directory) that has the longest match with the gtk theme name seems to suffice (since gtk theme names and their corresponding icon names are quite similar). Of course, if bugs are discovered, the previously discussed four column layout can be restored. The following code guesses the icon-theme name currently:

change_icon_theme () {
	local gtk_theme="$1"
	local longest_match=0
	local icon_name=

	local usr_icons_dir="$HOME/.icons"
	local sys_icons_dir="/usr/share/icons"
    
	for icon_dir in $sys_icons_dir/* $usr_icons_dir/*; do
        # does icon file exist ?
        [ ! -f $icon_dir/index.theme ] && continue

        icon=${icon_dir##*/}
		match_len="$(expr $gtk_theme : $icon)"
		[ $match_len -gt $longest_match ] && longest_match=$match_len && icon_name=$icon
	done

    [ -n "$icon_name" ] && [ $(get_current_icon_theme) != $icon ] && set_icon_theme "$icon_name"
}

Is there any apparent issues with the current code? Can it be improved? The full source can be viewed in the repo of course (devel branch, forgot to mention).

I'm trying to consider adding some more options to the script which is proving to be quite the point of thought for me. I'm thinking of adding the options in the config file itself so that dark-toggle can just be run without passing command-line options from menu programs like dmenu. I'll try to bring that in the next comment.

Last edited by rifaz_n (2021-10-16 19:19:13)

Offline

#19 2021-10-16 18:36:25

rifaz_n
Member
From: Bangladesh
Registered: 2021-09-20
Posts: 12

Re: Suggestions wanted for a script that toggles betwn gtk theme modes

I think it's quite reasonable to expect that dark-toggle should also change the icon-theme, and the GNOME Shell theme too, whenever the GTK Application theme is changed. But I would much prefer the script to only change the gtk theme and change the other themes manually. For this, adding some cli switches seem practical. But having cli switches/options would require a user to pass the options each and every time to run the script in the same manner. The user can add a wrapper script that calls dark-toggle with the right options every time but that seems like quite the hassle for something very small. For this reason, I thought of supporting/adding the switches in the config file itself. But I am not very sure what the config file should look like.

However, this is what I have in mind currently:

## Options
#
# Guess the icon name from the gtk theme name and change to it
change-icons

# Change the GNOME Shell theme as well the the GTK app theme
change-shell

# Don't run hooks found in the hooks/ dir
nohooks

# Use a fallback if an alternate variable cannot be guessed.
fallbacks {
	# Light		Dark
	Adwaita		Adwaita-dark
}

# Put user-defined mappings and also mappings for theme names that cannot be guessed.
mappings {
	# Light		Dark
	Adapta		Adapta-Nokto
	Plata		Plata-Noir
	Qogir-win	Qogir-dark
}

I might try to parse the config file the following way:

change_icons=false
change_shell=false
exec_hooks=false

parse_config () {
	local config="$1"
	local current_theme="$2"

	while read line; do
		line="${line%%#*}"
		case $line in
			# Options
			change-icons)    [ -z "$parse_type" ] && change_icons=true; ;;
			change-shell)    [ -z "$parse_type" ] && change_shell=true; ;;
			nohooks)    [ -z "$parse_type" ] && exec_hooks=true; ;;

			# Mappings
			"mappings {")    parse_type=mappings; ;;
			"}")    parse_type=; ;;
			*)
				[ "$parse_type" != "mappings" ] && continue

				read left right __ <<-EOF
					$line
				EOF
				[ "$left" = "$current_theme" ] && alt_theme="$right" && variant="dark"
				[ "$right" = "$current_theme" ] && alt_theme="$left" && variant="light"
				;;
		esac
	done < $config	
	printf "$alt_theme $variant"
}

$ parse_config config_file Adapta-Nokto
# Adapta light
$ parse_config config_file Adapta
# Adapta-Nokto dark
$ parse_config config_file Plata
# Plata-Noir dark

Could I please have some suggestions if this is an alright way to go about this problem? Or perhaps a better way can be used?

Last edited by rifaz_n (2021-10-18 13:08:38)

Offline

Board footer

Powered by FluxBB