-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinuxsetup.sh
More file actions
executable file
·62 lines (52 loc) · 2.06 KB
/
linuxsetup.sh
File metadata and controls
executable file
·62 lines (52 loc) · 2.06 KB
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
#!/usr/bin/env bash
# Define the root directory where your configuration files are stored.
# By default, it is set to $HOME/.config/linuxsetup
SETUP_DIR="$HOME/.config/linuxsetup"
echo -e "\nStarting configuration!\n"
# Function to create a symbolic link
create_symlink() {
local SOURCE="$1" # The source file or directory (from SETUP_DIR)
local TARGET="$2" # The target file or directory (where the link will be created)
local TARGET_DIR
TARGET_DIR=$(dirname "$TARGET")
if [ ! -d "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
echo -e "Created parent directory: $TARGET_DIR"
fi
# Check if the symbolic link already exists at the target location
if [ -L "$TARGET" ]; then
echo -e "The symbolic link already exists: $TARGET"
else
# If the symbolic link doesn't exist, check if the source file/directory exists
if [ -e "$SOURCE" ]; then
# If the source exists, create the symbolic link
ln -s "$SOURCE" "$TARGET"
echo -e "Symbolic link created: $TARGET -> $SOURCE"
else
# If the source file/directory doesn't exist, print an error message
echo -e "The source file or directory does not exist: $SOURCE"
fi
fi
}
# Define the configuration files and directories you want to set up
# The keys are the source files/directories, and the values are the target locations for the symbolic links
declare -A links=(
["$SETUP_DIR/alacritty"]="$HOME/.config/alacritty"
["$SETUP_DIR/tmux.conf"]="$HOME/.tmux.conf"
["$SETUP_DIR/zshrc"]="$HOME/.zshrc"
# Add more files or directories as needed, following the same pattern
)
# Loop through the links and create the symbolic links for each configuration file
for SOURCE in "${!links[@]}"; do
TARGET="${links[$SOURCE]}" # The target location for the symbolic link
create_symlink "$SOURCE" "$TARGET" # Call the function to create the link
done
# New line
echo ""
# If it's the tmux configuration, reload tmux config immediately
if pgrep -x "tmux" >/dev/null; then
# If tmux is running, reload the tmux configuration
tmux source-file ~/.tmux.conf
echo -e "Tmux configuration reloaded.\n"
fi
echo -e "Setup complete!\n"