12/07/22
09/5/1444
I like helix, especially multi-cursor supports which unfortunately for nvim seems hard to add
So everyone is waiting for the plugin system, till then here is a not so bad plugin like experience
mkdir -p ~/dev/helix/scripts/source
This example uses fish, other shell have similar abilities
function hx
set PATH_TMP $PATH
set PATH ~/dev/helix/scripts/ $PATH
helix $argv
set PATH $PATH_TMP
end
funcsave hx
So now hx
is aliased to helix that knows about our scripts path
I'm going to use deno here, but any compiled program can work
The advantage of deno, is the programs have 0 permissions by default which works actually very well as a plugin
But realisticly you want a compiled language, for the fastest cold startup time. I prefer Zig for this since it makes the lowest amount of syscalls possible by default in linux for example.
cd ~/dev/helix/scripts
Here is an example for a script I just needed that just simply flips ]
to )
and [
to (
source/f.ts
const buf = new Uint8Array(256);
const n = await Deno.stdin.read(buf);
const a = new TextDecoder().decode(buf.slice(0, n!));
let r;
switch (a) {
case "]":
r = ")";
break;
case "[":
r = "(";
break;
default:
r = a;
}
Deno.stdout.writeSync(new TextEncoder().encode(r));
Or another script that acts as a snippet (just inserts console.log)
Deno.stdout.writeSync(new TextEncoder().encode("console.log("));
This example uses fish syntax, other shell have similar workflow
for f in (ls source)
deno compile source/$f
end
That's it, now when running helix, we can pipe a selection to our scripts using the pipe command
which is bound to |
key by default (can be changed, I have personally "ยต" = "shell_pipe"
for azerty keyboard)