Skip to content

Commit

Permalink
Add helpers to replace the notion menus with rofi[1]
Browse files Browse the repository at this point in the history
  • Loading branch information
olejorgenb committed Jan 21, 2017
1 parent 23f6ace commit 29312f6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions contrib/scripts/notion_rofi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env zsh
#
# Example:
# rofi -show notion -modi "notion:'./notion_rofi.sh focuslist'" -scroll-method 1

function escape {
sed "s/'/\\'/g"
}

MENU_NAME=$1

if [[ -z $2 ]]; then
# No argument -> generate menu entries

notionflux -e "return rofi.menu_list('$MENU_NAME')" \
| sed -e 's/\\"/"/g' -e 's/^"//' -e 's/\\$//g' -e '$d'
else
# Entry selected

ENTRY=$(echo $2 | escape)
notionflux -e "rofi.menu_action('$MENU_NAME', '$ENTRY')" > /dev/null
fi
32 changes: 32 additions & 0 deletions contrib/scripts/rofi.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
rofi = {}

rofi.active_menu_entries = {}

function rofi.menu_list(menu_name)
local entry_lines = ""

local entries = ioncore.getmenu(menu_name)()

rofi.active_menu_entries[menu_name] = {}

for i,entry in ipairs(entries) do
entry_lines = entry_lines .. entry.name .. "\n"
rofi.active_menu_entries[menu_name][entry.name] = entry.func
end

return entry_lines
end

function rofi.menu_action(menu_name, entry_name)
rofi.active_menu_entries[menu_name][entry_name]()
end


-- To replace all menus with rofi set mod_menu.menu = rofi.menu
-- notion_rofi.sh must be moved to ~/.notion/ first
function rofi.menu(mplex, sub, menu, unused_parms)
local helper = notioncore.get_paths()["userdir"].."/notion_rofi.sh"
local rofispec = string.format("%s:%s %s", menu, helper, menu)

ioncore.exec(string.format("rofi -show %s -modi '%s'", menu, rofispec))
end

0 comments on commit 29312f6

Please sign in to comment.