The path is provided as an argument by a Makefile within an install
target. The script verifies if the specified path is already included in the system's PATH
variable. If it is not, the script prompts the user for confirmation to add the given path to the PATH
. Upon receiving a positive response, it proceeds to append the specified path to the PATH
variable. For instance, if the path /usr/local
is provided, it will be added to the PATH
variable after user confirmation.
#!/usr/bin/sh
# Check if kilo has been installed
set -e
program=kilo
expected="$(realpath "$1"/$program)"
echo "$PATH" | awk -v RS=: '{print $1 "/kilo" }'
for file in $(echo "$PATH" | awk -v RS=: '{print $1 "/$program" }'); do
if [ ! -e "$file" ]; then
continue
fi
if [ "$(realpath "$file")" = "$expected" ]; then
exit 0
fi
done
tput setaf 1
tput smso
1>&2 cat <<EOF
It appears that kilo was NOT installed successfully. Make sure that
$1
is in your \$PATH. For example, if you are using the Bash shell,
then you have to add
export PATH="$1:\$PATH"
to your ~/.bashrc file.
EOF
tput sgr0
if [ -n "$ZSH_VERSION" ]; then
shrc="$HOME/.zshrc"
elif [ -n "$BASH_VERSION" ]; then
shrc="$HOME/.bashrc"
elif [ -n "FISH_VERSION" ]; then
shrc="$HOME/.config/fish/config.fish"
fi
if [ -e "$shrc" ] && [ "$(tty)" != "not a tty" ]; then
1>&2 printf "\nFix %s automatically (y/N)? " "$shrc"
read -r IN
if [ "$IN" = "y" ] || [ "$IN" = "Y" ]; then
ed -s "$shrc" <<EOF
\$a
# look programs up in the local bin.
export PATH="$1:\$PATH"
.
wq
EOF
1>&2 echo "Done, restart your shell to take effect."
exit 0
fi
fi
exit 1
Review Request:
Anything. Everything.