You are not logged in.

#1 2021-02-06 13:38:10

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 468
Website

[Solved] Icons in pipe menus

Currently messing with Openbox Pipe menus, and was hoping there would be a way to insert a folder icon into the script to display next to every entry?

Screenshot-from-2021-02-06-07-35-29.png

Here is the basic recents script:

#!/bin/sh
echo "<openbox_pipe_menu>"
files=$(
cat ~/.local/share/recently-used.xbel | grep file:///  | tail -n15 |  cut -d "\"" -f 2 | tac | while read line; 
do  
file=$(echo "$line")
name=$(echo -en "$file" | sed 's,.*/,,' | sed 's/%20/ /g')
echo "<item label=\"$name\">
		<action name=\"Execute\"><command>xdg-open $line</command></action>
	</item>"
done);
echo "$files"
echo "<separator />"
echo "<item label=\"Clear Recents\">
		<action name=\"Execute\"><command>rm ~/.local/share/recently-used.xbel</command></action>
	</item>"
echo "</openbox_pipe_menu>"

Anyhow, Was hoping someone knows how to accomplish this.  Beyond me.


For those wondering about pipe menus, here is the oneliner to put into the menu.xml

<menu execute="pipe-recent-files" icon="/usr/share/icons/gnome-brave/32x32/places/folder.png" id="ID41" label="Recent Files"/>

You will need to change the specifics to match what you want.
"ID" must be changed with each addition.

------

Also, is there a way to bookmark files in Thunar like pcmanfm? - *(This part solved)

They are called "shortcuts" in Thunar. 
There is a right-click action to add to side pane from the send to menu.

Last edited by sleekmason (2021-02-07 14:03:25)

Offline

#2 2021-02-06 20:51:48

ohnonot
...again
Registered: 2015-09-29
Posts: 5,306
Website

Re: [Solved] Icons in pipe menus

The same way you would put icons in a normal menu entry.
Example:

<item label="7-Zip FM" icon="/home/ohnonot/.config/obmenu-generator/icons/c2b4ed15fc32f402abb928c431631076.png"><action name="Execute"><command><![CDATA[7zFM]]></command></action></item>

So, in a shell script:

echo '<item label="7-Zip FM" icon="/home/ohnonot/.config/obmenu-generator/icons/c2b4ed15fc32f402abb928c431631076.png"><action name="Execute"><command><![CDATA[7zFM]]></command></action></item>'

Where is the problem?


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#3 2021-02-06 21:53:56

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 468
Website

Re: [Solved] Icons in pipe menus

ohnonot wrote:

The same way you would put icons in a normal menu entry.
Example:

<item label="7-Zip FM" icon="/home/ohnonot/.config/obmenu-generator/icons/c2b4ed15fc32f402abb928c431631076.png"><action name="Execute"><command><![CDATA[7zFM]]></command></action></item>

So, in a shell script:

echo '<item label="7-Zip FM" icon="/home/ohnonot/.config/obmenu-generator/icons/c2b4ed15fc32f402abb928c431631076.png"><action name="Execute"><command><![CDATA[7zFM]]></command></action></item>'

Where is the problem?


I still cannot get it to work having tried various positions:

#!/bin/sh
echo "<openbox_pipe_menu>"
files=$(
cat ~/.local/share/recently-used.xbel | grep file:///  | tail -n15 |  cut -d "\"" -f 2 | tac | while read line; 
do  
file=$(echo "$line")
name=$(echo -en "$file" | sed 's,.*/,,' | sed 's/%20/ /g')
echo "<item label=\"$name\" icon="/usr/share/icons/gnome-human/32x32/places/folder-documents.png">
		<action name=\"Execute\"><command>xdg-open $line</command></action>
	</item>"
done);
echo "$files"
echo "<separator />"
echo "<item label=\"Clear Recents\">
		<action name=\"Execute\"><command>rm ~/.local/share/recently-used.xbel</command></action>
	</item>"
echo "</openbox_pipe_menu>"

Shouldn't this work? (but obviously doesn't).
It seems like the quotes don't line up like they do in the menus?

Last edited by sleekmason (2021-02-06 22:35:17)

Offline

#4 2021-02-07 06:37:51

ohnonot
...again
Registered: 2015-09-29
Posts: 5,306
Website

