This is the first push to this repo with my dotfiles
[dotfilesold/.git] / .nano / install.sh
1 #!/bin/sh
2
3 # check for unzip before we continue
4 if [ ! "$(command -v unzip)" ]; then
5   echo 'unzip is required but was not found. Install unzip first and then run this script again.' >&2
6   exit 1
7 fi
8
9 _fetch_sources(){
10   wget -O /tmp/nanorc.zip https://github.com/scopatz/nanorc/archive/master.zip
11   mkdir -p ~/.nano/
12
13   cd ~/.nano/ || exit
14   unzip -o "/tmp/nanorc.zip"
15   mv nanorc-master/* ./
16   rm -rf nanorc-master
17   rm /tmp/nanorc.zip
18 }
19
20 _update_nanorc(){
21   touch ~/.nanorc
22       
23   # add all includes from ~/.nano/nanorc if they're not already there
24   while read -r inc; do
25       if ! grep -q "$inc" "${NANORC_FILE}"; then
26           echo "$inc" >> "$NANORC_FILE"
27       fi
28   done < ~/.nano/nanorc
29 }
30
31 _update_nanorc_lite(){
32   sed -i '/include "\/usr\/share\/nano\/\*\.nanorc"/i include "~\/.nano\/*.nanorc"' "${NANORC_FILE}"
33 }
34
35 NANORC_FILE=~/.nanorc
36
37 case "$1" in
38  -l|--lite)
39    UPDATE_LITE=1;;
40  -h|--help)
41    echo "Install script for nanorc syntax highlights"
42    echo "Call with -l or --lite to update .nanorc with secondary precedence to existing .nanorc includes"
43  ;;
44 esac
45
46 _fetch_sources;
47 if [ $UPDATE_LITE ];
48 then
49   _update_nanorc_lite
50 else
51   _update_nanorc
52 fi