dotfiles/.config/kak/autoload/util.kak

72 lines
2.1 KiB
Text

define-command \
-docstring %{
Replace the selections with the date, with the args passed as a
string to date -d.
} \
insert-date -params 0.. %{
evaluate-commands -draft -save-regs '|"' %{
set-register | "date -d '%arg{@}' '+%%Y-%%m-%%d' | tr -d '\n'"
echo -debug "Inserting date: %reg{pipe}"
# we delete the trailing newline
execute-keys '|<ret>'
}
}
alias global date insert-date
define-command -params 2 \
-docstring %{
Swap all occurrence of the first parameter with the second in
selection.
} \
swap %{
evaluate-commands -save-regs | %{
set-register | %exp{
sed "s/%arg{1}/𝅙/; \
s/%arg{2}/%arg{1}/; s/𝅙/%arg{2}/"
}
execute-keys '|<ret>'
}
}
define-command -params 2 \
-docstring %{
Swap all occurence of param A with param B in selections.
} \
swap-buffer %{
evaluate-commands -save-regs "ab" -draft %{
set-register a %arg{1}
set-register b %arg{2}
execute-keys "<percent>s\Q<c-r>a\E|\Q<c-r>b\E<ret>"
swap "%arg{1}" "%arg{2}"
}
}
define-command regswap -params 2 %{
evaluate-commands -draft -save-regs "abcd" %{
set-register a %arg{1}
set-register b %arg{2}
execute-keys -draft '"xZZs\Q<c-r>a\E<ret>"cZzs\Q<c-r>b\E<ret>"dZ"cz"bR"dz"aRz'
}
}
define-command -docstring %{
pastes [<name>]: paste the selection(s) to pastes.sh. Separate selections are appended into one. Resulting URL is printed to *debug* and copied to clipboard.
Arguments:
name optional filename for the paste
} -params 0..1 pastes %{
evaluate-commands -draft -save-regs '"ab|' %{
set-register b %val{bufname}
execute-keys '"ay'
edit -scratch
set-register | "ssh pastes.sh %arg{1} 2>/dev/null"
execute-keys '"a<a-R>%|<ret>%s\r<ret>d%_"ay'
set-register | "wl-copy -n"
execute-keys '<a-|><ret>'
echo -debug %reg{a}
hook -once global WinDisplay %exp{\Q%reg{b}\E} %{
info -title 'pastes.sh' "%reg{a}"
}
delete-buffer
}
}