Commentary of Gholk's Tridactylrc
I would share commentaris about my tridactylrc here, which may be helpfull. I really think some of they are interesting. Anyone's commentary or improvement are welcome too.
The masked rc is publicly hosted on a self-host gitlab server: https://git.ccns.io/gholk/dot-public/-/blob/master/tridactylrc . The personal information is removed (some bindurl and seturl commands), and so do the commit log. Contact me if you really want to read them.
The commentaries are link to the line number of the commit hash, since track the line numbers with evolution is hard.
Moreover, the commands (or configs) often require some other commands to work. Mostly I will not mention the required commands; you have to find them yourself or just source the whole rc.
All javascript are uglify to one line (but not compressed),
to read or modify them, just prettify it.
(with uglifyjs -b
, firefox's devtool or something else)
I just work in this way.
Tridactyl sometimes mess up the persistent config store in browser,
and it will be hard to maintain a clean rc file without the native messenger and the source
command.
The mktridactylrc fix (alias mktp) command will output a sorted and tidy tridactylrc;
copy it with composite mktridactylrc_fix | yank
.
It will skip the default binding and sort the rc,
so the line number of rc will be stable and we can track it with git.
The source --clipboard
command can source tridactylrc from clipboard.
To use my rc, just copy the whole rc file and call the source --clipboard
command.
note it will not sanitise. To sanitise and source, use the source clipboard sanitise command.
There is a useful jse command, which define many useful functions, and we can reuse them because tridactyl will recursive expand the command alias and append the argument strings.
For example, if we define:
command jse js let $ = q => document.querySelector(q);
command js_body jse let body = $('body');
command body_green js_body body.style.backgroundColor = 'green'
The command body_green
will expand to:
body_green
# -> js_body body.style.backgroundColor = 'green'
# -> jse let body = $('body'); body.style.backgroundColor = 'green'
# -> js let $ = q => document.querySelector(q); let body = $('body'); body.style.backgroundColor = 'green'
jse, jsep
and jse@
are commands define $
$all
$ex
$d
$w
run
.
jsep is same to js -p
, and jse@
is same to js -d@
(you have to add the @
to close a delimiter command).
$ $all
is similar to querySelector and querySelectorAll, $ex async execute a ex command, $d is document and $w is window.
run
is use to execute a wrap async function, so you don't need to (async () => { /* async code here */ })()
,
just run(async () => { /* async */ })
.
ex input node define the node
to the <input>
of the ex cmdline and all the jse
function,
and return the node in js context.
use the node.value
to access ex cmdline's content.
video with define the video
to a video element in the page and all the jse
function,
and return the video in js context.
drop_with
see UI to drop file.
hint_with
see UI to select element TODO.
If you are already in js context and want to reuse the code,
use the $ex
function defined in jse
and make sure the command's js codes will evaluate to the value you want.
The $ex command not only execute the ex command but also return a promise
which resolve to the command's return value.
If you define:
command body_exp js document.body
the await $ex('body_exp')
or composite body_exp | js -p JS_ARG
will evaluate to the document.body
,
but we will not be able to do body_exp body.appendChild(sth)
.
to reuse code in both js context and command expansion context, I define command like this:
command js_body js let body = document.body; body;
These statement still evaluate (the eval
function in js) to body, and we also have a body variable,
or just manually make the last statement be the value you want: await $ex('js_body let child = body.firstChild; child')
.
To get more than one value: let [$, $all] = await $ex('jse [$, $all]')
use the drop with command to open cmdline and accept droping file on it one time.
you have to set the onDrop
callback on the drop with
command.
Eg:
drop_with onDrop = dropEvent => fillcmdline('# the file you drop is ' + dropEvent.dataTransfer.files[0].name)
will open the ex cmdline, wait you drop the file on it, and show the filename you drop.
To read the file content, you need the FileReader
or ArrayBuffer
api;
see the source drop command.
the source drop command will wait you drop the rc file on cmdline and prepare a command to source it (you need to press enter after drop the file).
the rc will be prepand a sanitise tridactyllocal
command so the config will be clean.
to source without sanitise, remove the 'santise tridactyllocal\n' +
in the cmdline.
Press <C-s>
in ex mode will save the content in command line,
and next time you press :
to open command line the save content will present.