General TC > Programming & Scripting - Unofficial
Using dmenu to load extensions
althalus:
So ondemand is nice, but it still requires interaction with the mouse, and I can type firefox far faster than I can identify it in a list. Since I already mostly use either dmenu or tablaunch for launching apps, I wrote the following simple little wrapper for dmenu that I set up on a hotkey to quickly and easily load extensions with just a couple of keystrokes. (shouldn't need to say that it requires dmenu.tcz loaded)
--- Code: ---#!/bin/sh
cd `cat /opt/.tce_dir`/optional
tcz=`ls *.tcz | dmenu -p "load extension: "` && exec tce-load -i $tcz
--- End code ---
Mayhap anyone else using dmenu will find it useful.
Misalf:
I'm using a slightly less simple script which makes dmenu show a list of extensions and indicate which ones are already loaded.
--- Code: ---#!/bin/sh
[ -e "/usr/local/tce.installed/dmenu" ] || tce-load -i dmenu.tcz >/dev/null 2>&1
TCZS="$(ls -1 /etc/sysconfig/tcedir/optional/*.tcz 2>/dev/null | sed 's:^/etc/sysconfig/tcedir/optional/::g;s/.tcz$//g' | sort -f)"
INSTALLED="$(for i in `ls -1 /usr/local/tce.installed/` ; do echo "$i" ; done)"
for i in $INSTALLED ; do TCZS="$(echo "${TCZS}" | sed "s/^\b$i\b$/:: $i/")" ; done
tce-load -i $(echo "$TCZS" | dmenu -b -w 300 -h 300 -y 19 -c -p "*.tcz" -i -xs -nb '#0D0D0C' -nf '#D4D0C8' -sb '#050503' -sf '#ffb000') >/dev/null 2>&1 &
--- End code ---
The only issue I have is that this loop is relatively slow.
--- Code: ---for i in $INSTALLED ; do TCZS="$(echo "${TCZS}" | sed "s/^\b$i\b$/:: $i/")" ; done
--- End code ---
It can take a few seconds to complete depending on how many extensions are available.
Would be great if anyone could think of a faster way.
curaga:
--- Code: ---INSTALLED="$[for i in `ls -1 /usr/local/tce.installed/` ; do echo "$i" ; done)"
--- End code ---
This loop is unnecessary. The shell will break them the same way either way, so just use INSTALLED="/usr/local/tce.installed/*".
String operations and forks are in general slow. You might be able to replace the echo/sed pair with the shell's string replacement operator, but if that's still too slow, the approach needs rethinking.
Misalf:
The loop for the INSTALLED variable was a workaround as I couldn't get the subsequent loop to succeed without sed complaining about "bad option in substitution expression". Maybe sed doesn't like the path containing a dot.
Still, your suggestion to remove that loop led to some simplification. It now cd into respective directories like the OPs script does.
--- Code: ---#!/bin/sh
[ -e "/usr/local/tce.installed/dmenu" ] || tce-load -i dmenu.tcz >/dev/null 2>&1
cd /etc/sysconfig/tcedir/optional
TCZS="$(ls -1 *.tcz 2>/dev/null | sed 's/.tcz$//g' | sort -f)"
cd /usr/local/tce.installed
for i in * ; do TCZS="$(echo "${TCZS}" | sed "s/^\b$i\b$/:: $i/")" ; done
tce-load -i $(echo "$TCZS" | dmenu -b -w 300 -h 300 -y 19 -c -p "*.tcz" -i -xs -nb '#0D0D0C' -nf '#D4D0C8' -sb '#050503' -sf '#ffb000') >/dev/null 2>&1 &
--- End code ---
Misalf:
--- Quote ---You might be able to replace the echo/sed pair with the shell's string replacement operator
--- End quote ---
In case you meant something like this
--- Code: ---for i in * ; do TCZS="${TCZS//$i/:: $i}" ; done
--- End code ---
it's either incredibly slow so that I loose the patients to wait for it to finish, or I'm doing something wrong.
Navigation
[0] Message Index
[#] Next page
Go to full version