SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2015-03-08 23:49:40

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

[MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

I propose to replace the existing bl-recent-files-pipemenu implementation with this rewrite, which features:

    - safe XML parsing using xmllint from libxml2-utils and XPATHS
    - no Bashisms, it has been written for /bin/dash
    - cleaner syntax allowing for more trivial adoption and extension
    - configuration by command line switches, no editing needed
    - implements the -h flag for displaying usage information
    - different implementation of the recently-used file's clearing (-c): remove the file since it will be automatically recreated

@johnraff, I have modelled the logic after your current implementation. Since I am not an openbox user though, I would like to ask you for your opinion on this and also if you could possibly test this. I am going to post this on the #! forums too which a request for testing/comments.

The script implements two different modi.

In the first modus (without the -H flag), a menu is being generated in which the respective files are being opened by xdg-open (or any other user-specified command, see the -o flag).

In the second modus (enabled by setting the -H flag), the files will be opened by the application from which their recently-used entry originated; for example, a file saved by Firefox will have Firefox as the associated application in which it will be opened.

Here's the complete synopsis:

Usage:  bl-recent-files-pipemenu [-Hch] [-f FILE] [-m MAX-ENTRIES] [-o OPEN-CMD]
        Where:  -H              Open recent files with their associated application.
                -c              Include a menu entry for clearing the recently used files.
                -f FILE         Use the .xbel file from the specified location instead of
                                trying to auto-detect it.
                -h              Print this message and exit.
                -m MAX-ENTRIES  Set the number of menu items to include, ignore the rest.
                -o OPEN-CMD     When not using -H, use OPEN-CMD to open any recent files.
                                Defaults to xdg-open.

Here's the proposed script (here's the current one). The pull request on Github.

Since I am myself not a user of openbox (actually I have no idea what I have done), I would like to ask users to test this so that I can bugproof it. Please do also tell me whether it sucks.

The script would like you to have installed, besides a bourneshell at /bin/sh (don't worry, you probably don't have to change anything), the package

$ sudo apt-get install libxml2-utils

Happy testing. If it breaks you get to keep the pieces big_smile

Last edited by twoion (2015-03-20 10:32:35)


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

Help fund CrunchBang, donate to the project!

#2 2015-03-09 02:54:59

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

@twoion thank you - this script was a major candidate for rewriting. smile

The current xml parsing, while it works more-or-less, is somewhat dependent on the structure of the recently-used.xbel file. Standards-compliant parsing would be more stable, but I was assuming it would require python or perl libraries.

I'll check out yours soon - I'm sure it will be an improvement though. Only three things I'll be looking for:
1) Speed - is it still fast enough for a dynamically-generated menu?
2) How does it deal with cases where there is more than one entry for the same file? I think the preferred default option is to open the file in whatever application used it last, but sometimes it's a tricky choice. Mime-type determination of the app would break down if you'd been recently editing an html file in geany, for example.
3) Is the escaping of weird filenames still OK?

Issue #2 has long  been on the "todo" list, see this post, and the three following:
http://crunchbang.org/forums/viewtopic. … 54#p264854
but took a rather low priority, because the problems didn't arise so often (or nobody was using the menu  tongue  ).


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#3 2015-03-09 04:44:24

tknomanzr
#! Die Hard
From: Heavener, OK
Registered: 2014-12-09
Posts: 777

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

I honestly never used it and had commented it out of my menu long before Phillip's announcement. I find stuff like geany's recent files or even just the fact that it reloads tabs for me to be way more useful.  I don't know. I think about it and I am of two minds about it. The first is that I used InDesign's recently used files functionality quite a bit at work because sometimes it saves me considerable time navigating roughly 500GB worth of files and art, which, although it is highly organized, still take time.

The other side though, is that I see a use for or need for the ability to tell my OS to stop leaving breadcrumbs all over the place. I am not that highly tin-foil hatty but sometimes I just wish you could tell your OS, don't track my useage of this file. I was considering, what if I had stuff in a truecrypt store and the OS or apps even was tracking back to that store? It's still encrypted, however, all those little breadcrumbs lead to....something.

At any rate, I turned it off in the menu. The ability to add shortcut bars to Thunar is good enough for me.

