Last active
November 8, 2020 00:26
-
-
Save nothub/ba7c6047291857fc3b79f6737b72aa8f to your computer and use it in GitHub Desktop.
use this instead: https://github.com/blockparole/reclink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [ -n "$1" ] && [ "$1" != "-f" ]; then | |
echo "put your dotfiles and this script in the same folder (eg. \$HOME/.dotfiles/)" | |
echo "keep the same folder structure as in \$HOME" | |
echo "run the script from anywhere, it will create links for the dotfiles" | |
echo "-f allows overwriting of existing files" | |
exit 0 | |
fi | |
if [ "$1" == "-f" ]; then | |
echo "overwriting existing files!" | |
DOT_FORCE="-f" | |
export DOT_FORCE | |
fi | |
DOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" | |
export DOT_DIR | |
DOT_SCRIPT="$(basename "$0")" | |
export DOT_SCRIPT | |
mirror_folders () { | |
if [ -n "$1" ] && [[ "$1" != .git ]]; then | |
mkdir -p "$1" | |
fi | |
} | |
export -f mirror_folders | |
link_recursive () { | |
if [ -n "$1" ] && [[ "$1" != .git/* ]] && [ "$1" != "$DOT_SCRIPT" ]; then | |
ln -s -v "$DOT_FORCE" "$DOT_DIR"/"$1" "$HOME"/"$1" || echo unable to write "$HOME"/"$1"! | |
fi | |
} | |
export -f link_recursive | |
cd "$HOME" | |
find "$DOT_DIR" -type d -printf '%P\n' | xargs -n 1 -I {} bash -c 'mirror_folders "$@"' _ {} | |
find "$DOT_DIR" -type f -printf '%P\n' | xargs -n 1 -I {} bash -c 'link_recursive "$@"' _ {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment