| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 | #!/bin/bashcheckout_dir=$HOME/.dofilesscript_dir=$checkout_dir/dotfilesdots_dir=$checkout_dir/dotfiles/dotsrepo="https://git.capella.pro/capella/dotfiles.git"set -extrap popd EXITmkdir -pv $checkout_dirpushd $checkout_dirsub_help(){    echo "Usage: $ProgName <subcommand> [options]\n"    echo "Subcommands:"    echo "    sync <dot_file_to_add>    add a dotfyle to sync"    echo ""    echo "For help with each subcommand run:"    echo "$ProgName <subcommand> -h|--help"    echo ""}sub_sync(){    if [[ ! -d $checkout_dir/dotfiles/.git ]]; then        git clone $repo        pushd dotfiles        git submodule init        popd    fi    cd $script_dir    git pull origin master    git checkout master    git submodule update    if [ ! -z "$1" ]; then        real_path=$(realpath $1)        to_copy=${real_path#*$HOME}        cp -R $real_path $dots_dir/$to_copy        mv -rf $real_path        echo "${to_copy/\//}" >> ../to_sync    fi    while read p; do        file="$dots_dir/$p"        git add $file    done < $script_dir/to_sync    if git commit -am "$(date)"; then        git remote add origin $repo || true        git push -u origin master    fi    while read p; do        destination="$HOME/$p"        rm -rf $destination        ln -s "$dots_dir/$p" $destination    done < $script_dir/to_sync}subcommand=$1case $subcommand in    "" | "-h" | "--help")        sub_help        ;;    *)        shift        sub_${subcommand} $@        if [ $? = 127 ]; then            echo "Error: '$subcommand' is not a known subcommand." >&2            echo "       Run '$ProgName --help' for a list of known subcommands." >&2            exit 1        fi        ;;esac
 |