You are not logged in.
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 )
Offline
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 )
Offline
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
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
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
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 )
Offline
@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 )
Offline
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
^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 )
Offline
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
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
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
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 )
Offline
^ Yes, go for it.
I see you put the openbox + gtk theme sync entries back in the menu - which is good
Offline
^ (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
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.
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 )
Offline