slight refactoring

This commit is contained in:
Olivier Perret 2018-06-02 10:12:40 +02:00
parent bf01679b4d
commit 7ea68cf618

View File

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