-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.sh
executable file
·100 lines (88 loc) · 2.96 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
97
98
99
100
#!/bin/bash
dotfiles_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
config_dir="$HOME/.config"
source "$dotfiles_dir/install/utils.sh"
if [[ ! -d "$config_dir" ]]; then
if mkdir -p "$config_dir"; then
print_message success "Created $config_dir directory"
else
print_message error "Failed to create $config_dir directory"
exit 1
fi
fi
# Create symbolic link
create_symlink() {
local source_dir="$1"
local target_dir="$2"
local target_name="$3"
if [[ -d "$target_dir/$target_name" ]]; then
print_message warning "$target_name directory already exists. Removing"
rm -r "${target_dir:?}/${target_name:?}" || {
print_message error "Failed to remove $target_name directory"
return 1
}
print_message success "Successfully removed $target_name directory"
fi
print_message info "Creating symbolic link for $target_name"
ln -s "$source_dir/$target_name" "$target_dir/$target_name" || {
print_message error "Failed to create symbolic link for $target_name"
return 1
}
print_message success "Successfully created symbolic link for $target_name"
}
# Function to link config files
link_config() {
local config="$1"
echo -e "\n"
create_symlink "$dotfiles_dir/config" "$config_dir" "$config" || exit 1
}
# Function to link shell files
link_shell_file() {
local file="$1"
if [ -f "$HOME/$file" ]; then
print_message warning "File $HOME/$file exists. Removing"
rm "$HOME/$file" || {
print_message error "Failed to remove $HOME/$file"
exit 1
}
print_message success "Successfully removed $HOME/$file"
fi
ln -s "$dotfiles_dir/shell/$file" "$HOME/$file" || {
print_message error "Failed to create symbolic link for $file"
exit 1
}
print_message success "Successfully created symbolic link for $file"
}
# Available config files
configs=("bat" "ags" "cava" "hypr" "kitty" "Kvantum" "lazygit" "lazyvim" "neofetch" "nvim" "rofi" "swaync" "tmux" "waybar" "wlogout" "zsh")
# If no arguments provided, show usage
if [ $# -eq 0 ]; then
print_message error "Usage: $0 [config_name ...] [all]"
print_message info "Available configs: ${configs[*]}"
exit 1
fi
# Process arguments
for arg in "$@"; do
if [ "$arg" = "all" ]; then
for config in "${configs[@]}"; do
if [ "$config" = "zsh" ]; then
link_shell_file ".zshrc"
link_shell_file ".p10k.zsh"
else
link_config "$config"
fi
done
break
elif [[ " ${configs[*]} " == *" $arg "* ]]; then
if [ "$arg" = "zsh" ]; then
link_shell_file ".zshrc"
link_shell_file ".p10k.zsh"
else
link_config "$arg"
fi
else
print_message error "Unknown config: $arg"
exit 1
fi
done
print_message success "All requested configurations have been linked."