Files
dotify/src/bin/dotify

146 lines
3.2 KiB
Bash
Executable File

#! /usr/bin/env bash
set -e
shopt -s extglob
[ -n "$DOTIFY_DEBUG" ] && set -x
# dotify {{VERSION}}
# https://github.com/jimeh/dotify
#
# Copyright (c) 2013 Jim Myhrberg.
#
# 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.
#
# Helper functions
#
source "../lib/arguments.sh"
source "../lib/trim.sh"
#
# Internal functions
#
source "../lib/internals/compile-dotfile.sh"
source "../lib/internals/create-symlink.sh"
source "../lib/internals/execute-dotfile.sh"
source "../lib/internals/locate-dotfile.sh"
source "../lib/internals/locate-target.sh"
source "../lib/internals/parse-dotfile-options.sh"
#
# Command functions
#
source "../lib/dotify-version.sh"
source "../lib/dotify-help.sh"
source "../lib/dotify-info.sh"
source "../lib/dotify-compile.sh"
source "../lib/dotify-install.sh"
#
# Built-in Plugins
#
source "../plugins/link.sh"
source "../plugins/git.sh"
#
# Argument Parsing
#
DOTFILE="" # --dotfile / -F
TARGET="" # --target / -t
FORCE="" # --force / -f
DRY_RUN="" # --dry-run / -d
HELP="" # --help / -h
VERSION="" # --version / -v
if has-argument dotfile F "$@"; then
DOTFILE="$(parse-argument dotfile F "$@")"
fi
if has-argument target t "$@"; then
TARGET="$(parse-argument target t "$@")"
fi
if has-argument dry-run d "$@"; then
DRY_RUN="1"
fi
if has-argument force f "$@"; then
FORCE="1"
fi
if has-argument help h "$@"; then
HELP="1"
fi
if has-argument version v "$@"; then
VERSION="1"
fi
#
# Command Parsing
#
# Command is first argument that does not start with a dash or plus.
for arg in "$@"; do
if [ -n "$skip_next" ]; then
skip_next=
elif [[ "$arg" =~ ^(--dotfile|-f|--taraget|-t)$ ]]; then
skip_next=1
elif [[ "$arg" != "-"* ]] && [[ "$arg" != "+"* ]]; then
command="$arg"
break
fi
done
# Show help and exit if help arguments or command are given.
if [ -n "$HELP" ] || [ "$command" == "help" ]; then
dotify-help
exit
fi
# Show version info and exit if version arguments or command are given.
if [ -n "$VERSION" ] || [ "$command" == "version" ]; then
dotify-help | head -1
exit
fi
# Deal with the commands.
case "$command" in
"info" )
dotify-info
;;
"compile" )
dotify-compile
;;
"" | "install" )
dotify-install
;;
"uninstall" | "remove" )
dotify-uninstall
;;
esac
exit $?