Skip to content

Commit c1bdc0e

Browse files
authored
Merge pull request #43 from olejorgenb/rofi
Contrib: Glue code to use rofi as a menu replacement/alternative
2 parents 55351a9 + 54dbcff commit c1bdc0e

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

contrib/scripts/notion_rofi.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env zsh
2+
#
3+
# Example:
4+
# rofi -show notion -modi "notion:'./notion_rofi.sh focuslist'" -scroll-method 1
5+
6+
function escape {
7+
sed "s/'/\\\'/g"
8+
}
9+
10+
MENU_NAME=$1
11+
12+
if [[ -z $2 ]]; then
13+
# No argument -> generate menu entries
14+
15+
# Unfortunately there's no good way getting pure stdout from notionflux?
16+
# Massage the format of the return string into a usable list.
17+
18+
notionflux -e "return rofi.menu_list('$MENU_NAME')" \
19+
| sed -e 's/\\"/"/g' -e 's/^"//' -e 's/\\$//g' -e '$d'
20+
else
21+
# Entry selected
22+
23+
ENTRY=$(echo $2 | escape)
24+
notionflux -e "rofi.menu_action('$MENU_NAME', '$ENTRY')" > /dev/null
25+
fi

contrib/scripts/rofi.lua

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
rofi = {}
2+
3+
rofi.active_menu_entries = {}
4+
5+
function rofi.menu_list(menu_name)
6+
local entry_lines = ""
7+
8+
local entries = ioncore.getmenu(menu_name)()
9+
10+
rofi.active_menu_entries[menu_name] = {}
11+
12+
for i,entry in ipairs(entries) do
13+
entry_lines = entry_lines .. entry.name .. "\n"
14+
rofi.active_menu_entries[menu_name][entry.name] = entry.func
15+
end
16+
17+
return entry_lines
18+
end
19+
20+
function rofi.menu_action(menu_name, entry_name)
21+
rofi.active_menu_entries[menu_name][entry_name]()
22+
end
23+
24+
25+
-- To replace all menus with rofi set mod_menu.menu = rofi.menu
26+
-- notion_rofi.sh must be moved to ~/.notion/ first
27+
function rofi.menu(mplex, sub, menu, unused_parms)
28+
local helper = notioncore.get_paths()["userdir"].."/notion_rofi.sh"
29+
local rofispec = string.format("%s:%s %s", menu, helper, menu)
30+
31+
ioncore.exec(string.format("rofi -show %s -modi '%s'", menu, rofispec))
32+
end

0 commit comments

Comments
 (0)