2 # recently_opened_menu.sh - a script to parse recently-used.xbel
3 # and generate openbox pipe menu
4 # Copyright (C) 2010 John Crawley
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
17 # <menu id="recent" label="Recent Files" execute="/path/to/recently_opened_menu.sh" />
18 # to your .config/openbox/menu.xml, or use with dash_places_menu.sh (see comments there)
20 maximum_entries=15 # max. number of entries in menu
22 #######################################################################
24 # if argument is --clear, empty recently-used.xbel
25 [ "$1" = '--clear' ] && {
26 cat <<':EOF' > "${HOME}"/.local/share/recently-used.xbel
27 <?xml version="1.0" encoding="UTF-8"?>
29 xmlns:bookmark="http://www.freedesktop.org/standards/desktop-bookmarks"
30 xmlns:mime="http://www.freedesktop.org/standards/shared-mime-info"
37 maximum_entries=$((maximum_entries+2))
41 <action name="Execute"><command>'
42 post='</command></action>
45 files=$( tac "${HOME}"/.local/share/recently-used.xbel | awk -v MAX="$maximum_entries" -v PR="$pre" -v MI="$mid" -v PO="$post" 'BEGIN {
51 # $1 is the command, $2 the file path
53 sub(/^.*exec=\"\&apos\;/,"",$1)
54 sub(/\&apos\;.*$/,"",$1)
56 sub(/^.*file:\/\//,"",$2)
58 gsub(/%22/,"\"",$2)
59 gsub(/%3C/,"\<",$2)
60 gsub(/%3E/,"\>",$2)
63 gsub(/\'/,"\'\"\'\"\'",$2)
64 print (PR name MI $1 " '"'"'" $2 "'"'"'" PO)
67 # use perl to decode urlencoded characters
68 files=$(perl -MURI::Escape -e 'print uri_unescape($ARGV[0]);' "$files")
70 output='<openbox_pipe_menu>
73 <item label="Effacer la liste">
74 <action name="Execute">
76 ''"$0"'' --clear
82 printf '%s' "$output" # printf because echo sometimes eats backslashes