89 lines
1.9 KiB
Bash
Executable File
89 lines
1.9 KiB
Bash
Executable File
#!/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
|
|
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
|
|
}
|
|
|
|
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"
|
|
|
|
[[ ! -w "${DIRECTORY}" ]] && error "You lack permissions to write to \"${DIRECTORY}\""
|
|
|
|
[[ $(confirmation "Copying *.nanorc files to ${DIRECTORY}, continue (y/N)? ") ]] && exit 1
|
|
|
|
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;
|
|
|
|
echo "Copying syntax files to ${DIRECTORY}"
|
|
cp -R "Nano-Syntax-Highlighting"/* "${DIRECTORY}"
|
|
|
|
NANORC_CONTENT="$(cat ./.nanorc)"
|
|
|
|
cat << EOF > ~/.nanorc
|
|
${NANORC_CONTENT}
|
|
include ${DIRECTORY}/*.nanorc
|
|
EOF
|
|
|
|
mkdir -p ~/Nano-Backups
|
|
|
|
echo "Successfully installed custom nanorc, see ~/.nanorc"
|