You are not logged in.

#1 2020-12-26 08:28:27

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,557
Website

suggestion for jgmenu's "startup" script

Hi @malm, since ~/.config/jgmenu/startup is a BL-specific file, not included in the jgmenu source (right?), I figured a GitHub issue would not be right for this.

The function gtktheme() breaks if there are any spaces around the equals sign in $HOME/.config/gtk-3.0/settings.ini
I think it's not unusual to find things like

gtk-theme-name = BL-lithium
# or even
gtk-theme-name = "BL-lithium"

and since settings.ini is not under our control maybe we should try to cope with these?

As it happens, I had some ini-parsing code to hand, so suggest this alternative function (also accommodates comments):

gtktheme () {
	local key='gtk-theme-name'
	local entry_regex="^[[:blank:]]*${key}[[:blank:]]*=[[:blank:]]*('[^']+'|\"[^\"]+\"|[^#[:blank:]]+)[[:blank:]]*(#.*)*$"
	local value=$(sed -nr "s/${entry_regex}/\1/p" "$HOME/.config/gtk-3.0/settings.ini")
	value=${value#[\'\"]} # strip quotes
	value=${value%[\'\"]}
	printf '%s' "$value"
}

Since the POSIX shell, unlike BASH, has no built-in regex support I resorted to calling sed - it looks a bit cumbersome, but it's still quite fast - on my machine that section takes ~6ms as opposed to ~3ms for the native function using read.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#2 2020-12-28 05:19:05

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,557
Website

Re: suggestion for jgmenu's "startup" script

Here's an alternative function that does everything in the native shell, so it's as fast as - and closely derived from - the original. Copes with trailing comments and strips leading and trailing spaces, but does not strip quotes. That's likely no problem in this case?

gtktheme () {
	while IFS='=' read -r key value; do
		key=${key#"${key%%[![:blank:]]*}"} # strip any leading spaces
		key=${key%"${key##*[![:blank:]]}"} # " " trailing " "
		if [ "${key}" = 'gtk-theme-name' ]; then
			value=${value%%#*} # strip trailing comments
			value=${value#"${value%%[![:blank:]]*}"}
			value=${value%"${value##*[![:blank:]]}"}
			printf '%s' "${value}"
			return 0
		fi
	done < "$HOME/.config/gtk-3.0/settings.ini"
}

...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#3 2020-12-28 17:22:40

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,740

Re: suggestion for jgmenu's "startup" script

Trying ini gem with ruby 2.7.1

gem install ini # I guess

and the readIni.rb

require 'inifile'
myini = IniFile.load(ENV['HOME']+'/.config/gtk-3.0/settings.ini')
myini.each_section do |section|
  puts "I want #{myini[section]['gtk-theme-name']} printed here!"
end

returns

time ruby readIni.rb 
I want oomox-tizix_dark printed here!
ruby readIni.rb  0.03s user 0.14s system 95% cpu 0.180 total

Not suggesting anything.

@john, somehow your function returns/echoes nothing here or I don't know how to use it, but it is much faster

sh ./readIni.sh  0.00s user 0.02s system 58% cpu 0.027 total

gist: Use ruby to be 5 times slower and 50 times more confused, but really pretty wink

edit: python3 is seems fast and less cpu intensive than shell script even

python3 readIni.py  0.02s user 0.00s system 38% cpu 0.041 total

Test script readIni.py

import configparser
filename=r'/home/b/.config/gtk-3.0/settings.ini'
config = configparser.ConfigParser()
config.read(filename)
for sect in config.sections():
    print("\nSection: ",sect)
    for k,v in config.items(sect):
        print("Key: ",k," Value: ",v)

I'm assuming same stuff in go for example would fly, but do we even want something like golang in the distro?

Last edited by brontosaurusrex (2020-12-28 18:42:47)

Online

#4 2020-12-28 22:13:32

malm
jgmenu developer
Registered: 2016-10-13
Posts: 735
Website

Re: suggestion for jgmenu's "startup" script

John - good shout. Yes, let go with one of them. Handling spaces/tabs is pretty fundamental. I wouldn’t worry about a few millisecs - parsing gtk themes is very slow in comparison.

Going back to first principles again, I think syncing with obtheme would be cleaner (easy code, well defined spec, part of the jgmenu core).
Whilst I see the appeal, I’ve never been a massive fan of the GTK script.

Offline

#5 2020-12-29 02:39:57

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,557
Website

Re: suggestion for jgmenu's "startup" script

Anyway GTK docs say "Space before and after the '=' character are ignored." (sic) They don't mention space at the start or end of lines, but I guess we should ignore that too.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#6 2020-12-29 02:48:22

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,557
Website

Re: suggestion for jgmenu's "startup" script

@bronto, does this script return anything for you?

#!/bin/sh

gtktheme () {
	while IFS='=' read -r key value; do
		key=${key#"${key%%[![:blank:]]*}"} # strip any leading spaces
		key=${key%"${key##*[![:blank:]]}"} # " " trailing " "
		if [ "${key}" = 'gtk-theme-name' ]; then
			value=${value%%#*} # strip trailing comments
			value=${value#"${value%%[![:blank:]]*}"}
			value=${value%"${value##*[![:blank:]]}"}
			printf '%s' "${value}"
			return 0
		fi
	done < "$HOME/.config/gtk-3.0/settings.ini"
}

new=$(gtktheme)
printf '%s\n' "Parsed new way: |$new|"

I get:

$ time sh parsing-test
Parsed new way: |BL-lithium|

real	0m0.003s
user	0m0.001s
sys	0m0.002s

...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#7 2020-12-29 10:06:58

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,740

Re: suggestion for jgmenu's "startup" script

This, seems even faster, cool

time sh readIni.sh
Parsed new way: |oomox-tizix_dark|
sh readIni.sh  0.00s user 0.00s system 0% cpu 0.021 total

Online

#8 2020-12-30 02:08:26

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,557
Website

Re: suggestion for jgmenu's "startup" script

^You've got a fast machine there!


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#9 2020-12-30 13:52:31

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,740

Re: suggestion for jgmenu's "startup" script

I'd had to invest to be able to work from home (video editing).

CPU:  Topology: 6-Core model: Intel Core i7-9750H bits: 64 type: MT MCP L2 cache: 256 KiB

It is a nice laptop for real.

Last edited by brontosaurusrex (2020-12-30 13:54:04)

Online

#10 2020-12-30 14:12:44

nobody
The Great
Registered: 2015-08-10
Posts: 3,655

Re: suggestion for jgmenu's "startup" script

brontosaurusrex wrote:

I'd had to invest to be able to work from home (video editing).

CPU:  Topology: 6-Core model: Intel Core i7-9750H bits: 64 type: MT MCP L2 cache: 256 KiB

It is a nice laptop for real.

Neato, HP Omen? They have some good laptop prices.

Offline

#11 2020-12-30 14:32:28

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,740

Re: suggestion for jgmenu's "startup" script

Yeah, I guess this was one of the last of the i7 series (new ones are i9 and 2x more costly).

edit: Actually looking at this prices
https://store.hp.com/us/en/slp/omen-gaming
looks good now, I guess I payed mine x2. (apple m1 dropping prices?)

Last edited by brontosaurusrex (2020-12-30 18:25:48)

Online

#12 2021-01-08 02:22:22

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,557
Website

Re: suggestion for jgmenu's "startup" script

johnraff wrote:

Here's an alternative function that does everything in the native shell, so it's as fast as - and closely derived from - the original. Copes with trailing comments and strips leading and trailing spaces, but does not strip quotes. That's likely no problem in this case?

gtktheme () {
	while IFS='=' read -r key value; do
		key=${key#"${key%%[![:blank:]]*}"} # strip any leading spaces
		key=${key%"${key##*[![:blank:]]}"} # " " trailing " "
		if [ "${key}" = 'gtk-theme-name' ]; then
			value=${value%%#*} # strip trailing comments
			value=${value#"${value%%[![:blank:]]*}"}
			value=${value%"${value##*[![:blank:]]}"}
			printf '%s' "${value}"
			return 0
		fi
	done < "$HOME/.config/gtk-3.0/settings.ini"
}

@malm, OK to replace gtktheme() in ~/.config/jgmenu/startup with that function? It seems to be testing OK.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#13 2021-01-08 18:44:10

malm
jgmenu developer
Registered: 2016-10-13
Posts: 735
Website

Re: suggestion for jgmenu's "startup" script

^ Yes, go for it.

I see you put the openbox + gtk theme sync entries back in the menu - which is good smile

Offline

#14 2021-01-09 02:49:53

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,557
Website

Re: suggestion for jgmenu's "startup" script

malm wrote:

^ (function replace) Yes, go for it.

OK will do.

I see you put the openbox + gtk theme sync entries back in the menu - which is good smile

I think the OB sync might be useful occasionally, but am now in fact wondering whether the GTK sync item would ever be used? The hook on ~/.config/gtk-3.0/settings.ini means that jgmenu's theme is synced immediately anyway.
(Maybe if a user decides to disable the auto-syncing in ~/.config/jgmenu/{startup,hooks} and always do it manually?)

I guess it does no actual harm. smile

Last edited by johnraff (2021-01-09 03:17:22)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

Board footer

Powered by FluxBB