Adding your own functionality
Adding a feature by writing a custom command
:command tabcloseallbykeyword jsb -p browser.tabs.query({}).then(tabs => tabs.forEach( t => { if(t.url.includes(JS_ARG)) browser.tabs.remove(t.id) }))
Starting development, make sure you're running a recent version of your browser and tridactyl. ( :version
)
Talk about what you're about to do, get help: https://gitter.im/tridactyl/Lobby
Writing the example command given above, looking up the help page about :js and :jsb came in handy: :help jsb
To get access to the full console you need to
:tabopen about:debugging
, click this Firefox, inspect Tridactyl, click console: a new development tab will open.
That way you can access objects you have logged etc
Try
:jsb console.log('i logged this from tridactyl')
this should pop up in the new firefox development console
Play around, developing your custom function
:jsb -p browser.tabs.query({}).then(tabs => tabs.forEach( t => { if(t.url.includes(JS_ARG)) browser.tabs.remove(t.id) }))
Create a command for it
:command tabcloseallbykeyword jsb -p browser.tabs.query({}).then(tabs => tabs.forEach( t => { if(t.url.includes(JS_ARG)) browser.tabs.remove(t.id) }))
Test it:
:tabopen https://www.lipsum.com/
:tabopen https://loremipsum.io/
:tabcloseallbykeyword ipsum
Finally, using your text-editor, write the custom command to your .tridactylrc
file without the :
(i didn't have one, so I created the file in my user-directory)
command tabcloseallbykeyword jsb -p browser.tabs.query({}).then(tabs => tabs.forEach( t => { if(t.url.includes(JS_ARG)) browser.tabs.remove(t.id) }))
Reload the RC-file :source
and retest your custom command.
In tridactyl:
-
:tab ...
command changes active tab. -
:tabopen ...
command creates a new tab.
Suppose you want to combine these two commands to switch to tab if it is open or create it if it is not. You can create a custom command like
:command tab_switch_or_open js -d@ let args=JS_ARGS.slice(1); tri.excmds.tab(...args).catch(e => tri.excmds.tabopen(...args)) @
After that you can do :tab_switch_or_open github.com
and if Github is open in your tabs, it will switch to it. If it is not in your tabs, it will create a new tab and open github.com
You can also add this command to your config like the previous one.
Finally, you can create a binding to run your command more easily. I will override the binding b
:
:bind b fillcmdline tab_switch_or_open
Now, if I press b
in normal mode, I can quickly execute my custom command.