Offline

#4 2015-03-09 05:21:39

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

OK some feedback already!

The order of entries needs to be reversed. The oldest file appears at the top.

There's no "clear recent files" entry. EDIT: sorry I missed the -c option, though to be honest I'm not sure if issuing a 'rm' on the xbel file is an improvement...

Escaping needs work. Files with odd names cause invalid XML to be outputted, which openbox rejects.
I have a directory of oddly-named files for testing:

john@raffles4:/data/john/text/oddnames$ for i in *; do echo "file name: $i";done 
file name: a; rm b
file name: b
file name: f\\
file name: "fish & chips" <what's that?>
file name: it's
file name: line
break
file name: New Empty File
file name: "new folder"
file name: s"s
file name: 日本語.txt

(One file has a linebreak in its name which breaks even the current menu. The others all work though.)

Running the script as-is an error at the top:

trap: SIGINT: bad trap

If you run it with bash the error doesn't appear, nor if SIGINT is replaced by INT. Actually, if you are already trapping EXIT do you need another trap on INT anyway?

Execution time. With -m 15 to output the same number of entries as the current menu:

john@raffles4:~$ time test/bl-recent-files-pipemenu -m 15
trap: SIGINT: bad trap

<openbox_pipe_menu>
 
  <item label="recently_opened_menu.sh">
    <action name="Execute">
      <command>
        xdg-open "file:///home/john/scripts/recently_opened_menu.sh"
      </command>
    </action>
  </item> 
...
<item label="gnome-applications.menu">
    <action name="Execute">
      <command>
        xdg-open "file:///etc/xdg/menus/gnome-applications.menu"
      </command>
    </action>
  </item>
</openbox_pipe_menu>

real	0m0.231s
user	0m0.120s
sys	0m0.040s
--------------------------------------------------------
john@raffles4:~$ time cb-recent-files-pipemenu 
<openbox_pipe_menu>
    <item label="recently-used.xbel">
    <action name="Execute"><command>geany '/home/john/.local/share/recently-used.xbel'</command></action>
    </item>
    <item label="日本語.txt">
    <action name="Execute"><command>geany '/home/john/text/oddnames/日本語.txt'</command></action>
    </item>
    <item label="f\\">
    <action name="Execute"><command>geany '/home/john/text/oddnames/f\\'</command></action>
    </item>
...
    <item label="dillo">
    <action name="Execute"><command>geany '/home/john/bin/super/dillo'</command></action>
    </item>
<separator />
    <item label="Clear Recent Files">
        <action name="Execute">
            <command>
            &apos;/usr/bin/cb-recent-files-pipemenu&apos; --clear
            </command>
        </action>
    </item>
</openbox_pipe_menu>

real	0m0.023s
user	0m0.012s
sys	0m0.004s

So it's about 10 to 1. Depending on the power of a user's computer this may or may not matter. With my core i3 there's a perceptible lag with the new menu.

I'm sure most of these issues can be fixed though.

Last edited by johnraff (2015-03-09 05:44:03)


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#5 2015-03-09 12:22:59

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

@johnraff, thanks for the testing.

You are right in that the script takes longer; it's about the same magnitude on my i5 (however, it's 0.3s vs 0.03s on 37 elements). I found that the calls to perl are the one great resource hog however! Without perl, my script runs in 0.03s too. I'll try to hack around this.

As for the XML representation of \n, I think that should be fixable too.

Reversing the output is trivial.

As for the -c option/the choice of rm: applications use libxdg or similar libraries to access the .xbel files. If the file is being deleted, nobody is going to notice since said libraries will always recreate the file if it doesn't exist. I find just removing is more elegant than echo'ing a snippet in there which we would also have to maintain.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#6 2015-03-09 12:46:54

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

@johnraff, could you please clearly indicate where the newline issue happens - in the label or in the <Command> tag? According to the XML spec, newlines in the document like

<xml attribute="a
b">
</xml>

should get normalized into a single space, i.e. they should disappear and produce wrong actions (because the filename as it is represented does not exit) but not wrong labels (there a space should appear). Is it the latter case, i.e. the actions do not work?
--
PS. I have pushed a few more commits and the speed issue should be resolved (except for when the user only has %-encoded urls in the file.)

