Quickly toggle between $kak_ and %...{

Hello,
I written the following command and wanted to share with you.
It toggle $kak_foo to %val{foo} and vis-versa, it also work with options.
It is not extensively tested but it worked for me in a few cases.

define-command toggle_kak_bash -docstring 'toggle between kak/bash syntax' %(
    execute-keys '<a-i><a-w>' # <- you might want to edit this

    evaluate-commands %sh[
        is_bash=$(echo $kak_selection | grep '^\$kak_')
        if [ -n "$is_bash" ];then
            is_kak_opt=$(echo $kak_selection | grep '^\$kak_opt')
            if [ -n "$is_kak_opt" ];then
                echo "execute-keys li}<esc>h<a-i><a-w><a-semicolon><semicolon>LLLLLLLLc<percent>opt{<esc>"
            else
                echo "execute-keys li}<esc>h<a-i><a-w><a-semicolon><semicolon>LLLLc<percent>val{<esc>"
            fi
        else


            is_kak_val=$(echo $kak_selection | grep '%val{')
            if [ -n "$is_kak_val" ];then
                echo " execute-keys '<semicolon>dh<a-i><a-w><a-semicolon><semicolon>LLLLc\$kak_<esc>'"
                exit
            fi

            is_kak_opt=$(echo $kak_selection | grep '%opt{')
            if [ -n "$is_kak_opt" ];then
                echo " execute-keys '<semicolon>dh<a-i><a-w><a-semicolon><semicolon>LLLLc\$kak_opt_<esc>'"
                exit
            fi

        fi
        echo "echo 'syntax could not be interpreted'"
    ]
)
3 Likes