Skip to content

Commit 25dc467

Browse files
committed
Create links to files, not directories
1 parent 8aa765e commit 25dc467

3 files changed

Lines changed: 23 additions & 62 deletions

File tree

.gitignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

cfgmanager.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,18 @@ bootstrap() {
7171
}
7272

7373
case $1 in
74+
--create-links)
75+
source $DOTFILES_REPO_DIR/scripts/links.sh
76+
create_links
77+
;;
7478
--brew-bundle)
7579
source $DOTFILES_REPO_DIR/scripts/brew.sh
7680
brew_bundle
7781
;;
82+
--remove-links)
83+
source $DOTFILES_REPO_DIR/scripts/links.sh
84+
remove_links
85+
;;
7886
*)
7987
bootstrap
8088
;;

scripts/links.sh

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,30 @@
11
#!/usr/bin/env bash
22

3-
set -e
4-
53
source ~/.env || { echo "Unable to source .env" && exit 1; }
64

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
177

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; }
2710
}
2811

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
3214
}
3315

3416
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 ~/%'
4120

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 ~/%"
5224
}
5325

5426
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 ~/%'
6830
}

0 commit comments

Comments
 (0)