Last edited by twoion (2015-03-09 12:48:39)


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#7 2015-03-10 03:13:56

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

twoion wrote:

@johnraff, could you please clearly indicate where the newline issue happens - in the label or in the <Command> tag?

It was not necessarily the filename with the newline that broke the menu. (There were some other unpleasant characters in that "oddnames" folder...) I just meant that that was the only filename that broke the current (ie #!) menu. Anyway, after opening some of those files so that records appeared in the xbel file, the new menu failed to display and OpenBox put up an error box. The old menu worked. So I thought there might be issues with escaping some of the XML reserved characters: & < > " '

I'll try out the new version.


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#8 2015-03-10 05:09:56

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

Quick feedback:

Speed is definitely up. Now in the region 80~100ms for a 15 item menu but still slower than the current script's ~28ms. You've saved by only calling perl when it's needed, but it seems like each of those three xmllint calls is taking ~15ms. (Maybe save time by running the perl call once on the whole menu content, rather than individually on entries?)
--------------
The order is now reversed, but entries are still being taken from the top of recently-used.xbel ie the oldest entries. If you set -m 2 you get the second oldest entry at the top. Getting the newest entries out of recently-used.xbel was something I had trouble with. Doing a "reverse cat" with tac was the only way I could find. (The reversed file then being scanned with awk.)
--------------
Escaping is still a problem. For example, one of the oddly-named files produced a menu entry like this:

<item label=""fish &amp; chips" <what's that?>">
    <action name="Execute">
      <command>
        xdg-open "file:///home/john/text/oddnames/%22fish%20&amp;%20chips%22%20%3Cwhat's%20that%3F%3E"
      </command>
    </action>
  </item> 

The label attribute is being url-decoded OK, but not the file path. OTOH code like that in label=... makes OpenBox choke out an "invalid content" box and refuse to display the menu.

Screenshot of the current menu's output: recent_oddnames.jpg
--------------
Multiple entries:

<item label="bl-recent-files-pipemenu2">
    <action name="Execute">
      <command>
        xdg-open "file:///home/john/test/bl-recent-files-pipemenu2"
      </command>
    </action>
  </item> 
  <item label="bl-recent-files-pipemenu2">
    <action name="Execute">
      <command>
        xdg-open "file:///home/john/test/bl-recent-files-pipemenu2"
      </command>
    </action>
  </item> 
  <item label="bl-recent-files-pipemenu2">
    <action name="Execute">
      <command>
        xdg-open "file:///home/john/test/bl-recent-files-pipemenu2"
      </command>
    </action>
  </item> 

------------------
Inappropriate program chosen to open files:

john@raffles4:~$ test/bl-recent-files-pipemenu2 -m 15 -H

<openbox_pipe_menu>

  <item label="File: waldorf-jessie-amd64.iso">
    <action name="Execute">
      <command>
        file-roller "file:///home/john/downloads/waldorf-jessie-amd64/waldorf-jessie-amd64.iso"
      </command>
    </action>
  </item> 
  <item label="Iceweasel: TODO">
    <action name="Execute">
      <command>
        iceweasel  "file:///home/john/text/TODO"
      </command>
    </action>
  </item> 
  <item label="File: imported_urls">
    <action name="Execute">
      <command>
        file-roller "file:///home/john/text/media_stuff/imported_urls"
      </command>
    </action>
  </item> 
  <item label="Iceweasel: list.txt">
    <action name="Execute">
      <command>
        iceweasel  "file:///home/john/tmp/list.txt"
      </command>
    </action>
  </item> 
  <item label="geany: Greybird-master.zip">
    <action name="Execute">
      <command>
        geany  "file:///home/john/downloads/Greybird-master.zip"
      </command>
    </action>
  </item> 

-----------------
To be honest, I'm still not happy with the delete-recently-used.xbel approach to clearing the menu. a) using "rm ..." always makes me nervous, and b) until a new file is regenerated openbox again spits out an "invalid content" box because without its xbel file the script outputs "failed to detect a recently-used.xbel file". I'd still prefer to inject some correct code into the file rather than deleting it, but an alternative could be to make the script output a correct OpenBox menu with a single "no  recently-used.xbel file found" item?

'<openbox_pipe_menu>
<separator label="No recently-used.xbel file found." />
</openbox_pipe_menu>'

This is what the current menu does.

Last edited by johnraff (2015-03-10 07:29:59)


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#9 2015-03-10 06:38:41

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

Twoion - just a thought, but have you tried xmlstarlet? It might be able to do a lot of the work all in one command. An example:

john@raffles4:~$ f=~/.local/share/recently-used.xbel
john@raffles4:~$ xmlstarlet sel -T -t -m "//bookmark" -n -o 'FilePath: ' -v "./@href" -n -o ' Applications: ' -n -m ".//bookmark:application" -o ' Name: ' -v "./@name" -o ' Exec: ' -v "./@exec" -n  "$f"

FilePath: file:///home/john/text/oddnames/%22fish%20&%20chips%22%20%3Cwhat's%20that%3F%3E
 Applications: 
 Name: Mousepad Text Editor Exec: 'mousepad %f'

FilePath: file:///home/john/text/oddnames/a%3B%20rm%20b
 Applications: 
 Name: Mousepad Text Editor Exec: 'mousepad %f'

FilePath: file:///home/john/images/DistrictLakeEngland.jpg
 Applications: 
 Name: mirage Exec: 'mirage %u'
 Name: GNU Image Manipulation Program Exec: 'gimp-2.8 %u'

FilePath: file:///home/john/scripts/andypix-desc.sh
 Applications: 
 Name: geany Exec: 'geany %u'

John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#10 2015-03-10 12:21:01

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

To be honest, I'm still not happy with the delete-recently-used.xbel approach to clearing the menu. a) using "rm ..." always makes me nervous, and b) until a new file is regenerated openbox again spits out an "invalid content" box because without its xbel file the script outputs "failed to detect a recently-used.xbel file". I'd still prefer to inject some correct code into the file rather than deleting it, but an alternative could be to make the script output a correct OpenBox menu with a single "no  recently-used.xbel file found" item?

'<openbox_pipe_menu>
<separator label="No recently-used.xbel file found." />
</openbox_pipe_menu>'

This is what the current menu does.

Interesting, since I was writing the warnings to stderr and not stdout I assumed that openbox would not see them. Apparently it's reading both stdout and stderr. I feel like this is something that should be fixed primarily in Openbox, but considering its development has halted its upon me. I'll change it that way.

Thanks for all the data, I am going to work with it a bit.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#11 2015-03-10 12:22:37

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

johnraff wrote:

Twoion - just a thought, but have you tried xmlstarlet?

Good find, I didn't know about this tool (written in C to top it). I am going to look into using it.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#12 2015-03-10 14:08:19

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

twoion wrote:

I was writing the warnings to stderr and not stdout I assumed that openbox would not see them. Apparently it's reading both stdout and stderr.

Not necessarily. I got that message in a terminal so of course was seeing both stdout and stderr. OB might have simply been objecting to the lack of any output at all.


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#13 2015-03-10 22:02:52

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

I wrote an incomplete prototype for comparison reasons using a real language. On my 1.3Ghz netbook, this runs in ~0.020s on a 50 item xbel file. I could make do with only 1 library but the penlight version going to ship in jessie is too old and won't have the necessary features :< I'm using a proper XML library so there should be no quoting issues...

Dependencies:

apt-get install lua5.2 lua-expat lua-penlight lua-posix

Code:

#!/usr/bin/env lua5.2

local posix = require 'posix'
local url = require 'socket.url'
local xml = require 'pl.xml'

local M = xml.new("openbox_pipe_menu")

local function swap(a, b)
  return b, a
end

local function quote(s)
  return string.format("%q", s)
end

local function printf(f, ...)
  return string.format(f, ...)
end

local function decode_url(s)
  if s:find("%", 1, true) then
    return url.decode(s)
  end
  return s
end

local function add_executable_item(m, label, cmd, args)
  m:add_direct_child(
    mk_item_tag(label, {
      mk_action_tag("Execute", mk_command_tag(cmd, args))
    }))
  return self
end

local function mk_item_tag(label, actions)
  return xml.elem("item", { label = label, table.unpack(actions)})
end

local function mk_action_tag(name, command_tag)
  return xml.elem("action", { name = name, command_tag })
end

local function mk_command_tag(cmd, args)
  return xml.elem("command"):text(quote(cmd) .. ' ' .. quote(args))
end

local function add_items_from_xbel(m, path, override_cmd)
  if not posix.access(path) then return self end

  local x = xml.parse(path, true)
  if not x then return self end

  for bookmark in x:childtags() do
    local file = bookmark:get_attribs().href
    local prop = bookmark:get_elements_with_name("bookmark:application")[1]:get_attribs()
    m:add_direct_child(
      mk_item_tag(decode_url(posix.basename(file)), {
        mk_action_tag("Execute", mk_command_tag(override_cmd or prop.exec:gsub("%%u", ""), file))
      }))
  end

  return X
end

local function print_menu(m)
  print(xml.tostring(m, "", "  "))
end

-- testing usage: $script <path-to-xbel-file>

add_items_from_xbel(M, arg[1])
print_menu(M)

Sample output

<item label='MediathekView_9.zip'>                                                                                                                             [5/14717]
    <action name='Execute'>
      <command>&quot;&apos;firefox &apos;&quot; &quot;file:///home/joj/Downloads/MediathekView_9.zip&quot;</command>
    </action>
  </item>

Last edited by twoion (2015-03-10 22:04:27)


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#14 2015-03-15 14:39:41

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

Twoion, sorry to be late here - just spent 3 days away from the internet. I installed those lua packages on my Jessie virtual testbed, but there still seems to be something missing:

john@fauxjanice:~$ test/recent4 
lua5.2: test/recent4:4: module 'socket.url' not found:
	no field package.preload['socket.url']
	no file '/usr/local/share/lua/5.2/socket/url.lua'
	no file '/usr/local/share/lua/5.2/socket/url/init.lua'
	no file '/usr/local/lib/lua/5.2/socket/url.lua'
	no file '/usr/local/lib/lua/5.2/socket/url/init.lua'
	no file '/usr/share/lua/5.2/socket/url.lua'
	no file '/usr/share/lua/5.2/socket/url/init.lua'
	no file './socket/url.lua'
	no file '/usr/local/lib/lua/5.2/socket/url.so'
	no file '/usr/lib/i386-linux-gnu/lua/5.2/socket/url.so'
	no file '/usr/lib/lua/5.2/socket/url.so'
	no file '/usr/local/lib/lua/5.2/loadall.so'
	no file './socket/url.so'
	no file '/usr/local/lib/lua/5.2/socket.so'
	no file '/usr/lib/i386-linux-gnu/lua/5.2/socket.so'
	no file '/usr/lib/lua/5.2/socket.so'
	no file '/usr/local/lib/lua/5.2/loadall.so'
	no file './socket.so'
stack traceback:
	[C]: in function 'require'
	test/recent4:4: in main chunk
	[C]: in ?

John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#15 2015-03-15 15:20:24

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

Sorry, I missed lua-socket in the list of packages to install. https://packages.debian.org/jessie/lua-socket.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#16 2015-03-15 15:28:19

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

Fewer errors now, but no menu yet:

lua5.2: test/recent4:49: bad argument #1 to 'access' (string expected, got nil)
stack traceback:
	[C]: in function 'access'
	test/recent4:49: in function 'add_items_from_xbel'
	test/recent4:72: in main chunk
	[C]: in ?

John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#17 2015-03-15 15:32:00

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

I just pushed a more up-to-date version https://github.com/2ion/bunsen-pipemenu … pemenu.lua


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#18 2015-03-15 15:46:34

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

johnraff wrote:

Fewer errors now, but no menu yet:

lua5.2: test/recent4:49: bad argument #1 to 'access' (string expected, got nil)
stack traceback:
	[C]: in function 'access'
	test/recent4:49: in function 'add_items_from_xbel'
	test/recent4:72: in main chunk
	[C]: in ?

In the most recent version above, at the bottom a few paths are hardcoded. The error above is due to the fact that the path to the xbel file is expected to be supplied as a command line argument. No detection logic is built in yet.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#19 2015-03-15 15:47:12

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

Now a menu, but only the last entry:

john@fauxjanice:~$ test/recent4  ~/.local/share/recently-used.xbel 

<openbox_pipe_menu>
  <separator/>
  <item label='Clear recent files'>
    <command>&quot;rm&quot; &quot;-- /tmp/recently-used.xbel&quot;</command>
  </item>
</openbox_pipe_menu>

(There are files in recently-used.xbel which the old menu shows.)

Last edited by johnraff (2015-03-15 15:49:43)


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#20 2015-03-15 16:10:57

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

johnraff wrote:

Now a menu, but only the last entry:

john@fauxjanice:~$ test/recent4  ~/.local/share/recently-used.xbel 

<openbox_pipe_menu>
  <separator/>
  <item label='Clear recent files'>
    <command>&quot;rm&quot; &quot;-- /tmp/recently-used.xbel&quot;</command>
  </item>
</openbox_pipe_menu>

(There are files in recently-used.xbel which the old menu shows.)

his

The second script doesn't take args but uses a hardcoded path (at the very bottom of the script) big_smile Sorry for putting you through this *lol*.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#21 2015-03-15 16:20:23

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

twoion wrote:
johnraff wrote:

Now a menu, but only the last entry:

john@fauxjanice:~$ test/recent4  ~/.local/share/recently-used.xbel 

<openbox_pipe_menu>
  <separator/>
  <item label='Clear recent files'>
    <command>&quot;rm&quot; &quot;-- /tmp/recently-used.xbel&quot;</command>
  </item>
</openbox_pipe_menu>

(There are files in recently-used.xbel which the old menu shows.)

his

The second script doesn't take args but uses a hardcoded path (at the very bottom of the script) big_smile Sorry for putting you through this *lol*.

Infact I fixed a function name just now smile Please pull the updated file.

moushi wake arimasen~


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#22 2015-03-15 16:21:55

twoion
Moderator
Registered: 2012-05-11
Posts: 1,648

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

Nice, runs in 0.009s on my Arch system.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#23 2015-03-15 20:13:03

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

Playing with the script now wink

One odd thing is that "menu.xml" doesn't appear in the Recently Used list, but "menu.xml.bkp", "rc.xml" and every other file I've opened does  hmm

EDIT: and I suggest that the "Clear recent files" is at the top of the menu, so it doesn't disappear off the bottom when there are lots of files in the list

local function add_remove_file_item(m, path)
m:add_direct_child(
mk_item_tag("Clear recent files",
mk_action_tag("Execute", mk_command_tag("rm", path)))
)
m:add_direct_child(xml.elem("separator"))
return m
end

local function print_menu(m)
print(xml.tostring(m, "", " "))
end
add_remove_file_item(M, "/home/damo/.local/share/recently-used.xbel")
add_items_from_xbel(M, "/home/damo/.local/share/recently-used.xbel")

print_menu(M)

Last edited by damo (2015-03-15 20:26:02)


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

#24 2015-03-16 02:28:30

brontosaurusrex
#! Red Menace
Registered: 2012-06-15
Posts: 1,643

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

edit: delete me, was looking at the wrong script.

Last edited by brontosaurusrex (2015-03-16 09:26:30)

Offline

Be excellent to each other!

#25 2015-03-16 03:22:43

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [MERGED][bunsen-pipemenus] big rewrite of bl-recent-files-pipemenu

Getting there!  cool

Yes, a menu with all the files, Japanese nicely decoded in the labels, and runs nice and fast - about the same as the hacky present script. Good job!

Few things left to do:
1) Get the newest files at the top of the list, not the bottom.
2) An option to limit the number of entries, eg the 15 newest entries only.
3) Need to convert '_' to '__' in Openbox menu "label" attributes. The first underbar is taken to indicate an underline for a keyboard shortcut. http://openbox.org/wiki/Help:Menus#Spec … _shortcuts

I have not yet checked behaviour with filenames containing nasty characters, or when there are multiple entries for different apps to open the same file.


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo