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 %{
|
||||
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 "<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" %{
|
||||
%sh{
|
||||
# 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: ' %{
|
||||
define-command -hidden sudo-prompt-password %{
|
||||
prompt -password 'Password:' %{
|
||||
try %{
|
||||
cache-password %val{text}
|
||||
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
|
||||
else
|
||||
echo sudo-prompt-password
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user