diff --git a/sudo-write.kak b/sudo-write.kak index 80c9e56..1241c19 100644 --- a/sudo-write.kak +++ b/sudo-write.kak @@ -3,10 +3,10 @@ define-command -hidden sudo-write-impl %{ eval -save-regs f %{ - set-register f "%sh{ mktemp --tmpdir XXXXX }" + set-register f %sh{ mktemp --tmpdir XXXXX } write %reg{f} %sh{ - sudo -- dd if="$kak_reg_f" of="$kak_buffile" >/dev/null 2>&1 + sudo -n -- dd if="$kak_reg_f" of="$kak_buffile" >/dev/null 2>&1 if [ $? -eq 0 ]; then echo "edit!" else @@ -17,8 +17,8 @@ define-command -hidden sudo-write-impl %{ } } -define-command -hidden -params 1 cache-password %{ - eval -draft %{ +define-command -hidden -params 1 sudo-cache-password %{ + eval -no-hooks -draft %{ edit -scratch *sudo_write_pass* reg '"' %arg{1} exec "|sudo -S echo ok" @@ -32,21 +32,24 @@ define-command -hidden -params 1 cache-password %{ } } +define-command -hidden sudo-prompt-password %{ + prompt -password 'Password:' %{ + try %{ + sudo-cache-password %val{text} + sudo-write-impl + } catch %{ + echo -markup '{Error}Incorrect password' + } + } +} + define-command sudo-write -docstring "Write the content of the buffer using sudo" %{ %sh{ # check if the password is cached if sudo -n true > /dev/null 2>&1; then - echo "sudo-write-impl" + echo sudo-write-impl else - # if not, ask for it - echo "prompt -password 'Password: ' %{ - try %{ - cache-password %val{text} - sudo-write-impl - } catch %{ - echo -markup '{Error}Incorrect password' - } - }" + echo sudo-prompt-password fi } }