-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotfiles.sh
executable file
·79 lines (69 loc) · 1.92 KB
/
dotfiles.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
#!/usr/bin/env bash
# Define the target directory
TARGET_DIR="$HOME"
# Define an array of dotfiles directories to be managed
DOTFILES=("shell" "tmux" "nvim" "vim" "git" "alacritty" "clangd")
# Function to print usage information
usage() {
echo "Usage: $0 [stow|unstow|restow]"
echo
echo "Options:"
echo " stow Symlink the dotfiles to the home directory"
echo " unstow Remove the symlinks from the home directory"
echo " restow Re-symlink the dotfiles to the home directory (unstow followed by stow)"
echo
echo "Example:"
echo " $0 stow # Symlink the dotfiles"
echo " $0 unstow # Remove the symlinks"
echo " $0 restow # Re-symlink the dotfiles"
exit 1
}
# Check if stow is installed, and install it if not
if ! command -v stow &> /dev/null; then
echo "stow is not installed. Installing stow..."
# Detect the operating system and install stow accordingly
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y stow
else
echo "Unsupported Linux distribution. Please install stow manually."
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
if command -v brew &> /dev/null; then
brew install stow
else
echo "Homebrew is not installed. Please install Homebrew and try again."
exit 1
fi
else
echo "Unsupported operating system. Please install stow manually."
exit 1
fi
fi
# Check for correct number of arguments
if [ "$#" -ne 1 ]; then
usage
fi
# Determine the operation based on the first argument
OPERATION=$1
case $OPERATION in
stow)
STOW_OPTION="-S"
;;
unstow)
STOW_OPTION="-D"
;;
restow)
STOW_OPTION="-R"
;;
*)
usage
;;
esac
# Iterate over the array and stow/unstow/restow each directory
for dir in "${DOTFILES[@]}"; do
stow $STOW_OPTION -t "$TARGET_DIR" "$dir"
done
echo "Dotfiles $OPERATION completed."