diff --git a/contrib/scripts/notion_rofi.sh b/contrib/scripts/notion_rofi.sh new file mode 100755 index 000000000..ec28b559b --- /dev/null +++ b/contrib/scripts/notion_rofi.sh @@ -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 diff --git a/contrib/scripts/rofi.lua b/contrib/scripts/rofi.lua new file mode 100644 index 000000000..6b9022626 --- /dev/null +++ b/contrib/scripts/rofi.lua @@ -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