2021-07-19 13:13:57 -05:00
|
|
|
#!/bin/bash --posix
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
DIRECTORY="/usr/local/share/nano"
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
printf "%s\n" "Usage: bash Install-Nano.bash -d <path>
|
|
|
|
--directory <dir> | -d <dir>
|
|
|
|
Explanation:
|
|
|
|
The directory to install the nano syntax highlighting files to
|
|
|
|
Default:
|
|
|
|
/usr/local/share/nano/
|
|
|
|
Example:
|
|
|
|
--syntax-directory ~/.nano/
|
|
|
|
|
|
|
|
Requires two things:
|
|
|
|
- Directory names \"Nano-Syntax-Highlighting\" that contains .nanorc files
|
|
|
|
- File \".nanorc\" that contains configuration settings for nano"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
printf "\n%s\n" "$1" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmation() {
|
|
|
|
while true; do
|
2021-07-28 09:32:08 -05:00
|
|
|
read -p "${1}" -n 1 -r choice
|
|
|
|
case "$choice" in
|
|
|
|
y | Y) return 1 ;;
|
|
|
|
n | N) return 0 ;;
|
|
|
|
*) echo -e "\nInput must be either y, Y, n, or N" ;;
|
|
|
|
esac
|
|
|
|
done
|
2021-07-19 13:13:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
while :; do
|
|
|
|
case $1 in
|
|
|
|
-h | -\? | --help)
|
|
|
|
usage # Display a usage synopsis.
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
--) # End of all options.
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-d | --directory)
|
|
|
|
shift
|
|
|
|
DIRECTORY="${1}"
|
|
|
|
;;
|
|
|
|
-?*)
|
|
|
|
printf 'Unknown option: %s\n' "$1" >&2
|
|
|
|
usage
|
|
|
|
error
|
|
|
|
;;
|
|
|
|
*) # Default case: No more options, so break out of the loop.
|
|
|
|
break ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
[[ "${DIRECTORY}" == "" ]] && error "A directory was not provided!"
|
|
|
|
[[ ! -d "${DIRECTORY}" ]] && error "The directory \"${DIRECTORY}\" does not exist"
|
|
|
|
|
2021-07-19 13:35:03 -05:00
|
|
|
[[ ! -w "${DIRECTORY}" ]] && error "You lack permissions to write to \"${DIRECTORY}\""
|
2021-07-19 13:13:57 -05:00
|
|
|
|
|
|
|
[[ $(confirmation "Copying *.nanorc files to ${DIRECTORY}, continue (y/N)? ") ]] && exit 1
|
|
|
|
|
2021-07-31 09:52:27 -05:00
|
|
|
echo ""
|
|
|
|
echo "It is recommended to update to Nano version 5 if you have not yet... see https://www.nano-editor.org/download.php"
|
|
|
|
sleep 3;
|
2021-07-19 13:13:57 -05:00
|
|
|
|
|
|
|
echo "Copying syntax files to ${DIRECTORY}"
|
2021-07-31 09:52:27 -05:00
|
|
|
cp -R "Nano-Syntax-Highlighting"/* "${DIRECTORY}"
|
2021-07-19 13:13:57 -05:00
|
|
|
|
|
|
|
NANORC_CONTENT="$(cat ./.nanorc)"
|
|
|
|
|
2021-07-31 09:52:27 -05:00
|
|
|
cat << EOF > ~/.nanorc
|
2021-07-19 13:13:57 -05:00
|
|
|
${NANORC_CONTENT}
|
2021-07-31 09:52:27 -05:00
|
|
|
include ${DIRECTORY}/*.nanorc
|
2021-07-19 13:13:57 -05:00
|
|
|
EOF
|
|
|
|
|
2021-08-10 04:18:08 -05:00
|
|
|
mkdir -p ~/Nano-Backups
|
|
|
|
|
2021-07-19 13:13:57 -05:00
|
|
|
echo "Successfully installed custom nanorc, see ~/.nanorc"
|