65 lines · 1.5 KB · executable
#!/usr/bin/env bash

os="$(which_os)"

symlinksFile="$DOTFILES/symlinks.yml"

# Ensure the given programs exists, exiting with error if not.
#
# Example:
#     require sponge realpath
function require() {
    for arg in "$@"; do
        if [[ "$(command_exists "$arg")" != 1 ]]; then
            printf '%s is required. Please install it and try again.\n' "$arg"
            exit 1
        fi
    done
}

# Get symlinks as key-value pairs, one per line. Common symlinks are merged
# into the target group.
#
# Example:
#     getSymlinkGroup void
function getSymlinks() {
    yq e ".common *+ .$1 | .[] | .src + \" \" + .dst" "$symlinksFile"
}

# Perform symlinking, removing any existing file or directory at the
# destination. The local path is relative to the repository root. The remote
# path is relative to the user's home directory.
#
# Example:
#     link myCuteBashrc .bashrc
function link() {
    local src="$DOTFILES/$1"
    local dst="$HOME/$2"

    if [[ ! -f $src && ! -d $src ]]; then
        printf 'Warning:\n    %s does not exist\n    ...so we cannot symlink it to %s\n' "$src" "$dst"