mirror of
https://github.com/occivink/kakoune-sudo-write
synced 2025-04-02 22:40:36 +02:00
slight refactoring
This commit is contained in:
parent
bf01679b4d
commit
7ea68cf618
@ -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 -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" %{
|
define-command sudo-write -docstring "Write the content of the buffer using sudo" %{
|
||||||
%sh{
|
%sh{
|
||||||
# check if the password is cached
|
# check if the password is cached
|
||||||
if sudo -n true > /dev/null 2>&1; then
|
if sudo -n true > /dev/null 2>&1; then
|
||||||
echo "sudo-write-impl"
|
echo sudo-write-impl
|
||||||
else
|
else
|
||||||
# if not, ask for it
|
echo sudo-prompt-password
|
||||||
echo "prompt -password 'Password: ' %{
|
|
||||||
try %{
|
|
||||||
cache-password %val{text}
|
|
||||||
sudo-write-impl
|
|
||||||
} catch %{
|
|
||||||
echo -markup '{Error}Incorrect password'
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user