Skip to content

Commit 0f764d9

Browse files
committed
Move link functions to cfgmanager
1 parent 9abaedc commit 0f764d9

2 files changed

Lines changed: 58 additions & 27 deletions

File tree

bin/cfgmanager

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
set -euo pipefail
44

5-
[ -f ~/.env ] && source ~/.env
6-
75
set_env() {
86
while true; do
97
echo "Confgure environement for:"
@@ -37,6 +35,64 @@ set_env() {
3735

3836
echo "CONFIG_ENV=$ENV" >~/.env
3937
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
4096
}
4197

4298
install_brew() {
@@ -93,15 +149,12 @@ case $1 in
93149
bundle_cleanup
94150
;;
95151
--create-links)
96-
source $DOTFILES_REPO_DIR/scripts/links.sh
97152
create_links
98153
;;
99154
--prune-links)
100-
source $DOTFILES_REPO_DIR/scripts/links.sh
101155
prune_links
102156
;;
103157
--remove-links)
104-
source $DOTFILES_REPO_DIR/scripts/links.sh
105158
remove_links
106159
;;
107160
-h | --help)

scripts/links.sh

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

0 commit comments

Comments
 (0)