12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/bin/bash
- dot_dir=$HOME/.dofiles
- repo="https://git.capella.pro/capella/dotfiles.git"
- set -ex
- trap popd EXIT
- mkdir -pv $dot_dir
- pushd $dot_dir
- sub_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 $dot_dir/dotfiles/.git ]]; then
- git clone $repo
- pushd dotfiles
- git submodule init
- git submodule update
- popd
- fi
- mkdir -p dotfiles/dots
- cd dotfiles/dots
- git pull
- if [ ! -z "$1" ]; then
- real_path=$(realpath $1)
- to_copy=${real_path#*$HOME}
- cp -R $real_path $(pwd)$to_copy
- rm -rf $real_path
- echo "${to_copy/\//}" >> ../to_sync
- fi
- cd ..
- git add .
- 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 "$dot_dir/dotfiles/dots/$p" $(dirname $destination)
- done <to_sync
- }
- subcommand=$1
- case $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
|