Skip to content

Instantly share code, notes, and snippets.

@cipharius
Last active April 18, 2024 14:39
Show Gist options
  • Save cipharius/6f5132bfbd447c1e89c33ab9583657ee to your computer and use it in GitHub Desktop.
Save cipharius/6f5132bfbd447c1e89c33ab9583657ee to your computer and use it in GitHub Desktop.

Revisions

  1. cipharius revised this gist Jul 19, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions sort-selections.kak
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    define-command sort-selections -params 0.. -override -docstring '
    sort-selections: Sort current selections
    All parameters will be passed to the unix sort command
    sort-selections: Sort current selections using GNU sort utility
    All parameters will be passed to the GNU sort utility
    ' %{
    # Copy current selections to a temporary sort buffer
    execute-keys %{"sy}
    edit -scratch *sort-selections*
    execute-keys %{"s<a-p>}

    # Seperate selections with null characters
    execute-keys %{<a-!>echo -ne '\x00'<ret>ggd}
    execute-keys %{<a-!>printf '\000'<ret>ggd}

    # Sort the buffer
    # Use `head -c-1` to get rid of leading newline
  2. cipharius revised this gist Jul 19, 2019. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions sort-selections.kak
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    define-command sort-selections -docstring '
    define-command sort-selections -params 0.. -override -docstring '
    sort-selections: Sort current selections
    All parameters will be passed to the unix sort command
    ' %{
    # Copy current selections to a temporary sort buffer
    execute-keys %{"sy}
    @@ -10,10 +11,11 @@ sort-selections: Sort current selections
    execute-keys %{<a-!>echo -ne '\x00'<ret>ggd}

    # Sort the buffer
    execute-keys %{%|sort -z<ret>ggd}
    # Use `head -c-1` to get rid of leading newline
    execute-keys "%%|head -c-1|sort -z %arg{@}<ret>"

    # Yank the sorted candidates
    execute-keys %{%H<a-;>LS\x00<ret>"sy}
    execute-keys %{%HS\x00<ret>"sy}

    # Update the original buffer
    delete-buffer
  3. cipharius created this gist Jul 19, 2019.
    21 changes: 21 additions & 0 deletions sort-selections.kak
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    define-command sort-selections -docstring '
    sort-selections: Sort current selections
    ' %{
    # Copy current selections to a temporary sort buffer
    execute-keys %{"sy}
    edit -scratch *sort-selections*
    execute-keys %{"s<a-p>}

    # Seperate selections with null characters
    execute-keys %{<a-!>echo -ne '\x00'<ret>ggd}

    # Sort the buffer
    execute-keys %{%|sort -z<ret>ggd}

    # Yank the sorted candidates
    execute-keys %{%H<a-;>LS\x00<ret>"sy}

    # Update the original buffer
    delete-buffer
    execute-keys %{"sR}
    }