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
}
```
I need to evaluate this variables before appending this lines to a few files:
```
sudo tee -a /etc/profile /etc/zshenv /etc/zsh/zshenv &>/dev/null <<EOF
export XDG_CONFIG_HOME="$SYNC"/config
export XDG_CACHE_HOME="$HOME"/.cache
export XDG_DATA_HOME="$HOME"/.local/share
export XDG_STATE_HOME="$HOME"/.local/state
export ZDOTDIR="$XDG_CONFIG_HOME"/zsh
EOF
```
For example I have a function that appends to a file a few lines. But if something else fails in the script I wouldn't want to fix it and execute it again, and then have those lines duplicated.
How do I improve this function efficiency so that it only searches once instead of three times:
```
# Fixes permissions for files and directories in the given folder or the current folder
fixperms() {
find "${1:-.}" -type f -executable -exec chmod 744 {} \;
find "${1:-.}" -type f ! -executable -exec chmod 644 {} \;
find "${1:-.}" -type d -exec chmod 755 {} \;
}
```
I want to let every file know the path of the root of a project. For example let's consider this the root: `/home/username/.config/project`. If I have a folder in the project and every file in the folder has a line like `ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"` (gets the absolute path of the parent directory) whenever I move the folder to another location I may have to change that line for every file in the folder.
Is there a better option to let every file know the path of the project root?