-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.sh
executable file
·96 lines (80 loc) · 2.12 KB
/
link.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
if [[ $1 == "--help" ]]; then
echo "Usage: ./link.sh [rhd] [--help]"
echo -e "Symlink dotfiles (config files/directories) to \$HOME/.config\n"
echo "Options:"
echo " -r: Only remove symlinks that would be created by this script"
echo " -h: Also symlinks hyprland config files/directories"
echo " -d: Dry run, only show what would be symlinked"
echo " --help: Show this help message"
exit 0
fi
while getopts ":rhd" opt; do
case $opt in
r) REMOVE_=true;;
h) HYPRLAND_=true;;
d) DRYRUN_=true;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo "Try './link.sh --help' for more information."
exit 1
;;
esac
done
set -e
FILES=(
.zprofile
.bashrc
.zshrc
.p10k.zsh
)
if [[ -z $HOME || -z $PWD ]]; then
echo "Error: \$HOME or \$PWD is not set"
exit 1
fi
if [[ ! -d $HOME/.config ]]; then
mkdir $HOME/.config
echo "Created $HOME/.config"
fi
if [[ -n $HYPRLAND_ ]]; then
DIRS="$(\ls -d *) $(\ls -d _hypr/*)"
else
DIRS=$(\ls -d *)
fi
for DIR in $DIRS; do
if [[ -n $DRYRUN_ && -d $DIR && ($DIR != _* || $DIR == _hypr/* && $DIR != _hypr/_*) ]]; then
echo "[ $DIR ] would be symlinked to $HOME/.config"
continue
fi
if [[ -n $HYPRLAND_ ]]; then
dir="$(echo $DIR | sed 's/_hypr\///')"
rm -rf $HOME/.config/$dir
else
rm -rf $HOME/.config/$DIR
fi
if [[ -n $REMOVE_ ]]; then
echo "Removed $HOME/.config/$DIR symlink"
continue
fi
if [[ -d $DIR && ($DIR != _* || $DIR == _hypr/* && $DIR != _hypr/_*) ]]; then
ln -s $PWD/$DIR $HOME/.config/
echo "Symlinked $DIR to $HOME/.config"
fi
done
for FILE in "${FILES[@]}"; do
if [[ -n $DRYRUN_ && -f $FILE ]]; then
echo "[ $FILE ] would be symlinked to $HOME"
continue
fi
rm -rf $HOME/$FILE
if [[ -n $REMOVE_ ]]; then
echo "Removed $HOME/$FILE symlink"
continue
fi
if [[ -f $FILE ]]; then
ln -s $PWD/$FILE $HOME
echo "Symlinked $FILE to $HOME"
fi
done
echo "Done!"
exit 0