Re: [Solved] Icons in pipe menus

You forgot to escape the quotes around the icon path, just like for the other elements.
If you run the script in a terminal it willmost likely tell you what's up.


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#5 2021-02-07 14:01:22

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 468
Website

Re: [Solved] Icons in pipe menus

Ha! Brilliant:) Thank you.

echo "<item label=\"$name\" icon=\"/usr/share/icons/gnome-human/32x32/places/folder-documents.png\">

Offline

#6 2021-02-08 19:22:52

muppetfan
New Member
From: USA
Registered: 2021-01-12
Posts: 4

Re: [Solved] Icons in pipe menus

I highly recommend shellcheck for this sort of thing -- available as a plugin for some editors, and at www.shellcheck.net.

Offline

#7 2021-02-09 01:56:31

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,700
Website

Re: [Solved] Icons in pipe menus

^agreed!

Just install the Debian shellcheck package and Geany's (default BL editor) "Lint" item in the "Build" menu will run a check on the current file.

Surprising how often a script you think is perfect will turn out to have some bug or typo. roll


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#8 2021-02-09 02:42:23

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 468
Website

Re: [Solved] Icons in pipe menus

Thank you both for the info!
I have used it before online, and simply forgot it was there. 
Using shellcheck with Geany sounds like a good plan.

*Edit - This is nice in Geany!  Found a few other obsolete commands in the script.  Hell, Think I just found a new toy:)

Last edited by sleekmason (2021-02-09 02:55:26)

Offline

#9 2021-02-09 05:09:23

ohnonot
...again
Registered: 2015-09-29
Posts: 5,306
Website

Re: [Solved] Icons in pipe menus

muppetfan wrote:

I highly recommend shellcheck for this sort of thing

Agreed. But in this case, simply running the script from a terminal should've helped a long way.
Maybe adding "set -x" or even "set -xv" just under the shebang.


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#10 2021-02-11 15:04:35

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 468
Website

Re: [Solved] Icons in pipe menus

ohnonot wrote:
muppetfan wrote:

I highly recommend shellcheck for this sort of thing

Agreed. But in this case, simply running the script from a terminal should've helped a long way.
Maybe adding "set -x" or even "set -xv" just under the shebang.

I see what you are saying.  I'm am finding in my limited experience, that it's hard to beat the terminal for simple error control.

Using lint in Geany has been interesting.  It made three suggestions for the script, but none of the suggestions actually worked (that is, if I did it right). 

Seems like this could throw a twist in the works if you were not sure of your own code, and kept trying to follow the hints while writing a script. 

Still, a nice tool overall. I suppose there are other tools for this as well?  Reckon I'll find out.

Offline

#11 2021-02-12 04:24:38

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,700
Website

Re: [Solved] Icons in pipe menus

sleekmason wrote:

Using lint in Geany has been interesting.  It made three suggestions for the script, but none of the suggestions actually worked (that is, if I did it right). 

Seems like this could throw a twist in the works if you were not sure of your own code, and kept trying to follow the hints while writing a script. 

Still, a nice tool overall. I suppose there are other tools for this as well?  Reckon I'll find out.

shellcheck is quite a respected piece of software, and while it's sometimes a bit picky I've never known it to give wrong advice. There's a website where you can look up a shellcheck complaint by its number (appears in the lint window) and learn more about it.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#12 2021-02-12 06:00:43

damo
....moderator....
Registered: 2015-08-20
Posts: 6,516

Re: [Solved] Icons in pipe menus

Careful believing this one every time though, if you are using "echo -e"...

note: Backslash is literal in "\n". Prefer explicit escaping: "\\n".

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

#13 2021-02-12 06:04:44

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,700
Website

Re: [Solved] Icons in pipe menus

^Yes, yes! Hit that one a few times...

EDIT: but adding the extra backslash probably wouldn't break anything, would it?

Last edited by johnraff (2021-02-12 08:25:21)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#14 2021-02-12 13:13:44

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 468
Website

Re: [Solved] Icons in pipe menus

johnraff wrote:
sleekmason wrote:

Using lint in Geany has been interesting.  It made three suggestions for the script, but none of the suggestions actually worked (that is, if I did it right). 

