balta2ar / brotab

Control your browser's tabs from the command line
MIT License
389 stars 27 forks source link

Method to close the current tab in the active browser window? #101

Open mxmilkiib opened 1 year ago

mxmilkiib commented 1 year ago

I'm trying to bind meta key + mouse button in AwesomeWM to close the current web page tab. Could this be possible through the use of brotab? Thanks for any thoughts!

drocta commented 12 months ago

I'm not familiar with AwesomeWM, but, assuming you can set it up to call a script of your choosing, that should be possible, I would think.

The command brotab query +active +lastFocusedWindow will tell you the active tab in the browser window which most recently had focus. (I think brotab query +active +currentWindow will do the same but only if you currently have it active? I haven't checked this.) In my case, this returned a.920.899 Method to close the current tab in the active browser window? · Issue #101 · balta2ar/brotab https://github.com/balta2ar/brotab/issues/101 this a.920.899 is the thing you would need (please excuse my obscene number of tabs I have open)

Then, brotab close a.920.899 would close the tab. So, if you make a little bash script which calls brotab query +active +lastFocusedWindow , and then uses split or whatever it is called to get the first field in the resulting line, and then have the script call brotab close $theVariableWithTheTabId , it should close the tab.

However, I'm not really familiar with how tiling window managers work, so, for all I know, "the current active window" might not quite be a relevant concept there(?). But, if you have access to the window title of the browser window containing (as its active tab) the tab you want to close, then instead of brotab query +active +lastFocusedWindow you could use something like brotab query +active -title $bashVariableWithTitleOfTheTabPage to get the tab id, and then use the close command to close it as before. This should work provided that you don't have multiple windows which have as their active tab, one with a title containing as a substring(?)(the help text says "pattern", so maybe it supports wildcards or something?) the title of the page in the tab you want to close.