Go to file
2022-03-07 21:50:52 -05:00
dist Add demo asciinema 2022-01-25 00:14:05 -05:00
src Use BufWriter instead of File 2022-03-07 21:50:52 -05:00
.gitignore Add initial code 2022-01-22 16:29:02 -05:00
Cargo.lock Use a BTreeSet of hashesh instead of a HashMap of unit 2022-03-06 21:29:15 -05:00
Cargo.toml Use BufWriter instead of File 2022-03-07 21:50:52 -05:00
README.adoc Use a BTreeSet of hashesh instead of a HashMap of unit 2022-03-06 21:29:15 -05:00
rustfmt.toml Format import granularity 2022-02-21 18:30:32 -05:00

= rust-selection-sort.kak

Sort selections by regular expression or lexicographically

== Example

. Imagine you want to sort these stages
+
[source,groovy]
----
stage('Package (#3)') {
    // ...
}

stage('Build (#2)') {
    // ...
}

stage('Initialize (#1)') {
    // ...
}

stage('Publish (#4)') {}
----

. Select the stage and stage body with: `%sstage<ret>MLM`
. Sort the selection by step number with: `:sort-selections #\d+<ret>` (sort on whole capture) or `:sort-selections "'.+?#(\d).+?'"` (sort on first capture group, which contains only the digits)
. Note if you just run `:sort-selections<ret>`

== Configuration

[source,sh,title='sh']
----
cargo install --git https://github.com/austenadler/rust-selection-sort.kak
----

[source,title='kakrc']
----
define-command sort-selections -params 0.. %{
    eval -save-regs '"' %{
        reg dquote %val{selections}
        eval %sh{
            regex="${1:-.*}"
            # use kak_command_fifo kak_response_fifo;
            ~/syncthing/code/kakutils-rs/target/debug/kakutils-rs sort "$regex" -- "$@"
        }
        exec R
    }
}
----

== Usage

* Make multiple selections
* Run `sort-selections` to sort the selections lexicographically (TODO: implement a `sort -h` like feature)
* Run `sort-selections REGEX` to sort by regex match
** If the regex does not contain a capture group
** If the regex contains at least one capture group

== TODO

* I don't know what will happen with multiline strings
* Use 2 fifos for getting and sending selections since this should be faster than sending this to shell
* Send options (`-S`) to cli from kak
* Figure out how to change the `no_skip_whitespace` option name in the source