I prefer to use kudasai … but as some may already know, it should be at the end of the sentencecommand 😅, so I added a custom hook to my ZSH config to make it run commands as pacman -Syu kudasai.
Essentially you can add any type of string matching in the function. Add this to the end of your .zshrc file:
function kudasai_preexec() {
# Check if the last word is ' kudasai'
if [[ $1 == *" kudasai" ]]; then
# Remove ' kudasai' and prepend 'sudo'
cmd=${1%" kudasai"}
eval "sudo $cmd"
# Prevent the original command from running
return 1
fi
}
# Register the preexec hook
autoload -Uz add-zsh-hook
add-zsh-hook preexec kudasai_preexec
Edit: as downside you always get 1 exit code with this implementation (little_annoying) .
I prefer to use
kudasai
… but as some may already know, it should be at the end of thesentencecommand 😅, so I added a custom hook to my ZSH config to make it run commands aspacman -Syu kudasai
.Essentially you can add any type of string matching in the function. Add this to the end of your
.zshrc
file:Edit: as downside you always get
1
exit code with this implementation (little_annoying) .damn, this is some next level shit
Why does it compare against
$1
for the string match? Wouldn’tkudasai
be at the end of something like$*
?