You are not logged in.
This is a bash script for Openbox that lists all of your installed steam games in your little openbox window thing.
#This script creates an Openbox pipe menu to list all currently installed steam games as well as launch them.
#To install:
#Put this script in ~./config/openbox/scripts/steam.sh (or elsewhere if you want to edit the below <menu>)
#Edit the preferences of steam.sh to allow running as a program
#Add the below line to menu.xml (without the comment of course)
#<menu execute="~/.config/openbox/scripts/steam.sh" id="steam" label="Steam"/>
#!/bin/bash
STEAMAPPS=~/.local/share/Steam/steamapps
echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $(ls $STEAMAPPS/*.acf -1v); do
ID=$(cat "$file" | grep '"appid"' | head -1 | sed -r 's/[^"]*"appid"[^"]*"([^"]*)"/\1/')
NAME=$(cat "$file" | grep '"name"' | head -1 | sed -r 's/[^"]*"name"[^"]*"([^"]*)"/\1/')
echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>steam -applaunch $ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'
Pretty straightforward if I do say so myself.
Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc
Offline
Hey, that's neat! I need to work on and practice using the pipe menus for openbox. Seem's like there's a lot of neat things you can do with 'em.
"I have not failed, I have found 10,000 ways that will not work" -Edison
Offline
Hey, that's neat! I need to work on and practice using the pipe menus for openbox. Seem's like there's a lot of neat things you can do with 'em.
...and from the archives: The ultimate pipe menu thread
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Horizon_Brave wrote:Hey, that's neat! I need to work on and practice using the pipe menus for openbox. Seem's like there's a lot of neat things you can do with 'em.
...and from the archives: The ultimate pipe menu thread
Heh, I had originally had help from someone back on the #! forums with creating this script in the first place. (In fact, I think they made the original, and then I recreated it because it was broke ;3; )
Last edited by Viomi (2016-02-01 17:48:34)
Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc
Offline
try this instead:
#This script creates an Openbox pipe menu to list all currently installed steam games as well as launch them.
#To install:
#Put this script in ~./config/openbox/scripts/steam.sh (or elsewhere if you want to edit the below <menu>)
#Edit the preferences of steam.sh to allow running as a program
#Add the below line to menu.xml (without the comment of course)
#<menu execute="~/.config/openbox/scripts/steam.sh" id="steam" label="Steam"/>
#!/bin/bash
STEAMAPPS=~/.local/share/Steam/steamapps
echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $STEAMAPPS/*.acf ; do
ID=$(grep '"appid"' "$file" | head -1 | sed -r 's/[^"]*"appid"[^"]*"([^"]*)"/\1/')
NAME=$(grep '"name"' "$file"| head -1 | sed -r 's/[^"]*"name"[^"]*"([^"]*)"/\1/')
echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>steam -applaunch $ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'
i guess one could shorten/improve it more, but i don't know what these .acf files contain...
Offline
try this instead:
#This script creates an Openbox pipe menu to list all currently installed steam games as well as launch them. #To install: #Put this script in ~./config/openbox/scripts/steam.sh (or elsewhere if you want to edit the below <menu>) #Edit the preferences of steam.sh to allow running as a program #Add the below line to menu.xml (without the comment of course) #<menu execute="~/.config/openbox/scripts/steam.sh" id="steam" label="Steam"/> #!/bin/bash STEAMAPPS=~/.local/share/Steam/steamapps echo '<openbox_pipe_menu>' echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>' echo '<separator/>' for file in $STEAMAPPS/*.acf ; do ID=$(grep '"appid"' "$file" | head -1 | sed -r 's/[^"]*"appid"[^"]*"([^"]*)"/\1/') NAME=$(grep '"name"' "$file"| head -1 | sed -r 's/[^"]*"name"[^"]*"([^"]*)"/\1/') echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>steam -applaunch $ID</execute></action></item>" done echo '</openbox_pipe_menu>'
i guess one could shorten/improve it more, but i don't know what these .acf files contain...
I believe it's just a json list with different values, including appid and name.
Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc
Offline
Bump because I updated the script per recommendation of @ohnonot
I've also made it use awk instead of sed.
#This script is a generally used Openbox pipe menu to list all currently installed steam games as well as launch them.
#To install:
#Put this script in ~./config/openbox/scripts/steam.sh (or elsewhere if you want to edit the below <menu>)
#Add the below line to menu.xml (without the comment of course)
#<menu execute="~/.config/openbox/scripts/steam.sh" id="steam" label="Steam"/>
#!/bin/bash
STEAMAPPS=~/.local/share/Steam/steamapps
echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $(ls $STEAMAPPS/*.acf -1v); do
ID=$(grep '"appid"' "$file" | head -1 | awk -F\" '{print $4}')
NAME=$(grep '"name"' "$file" | head -1 | awk -F\" '{print $4}')
echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>steam -applaunch $ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'
Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc
Offline
for file in $(ls $STEAMAPPS/*.acf -1v); do
why do you insist on parsing ls, which the old guys with the long beards consider a really bad idea?
if you really must, it should be /usr/bin/ls or $(which ls), but why, if a simple * does the same (in this case).
to prove my point, i rewrote the script for .desktop files, just to be able to test it:
#!/bin/bash
STEAMAPPS="/usr/share/applications"
echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $STEAMAPPS/*.desktop ; do
ID="$(cut -d= -f2 <<<$(grep -i 'Exec' "$file"))"
NAME="$(cut -d= -f2 <<<$(grep -i 'Name' "$file"))"
echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>$ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'
(i also prefer to use the '<<<' construct instead of pipes '|', whenever possible.)
Offline
I don't "insist" on parsing ls. I didn't know old men with beards think it's a bad idea.
I also don't understand what's wrong with pipes. Would you like to be informational and educate me about it, and tell me why it's wrong?
Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc
Offline
Why you shouldn't parse the output of ls
From the ultimate bash guru who wrote that:
All in all, you really can't and shouldn't trust the output of ls to be a true representation of the filenames that you want to work with. So don't.
Also if you can avoid pipes, and/or do parameter substitution, it is a lot more efficient - less processes started and stopped etc.
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Your $ID and $NAME lines error, but the rest is great. Thanks.
Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc
Offline
I also don't understand what's wrong with pipes. Would you like to be informational and educate me about it, and tell me why it's wrong?
hey, it's ok, just trying to improve things. it's FOSS after all, right?
pipes are great and useful.
it's not apparent to the casual user, but every pipe opens a new shell (i hope i'm phrasing this right).
with the '<<<' construct (i don't even know what that's called) i can do almost the same as with a pipe, but stay within the same shell.
for every script i write i try to optimize it as much as i can. with my changes, you are executing far less processes (no awk, no ls, no pipes) than with your version. pipemenus are executed everytime you hover over them in the menu, so every performance gain matters. at least to me.
Your $ID and $NAME lines error, but the rest is great. Thanks.
where? how? not on my system.
show us!
(it is possible that it doesn't work as an actual openbox pipemenu, i just whipped it up to prove my point even without using steam)
Offline
with the '<<<' construct (i don't even know what that's called)
It's called a here document
See http://www.tldp.org/LDP/abs/html/here-docs.html
EDIT: No, it's not, I'm getting confused. I don't know what it's called either :8
Just ignore me...
Last edited by Head_on_a_Stick (2016-02-05 08:07:06)
Offline
http://www.tldp.org/LDP/abs/html/x17837.html
"A here string can be considered as a stripped-down form of a here document.
It consists of nothing more than COMMAND <<< $WORD,
where $WORD is expanded and fed to the stdin of COMMAND"
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Thanks damo!
I knew it was here something...
Offline
There is one drawback to using here-docs or here-strings: bash is using a temp file to store the content of whatever follows << or <<<.
You can see it when you run strace on that script, like so:
me@medion:~/tmp/today/quicktests$ strace -o strace -f -tT ./t1
I have dropped the script in a directory quicktest as file t1.
The strace command (install package strace if the command is not there) output goes to file 'strace' in the current directory.
You can see the temp files when you search file strace for 'tmp/'.
Search the file for 'execve' to see what external commands it uses.
Don't know if using here-docs or here-strings should be preferred over using pipes. Could depend on what you are actually doing. Perhaps its worth benchmarking the two solutions per specific case?
For small scripts that take seconds to run, it doesn't make any difference.
Offline
thanks for the extra info!
For small scripts that take seconds to run, it doesn't make any difference.
imho, it does make a difference for ob pipemenus, because the actual script gets executed everytime you even hover your mouse over the menu entry.
but hey, i don't want to sound nitpicking for the OP, i'm just trying to improve things.
if one could actually see those steam files, it could probably be improved even more.
i am myself regularly blown by what one can do with bash - mere mortals have to write 10 lines of code with ifs and pipes, but if you have the know-how, you do it in one short command with lots of weird-looking characters....
Offline
imho, it does make a difference for ob pipemenus, because the actual script gets executed everytime you even hover your mouse over the menu entry.
Offline
I agree that speed is essential here.
I wonder if a benchmark could be usefull?
My gut feeling is that using here-documents or here-strings (I/O operation involved) in this case could lose it from creating extra processes(processing + memory involved). It would still depend on your system being I/O-bound or memory-bound.
Offline
i'm sorry i didn't understand that.
Offline