HOSTS=("$@")
# Config files
for TARGET in ".inputrc" ".config/starship.toml"; do
  SOURCE="$HOME/$TARGET"
  echo "--- $SOURCE ---"
  TMP_TARGET=/tmp/rsync-local-config
  TMP_SOURCE=$TMP_TARGET
  NIX_SED="sed -i 's|/nix/.*/bin/||g'"
  NIX_REPLACE="$NIX_SED $TMP_TARGET"
  if [[ -e $SOURCE ]]; then
    if [[ -d $SOURCE ]]; then
      SOURCE=$SOURCE/
      TMP_SOURCE=$TMP_SOURCE/
      NIX_REPLACE="fd -g '**' $TMP_TARGET -tfile -x $NIX_SED {};"
    fi
    rsync -avzL --exclude=".git*" --chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r "$SOURCE" $TMP_TARGET
    sh -c "$NIX_REPLACE"
    for HOST in "${HOSTS[@]}"; do
      rsync -avzL --delete --exclude=".git*" $TMP_SOURCE "$HOST:$TARGET"
    done
    rm -rf $TMP_SOURCE
  fi
done