|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -set -e |
4 | | - |
5 | 3 | source ~/.env || { echo "Unable to source .env" && exit 1; } |
6 | 4 |
|
7 | | -find_dotfiles() { |
8 | | - case $1 in |
9 | | - --public) |
10 | | - echo $(find $DOTFILES_REPO_DIR/home -depth 1) |
11 | | - ;; |
12 | | - --private) |
13 | | - echo $(find $DOTFILES_REPO_DIR/private/home -type f) |
14 | | - ;; |
15 | | - esac |
16 | | -} |
| 5 | +pub_home=$DOTFILES_REPO_DIR/home |
| 6 | +prv_home=$DOTFILES_REPO_DIR/private/home |
17 | 7 |
|
18 | | -source_to_target() { |
19 | | - case $1 in |
20 | | - --public) |
21 | | - echo $(echo $2 | sed "s|$DOTFILES_REPO_DIR/home|$HOME|") |
22 | | - ;; |
23 | | - --private) |
24 | | - echo $(echo $2 | sed "s|$DOTFILES_REPO_DIR/private/home|$HOME|") |
25 | | - ;; |
26 | | - esac |
| 8 | +find_dirs() { |
| 9 | + { cd $1 && find .config -type d -mindepth 1; } |
27 | 10 | } |
28 | 11 |
|
29 | | -create_link() { |
30 | | - test -L $2 && rm -f $2 && echo "- $2" |
31 | | - ln -s $1 $2 && echo "+ $2 -> $1" |
| 12 | +find_files() { |
| 13 | + { cd $1 && find .config -type f; } | sort |
32 | 14 | } |
33 | 15 |
|
34 | 16 | create_links() { |
35 | | - echo "Creating public dotfile links" |
36 | | - files=$(find_dotfiles --public) |
37 | | - for f in $files; do |
38 | | - target=$(source_to_target --public $f) |
39 | | - create_link $f $target |
40 | | - done |
| 17 | + echo "Creating directories" |
| 18 | + { find_dirs $pub_home && find_dirs $prv_home; } | |
| 19 | + sort | uniq | xargs -I % bash -c 'mkdir -p ~/%; echo ~/%' |
41 | 20 |
|
42 | | - echo "Creating private dotfile links" |
43 | | - files=$(find_dotfiles --private) |
44 | | - for f in $files; do |
45 | | - target=$(source_to_target --private $f) |
46 | | - create_link $f $target |
47 | | - done |
48 | | -} |
49 | | - |
50 | | -remove_link() { |
51 | | - test -L $1 && rm -f $1 && echo "- $1" |
| 21 | + echo "Creating links" |
| 22 | + find_files $pub_home | xargs -I % bash -c "ln -sf $pub_home/% ~/%; echo ~/%" |
| 23 | + find_files $prv_home | xargs -I % bash -c "ln -sf $prv_home/% ~/%; echo ~/%" |
52 | 24 | } |
53 | 25 |
|
54 | 26 | remove_links() { |
55 | | - echo "Removing private dotfile links" |
56 | | - files=$(find_dotfiles --private) |
57 | | - for f in $files; do |
58 | | - target=$(source_to_target --private $f) |
59 | | - remove_link $target |
60 | | - done |
61 | | - |
62 | | - echo "Removing public dotfile links" |
63 | | - files=$(find_dotfiles --public) |
64 | | - for f in $files; do |
65 | | - target=$(source_to_target --public $f) |
66 | | - remove_link $target |
67 | | - done |
| 27 | + echo "Removing links" |
| 28 | + { find_files $pub_home && find_files $prv_home; } | |
| 29 | + xargs -I % bash -c '[ -L ~/% ] && rm -f ~/% && echo ~/%' |
68 | 30 | } |
0 commit comments