Seems like this could throw a twist in the works if you were not sure of your own code, and kept trying to follow the hints while writing a script. 

Still, a nice tool overall. I suppose there are other tools for this as well?  Reckon I'll find out.

shellcheck is quite a respected piece of software, and while it's sometimes a bit picky I've never known it to give wrong advice. There's a website where you can look up a shellcheck complaint by its number (appears in the lint window) and learn more about it.

Thanks for the link @Johnraff.  Good stuff.

Easy enough to check if it was just me. The commands offered by lint would not work, breaking the info the script was trying to provide.  Said "useless cat" but without it, (or replaced), The script didn't work.

Same for the other suggestions.  This being said, I am certainly no code expert and no doubt left something out/wrong/etc . .

Offline

#15 2021-02-13 03:42:50

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,700
Website

Re: [Solved] Icons in pipe menus

"useless use of cat" is a perennial favourite. (websearch)
It's not a bug per se, just not considered nice code.

One example:
cat file | grep 'pattern'
could just as well be
grep 'pattern' file
but there are many many others.

You seem pretty busy now, so as long as your code works, and you don't have any real potential breaks like unquoted variables, then sure leave it be.

If you felt like posting the code snippet and shellcheck's issue number though, I'd be happy to have a look...


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#16 2021-02-14 07:40:07

ohnonot
...again
Registered: 2015-09-29
Posts: 5,306
Website

Re: [Solved] Icons in pipe menus

I must admit I do not use shellcheck all that often ops

It could prevent someone from thinking about good coding practice and instead adopting an attitude of "I just have to run it through shellcheck until there's no more errors". The same goes for all helper applications of this sort.

And, as I said, the shell itself usually gives pretty good hints about what went wrong and where.


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#17 2021-02-14 08:04:48

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,700
Website

Re: [Solved] Icons in pipe menus

ohnonot wrote:

It could prevent someone from thinking about good coding practice and instead adopting an attitude of "I just have to run it through shellcheck until there's no more errors".

In my experience it's the opposite. It pulls you up and reminds you of good coding practice if you get sloppy. Everyone would rather write code that doesn't trigger errors and warnings, surely? And everyone makes typos from time to time. Much better to catch them before running the code.  yikes


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#18 2021-02-14 08:15:57

ohnonot
...again
Registered: 2015-09-29
Posts: 5,306
Website

Re: [Solved] Icons in pipe menus

Your point is just as valid as mine - that's why I used the conditional.

johnraff wrote:

Much better to catch them before running the code.  yikes

I don't think shellcheck (or any other such helper) can save you from having to test-run your code.
And there's so much potential for errors that shellcheck can never see.


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#19 2021-02-14 15:16:54

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 468
Website

Re: [Solved] Icons in pipe menus

For those of us mortals who can't code, we'll take all the help we can get:)

johnraff wrote:

You seem pretty busy now, so as long as your code works, and you don't have any real potential breaks like unquoted variables, then sure leave it be.

Like a whirlwind.  Don't know why I put myself under pressure, lol.  Sourceforge was fun to get into, but once there has a really neat interface.

Being able to just "read the code" like both of you, and many more here is an ability to strive for.  My hacking together bits and pieces really annoys the hell out of me, but slowly over time I'm learning more.

I feel like all of this exploration is a journey I am on.  If I just follow the sign posts, more is revealed. Do the next right thing. Mind blowing really.

The snippet in question is above, but no need to go over it:) It works fine. I will use it as an opportunity to learn more.  When/if I change it, I'll remember this thread and post the change. Ha!

Offline

#20 2021-02-14 22:50:33

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,049

Re: [Solved] Icons in pipe menus

sleekmason wrote:

For those of us mortals who can't code, we'll take all the help we can get:)

johnraff wrote:

You seem pretty busy now, so as long as your code works, and you don't have any real potential breaks like unquoted variables, then sure leave it be.

Like a whirlwind.  Don't know why I put myself under pressure, lol.  Sourceforge was fun to get into, but once there has a really neat interface.

Being able to just "read the code" like both of you, and many more here is an ability to strive for.  My hacking together bits and pieces really annoys the hell out of me, but slowly over time I'm learning more.

I feel like all of this exploration is a journey I am on.  If I just follow the sign posts, more is revealed. Do the next right thing. Mind blowing really.

