Is this the correct way to check for sudo access?
has_sudo() {
if [[ "$EUID" = 0 ]]; then
exit 0
else
sudo -k # make sure to ask for password on next sudo
if sudo true; then
exit 0
else
exit 1
fi
fi
}
load_zshenv_on_startup() {
if has_sudo; then
append_zshenv_to_global_files
else
link_zshenv_to_home_directory
fi
}
It’s typically frowned upon to do “magic” like this.
Your program would have more predictable behavior if you implemented a
--global
argument to explicitly request the special actions instead.