-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from olejorgenb/rofi
Contrib: Glue code to use rofi as a menu replacement/alternative
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/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 | ||
|
||
# Unfortunately there's no good way getting pure stdout from notionflux? | ||
# Massage the format of the return string into a usable list. | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |