Closed vredesbyyrd closed 5 years ago
I've commited sample scripts for integration with rofi, take a look at the latest commit. I adjusted it slightly and removed some code since in the full version there are parts that are not relevant to brotab. But if you are interested, I posted the full version of dispatcher below.
Wow, that layout looks neat, thanks for sharing! My current layout is much less elegant, it's just id, title, url:
I also tried -sidebar
rofi style before but at some point for tabs I switch to a simpler layout for some reason. Take a look at the full version of dispatcher, maybe you'll like sidebar version better.
```bash #!/bin/bash ACTIVE_WINDOW=/tmp/rofi_active_window.txt SELECTED_LINES=/tmp/rofi_selected_lines.txt ACTION=/tmp/rofi_action.txt MODE=${1:-rt} # Reset state echo -n "" > $SELECTED_LINES echo -n "" > $ACTION xdotool getactivewindow > $ACTIVE_WINDOW DEFAULT_WIDTH=90 MODI="" SELECT="" if [ "$MODE" == "rt" ]; then # MODI+=",open_sheet:rofi_rt_open_sheet.sh" MODI+=",open_rt:rofi_rt_open_candidates.sh" MODI+=",rt_number:rofi_insert_rt_number.sh" MODI+=",rt_number_title:rofi_insert_rt_number_title.sh" MODI+=",rt_url:rofi_insert_rt_url.sh" MODI+=",rt_all:rofi_insert_rt_all.sh" DEFAULT_MODE=rt_number elif [ "$MODE" == "jira" ]; then MODI+=",jira_open:rofi_jira_open_candidates.sh" MODI+=",jira_number:rofi_jira_insert_number.sh" MODI+=",jira_number_title:rofi_jira_insert_number_title.sh" MODI+=",jira_url:rofi_jira_insert_url.sh" MODI+=",jira_all:rofi_jira_insert_all.sh" DEFAULT_MODE=jira_open elif [ "$MODE" == "tab" ]; then MODI+=",activate_tab:rofi_activate_tab.sh" MODI+=",close_tabs:rofi_close_tabs.sh" DEFAULT_MODE=activate_tab elif [ "$MODE" == "unicode" ]; then MODI+=",unicode:rofi_unicode.sh" DEFAULT_MODE=unicode DEFAULT_WIDTH=40 else echo "Unknown mode: $MODE. Known modes: rt, tab" exit 1 fi # source $HOME/rc.arch/bz/.config/fzf/bz-completion.zsh # Mode scripts will use this var export SECOND_COL_WIDTH=97 tab_menu_mode() { mode=$(echo -e "activate\nclose" | rofi -dmenu -p "What would you like to do with browser tabs?" -width $DEFAULT_WIDTH) if [ "$mode" == "activate" ]; then rofi_activate_tab.sh elif [ "$mode" == "close" ]; then rofi_close_tabs.sh fi } regular_mode() { rofi -i -modi "$MODI" -show $DEFAULT_MODE -sidebar-mode -width $DEFAULT_WIDTH ID=$(cat $SELECTED_LINES | sed 's/ \+/\t/g' | cut -d $'\t' -f1) TITLE=$(cat $SELECTED_LINES | sed 's/ \+/\t/g' | cut -d $'\t' -f2) RT_URL="https://www.somecompany.net/rt/Ticket/Display.html?id=$ID" RT_ALL="$ID $TITLE ($RT_URL)" JIRA_URL="https://jira.somecompany.net/browse/$ID" JIRA_ALL="$ID $TITLE ($JIRA_URL)" case "`cat $ACTION`" in "rt_number") xdotool windowfocus --sync `cat $ACTIVE_WINDOW` type "$ID" ;; "rt_number_title") xdotool windowfocus --sync `cat $ACTIVE_WINDOW` type "$ID $TITLE" ;; "rt_url") xdotool windowfocus --sync `cat $ACTIVE_WINDOW` type "$RT_URL" ;; "rt_all") xdotool windowfocus --sync `cat $ACTIVE_WINDOW` type "$RT_ALL" ;; "jira_number") xdotool windowfocus --sync `cat $ACTIVE_WINDOW` type "$ID" ;; "jira_number_title") xdotool windowfocus --sync `cat $ACTIVE_WINDOW` type "$ID $TITLE" ;; "jira_url") xdotool windowfocus --sync `cat $ACTIVE_WINDOW` type "$JIRA_URL" ;; "jira_all") xdotool windowfocus --sync `cat $ACTIVE_WINDOW` type "$JIRA_ALL" ;; "unicode") CODE=$(cat $SELECTED_LINES | cut -d ';' -f1) VALUE=$(echo -e "\U$CODE" ) xdotool windowfocus --sync `cat $ACTIVE_WINDOW` type "$VALUE" ;; esac } if [ "$MODE" == "tab" ]; then tab_menu_mode else regular_mode fi ```
Thank you for doing all this! Very much appreciated. Makes it easier to wrap my head around everything. When I get some time in the coming days I will be doing something this. I will close this now, but I will post my end result when its done.
Thanks again for your time!
@vredesbyyrd Could you please share your rofi script?
I only got around to making one with bare bones functionality, currently the only function is tab-switching. When time abides I want to at least add close
and integration with _simple_tabgroups. Its a modi script, so its started like:
rofi -modi brotab:/path/to/brotab_modi.lua -show brotab -eh 3
I went with a modi script over dmenu because I intend to use it along with a couple other web based rofi modes. It requires shepi.
EDIT: this script requires setting the delimiter
internally, which was only added to rofi
in the last couple months. Im on version Version: 1.5.4-104-g9a3d4b1d
#!/usr/bin/lua
local bp = require("lua-shepi")
local rofi_markup = print("\0markup-rows\x1ftrue\n")
local function GetTabs(sin, sout, serr)
local delim = print("\x00delim\x1f\x0f")
local markup_s = '%s\n<span foreground="#6B838E">%s\n</span><span foreground="#44555D"><small><i>%s</i></small></span>\x0f'
local pipe_in = sin:read("a")
for line in pipe_in:gmatch("([^\n]*)\n") do
local id, title, url = line:match("([^\t]+)\t([^\t]+)\t([^\t]+)")
local result = string.format(markup_s, title, url:match("https?://[www%.]*(.*)"), id)
local prune_s = result:gsub("&", "&")
sout:write(prune_s)
end
end
args = {...}
local pipe = bp.bt("list") | bp.tac("-s", "\n") | bp.fun(GetTabs)
if not args[1] then
io.write(pipe())
else
os.execute(string.format("bt activate %s", args[1]:match("<i>(.-)</i>")))
end
Hi, thanks for sharing this awesome tool. Really well done. I am using it with fzf currently, but I am thinking of trying to integrate it with Rofi. Before I dive into that, do you have any example functions / scripts with rofi + brotab? The fzf and Albert examples are very helpful.
Mimicking a layout like zzzfoo could probably be a good fit for brotab, having the tab title and url on separate lines would be great for readability, imo. I have fzf + brotab setup similar, but some fzf limitations make that specific layout not ideal.
Cheers.
EDIT: To clarify what I mean about fzf limitations. I am not sure you can have the title and url each on a separate line, but considered a single item. Which makes filtering a mess. Rofi has ways around that I believe.