|
2 | 2 |
|
3 | 3 | set -euo pipefail |
4 | 4 |
|
5 | | -[ -f ~/.env ] && source ~/.env |
6 | | - |
7 | 5 | set_env() { |
8 | 6 | while true; do |
9 | 7 | echo "Confgure environement for:" |
@@ -37,6 +35,64 @@ set_env() { |
37 | 35 |
|
38 | 36 | echo "CONFIG_ENV=$ENV" >~/.env |
39 | 37 | echo "DOTFILES_REPO_DIR=$REPO_DIR" >>~/.env |
| 38 | + source ~/.env |
| 39 | +} |
| 40 | + |
| 41 | +create_links() { |
| 42 | + echo "Creating links" |
| 43 | + pub_home=$DOTFILES_REPO_DIR/home |
| 44 | + prv_home=$DOTFILES_REPO_DIR/private/home |
| 45 | + |
| 46 | + dirs=$(find $pub_home -type d -depth 1) |
| 47 | + for source in $dirs; do |
| 48 | + target=$(echo $source | sed "s|$pub_home|$HOME|") |
| 49 | + |
| 50 | + if [ -d $target ]; then |
| 51 | + if [ -L $target ]; then |
| 52 | + rm -f $target |
| 53 | + else |
| 54 | + echo "$target: Directory exists" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + fi |
| 58 | + |
| 59 | + ln -s $source $target |
| 60 | + echo $target |
| 61 | + done |
| 62 | + |
| 63 | + files=$(find $pub_home -type f -depth 1) |
| 64 | + for source in $files; do |
| 65 | + target=$(echo $source | sed "s|$pub_home|$HOME|") |
| 66 | + |
| 67 | + if [ -L $target ]; then |
| 68 | + rm -f $target |
| 69 | + fi |
| 70 | + |
| 71 | + ln -s $source $target |
| 72 | + echo $target |
| 73 | + done |
| 74 | + |
| 75 | + files=$(find $prv_home -type f) |
| 76 | + for source in $files; do |
| 77 | + target=$(echo $source | sed "s|$prv_home|$HOME|") |
| 78 | + |
| 79 | + if [ -L $target ]; then |
| 80 | + rm -f $target |
| 81 | + fi |
| 82 | + |
| 83 | + ln -s $source $target |
| 84 | + echo $target |
| 85 | + done |
| 86 | +} |
| 87 | + |
| 88 | +prune_links() { |
| 89 | + echo "Pruning broken links" |
| 90 | + find -L ~ -path ~/Library -prune -o -lname $DOTFILES_REPO_DIR/\* -exec rm -f {} \; -print 2>/dev/null |
| 91 | +} |
| 92 | + |
| 93 | +remove_links() { |
| 94 | + echo "Removing all links" |
| 95 | + find ~ -path ~/Library -prune -o -lname $DOTFILES_REPO_DIR/\* -exec rm -f {} \; -print 2>/dev/null |
40 | 96 | } |
41 | 97 |
|
42 | 98 | install_brew() { |
@@ -93,15 +149,12 @@ case $1 in |
93 | 149 | bundle_cleanup |
94 | 150 | ;; |
95 | 151 | --create-links) |
96 | | - source $DOTFILES_REPO_DIR/scripts/links.sh |
97 | 152 | create_links |
98 | 153 | ;; |
99 | 154 | --prune-links) |
100 | | - source $DOTFILES_REPO_DIR/scripts/links.sh |
101 | 155 | prune_links |
102 | 156 | ;; |
103 | 157 | --remove-links) |
104 | | - source $DOTFILES_REPO_DIR/scripts/links.sh |
105 | 158 | remove_links |
106 | 159 | ;; |
107 | 160 | -h | --help) |
|
0 commit comments