The snippet in question is above, but no need to go over it:) It works fine. I will use it as an opportunity to learn more.  When/if I change it, I'll remember this thread and post the change. Ha!

Welcome to coding, because there is no possible way to know it all or even understand it all. It's the pattern recognition that really helps.

Offline

#21 2021-02-15 00:23:07

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,700
Website

Re: [Solved] Icons in pipe menus

ohnonot wrote:

Your point is just as valid as mine - that's why I used the conditional.

johnraff wrote:

Much better to catch them before running the code.  yikes

I don't think shellcheck (or any other such helper) can save you from having to test-run your code.
And there's so much potential for errors that shellcheck can never see.

Of course I wasn't for a moment suggesting that passing a shellcheck was sufficient. But IMO a shellcheck before running the code is, at minimum, highly desirable.

Everyone has a different learning strategy, but shellcheck has on numerous occasions pointed out to me things I hadn't thought of. (The explanations attached to each error number are usually quite good.) I'd rather learn that way than by eg reading a book on "Best practice in shell scripting", but each to their own. smile


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#22 2021-02-15 00:30:46

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,049

Re: [Solved] Icons in pipe menus

johnraff wrote:
ohnonot wrote:

Your point is just as valid as mine - that's why I used the conditional.

johnraff wrote:

Much better to catch them before running the code.  yikes

I don't think shellcheck (or any other such helper) can save you from having to test-run your code.
And there's so much potential for errors that shellcheck can never see.

Of course I wasn't for a moment suggesting that passing a shellcheck was sufficient. But IMO a shellcheck before running the code is, at minimum, highly desirable.

Everyone has a different learning strategy, but shellcheck has on numerous occasions pointed out to me things I hadn't thought of. (The explanations attached to each error number are usually quite good.) I'd rather learn that way than by eg reading a book on "Best practice in shell scripting", but each to their own. smile

I write python with both syntax checking and code assist and still have tons of errors at times. And it is much easier to read than shell globes. Lint your code is just good practice.

Offline

#23 2021-02-15 00:36:25

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,700
Website

Re: [Solved] Icons in pipe menus

sleekmason wrote:

The snippet in question is above, but no need to go over it:) It works fine.

That's what they all say! big_smile

I ran shellcheck on it, and all its comments were correct, though some were of the "this is unnecessary" type, so no urgent need to fix. One thing to remember now, though, in 99% of cases read should be given the -r option. If you don't have time to read up on it right now, please just do it!


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#24 2021-02-15 05:39:12

ohnonot
...again
Registered: 2015-09-29
Posts: 5,306
Website

Re: [Solved] Icons in pipe menus

johnraff wrote:

IMO a shellcheck before running the code is, at minimum, highly desirable.

I should probably adopt that.
Not only does it help to find mistakes, but it also minimises code runs (important when e.g. getting stuff from the internet) and hunting for stray files that ended up in the wrong place...

The AUR has a shellcheck-bin package without all the haskell dependencies big_smile


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#25 2021-02-15 16:46:13

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 468
Website

Re: [Solved] Icons in pipe menus

johnraff wrote:

I ran shellcheck on it, and all its comments were correct, though some were of the "this is unnecessary" type, so no urgent need to fix. One thing to remember now, though, in 99% of cases read should be given the -r option. If you don't have time to read up on it right now, please just do it!

Done! No more mangling of backslashes. Lol.


I'm looking at the "useless cat" comment from lint,

cat ~/.local/share/recently-used.xbel | grep file:///  | tail -n15 |  cut -d "\"" -f 2 | tac | while read -r line;

Would be changed to just reflect the filename at the end of the line. But of course this doesn't work without whatever it is I am missing?

(not working)

grep file:///  | tail -n15 |  cut -d "\"" -f 2 | tac | while read -r line ~/.local/share/recently-used.xbel;

**** And whatever you do don't use "<" (one of the lint suggestions), or it will loop when entered from the menu! Froze everything right up. Ha!

Lint accepted the line above as working, so no more clues from lint for the replaced line. No mind reading of intentions for use. Maybe next release.

Is there a way to check lines like this in a terminal by specifying a .txt output or something? (normally would just keep trying until I got it but don't want to < loop again:)

Offline

Board footer

Powered by FluxBB