diff options
Diffstat (limited to 'make_links')
-rwxr-xr-x | make_links | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/make_links b/make_links new file mode 100755 index 0000000..4b6babb --- /dev/null +++ b/make_links @@ -0,0 +1,128 @@ +#!/bin/sh +# vim: ts=4:sw=4:sts=4 +############################################################################# +# Copyright 2021 Christopher Nelson <christopher.nelson@languidnights.com> +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +############################################################################# + +BASEDIR="$(cd "$(dirname "$0")" && pwd )" + +mkdir -p $HOME/.config +mkdir -p $HOME/.local/share +mkdir -p $HOME/.local/bin + +linker() +{ + local destroy="$1" + + while read -r dotfile + do + # Skip blank lines + [ -z "$dotfile" ] && continue + + initial_char=$(echo $dotfile | cut -c1-1) + # Skip lines with a '#' + [ $initial_char = '#' ] && continue + echo "linking $BASEDIR/$dotfile to $HOME/$dotfile" + if [ -f "$HOME/$dotfile" ]; then + if [ $destroy = "true" ]; then + echo "removing $HOME/$dotfile" + rm "$HOME/$dotfile" + elif [ -L $HOME/$dotfile ]; then + echo "$HOME/$dotfile is already a link, skipping" + continue + else + echo "$HOME/$dotfile is a regular file, skipping" + continue + fi + elif [ -d "$HOME/$dotfile" ]; then + if [ -L "$HOME/$dotfile" ]; then + if [ $destroy = "true" ]; then + echo "removing $HOME/$dotfile" + rm "$HOME/$dotfile" + else [ -L "$HOME/$dotfile" ] + echo "$HOME/$dotfile is already a link, skipping" + continue + fi + elif [ $destroy = "true" ]; then + echo "removing $HOME/$dotfile" + rm -r "$HOME/$dotfile" + else + echo "$HOME/$dotfile already exists, skipping" + continue + fi + fi + + if [ ! -d $(dirname "$HOME/$dotfile") ]; then + echo "dir does not exist $(dirname "$HOME/$dotfile")" + mkdir -p $(dirname "$HOME/$dotfile") + echo "creating directory" + fi + + ln -s $BASEDIR/$dotfile $HOME/$dotfile + echo "linked $BASEDIR/$dotfile to $HOME/$dotfile" + + done < $BASEDIR/linked_files +} + +convert_readme() +{ + if [ $(command -v rst2html5) != "" ]; then + rst2html5 $BASEDIR/README.rst > $BASEDIR/README.html + fi +} + +help() +{ + echo "make_links will link out the contents of \"linked_files\" to your home dir" + echo + echo "Syntax: make_links [-d|-h|-l|-n|-m]" + echo "options:" + echo " -d, --destructive Destructively link (removes existing symlinks)" + echo " -h, --help Print this help" + echo " -l, --license Print the license for make_links" + echo " -n, --nondestructive Non-destructively link (existing files and links will be left alone)" + echo " -m, --make-documentation Converts documentation READMEs from rst to HTML" + echo +} + +license() +{ + $PAGER $BASEDIR/COPYING +} + +for arg in "$@"; do + shift + case "$arg" in + "--help") help; exit 0;; + "-h") help; exit 0;; + "--destructive") linker true; exit 0;; + "-d") linker true; exit 0;; + "--nondestructive") linker false; exit 0;; + "-n") linker false; exit 0;; + "--license") license; exit 0;; + "-l") license; exit 0;; + "--make-documentation") convert_readme; exit 0;; + "-m") convert_readme; exit 0;; + esac +done + +help |