-
Notifications
You must be signed in to change notification settings - Fork 1
/
configs.sh
executable file
·84 lines (61 loc) · 2.02 KB
/
configs.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
#!/usr/bin/env bash
set -euo pipefail
if [ -z "$1" ];then
echo "Usage: $(basename "${BASH_SOURCE[0]}") <BASEDIR>"
exit 1
fi
BASEDIR=$1
CONFIGS="$BASEDIR/configs"
# $1 = source_file, $2 = target_file
create_symlink() {
local source_file=$1
local target_file=$2
if [[ ${DEBUG-} != "true" ]]; then
ln -sfn "$source_file" "$target_file"
else
echo "$source_file -> $target_file"
fi
}
# $1 = relative_source_file, $2 = target_directory
symlink_file() {
file=$1
target_directory=$2
mkdir -p "$target_directory"
echo -e "\e[1;34m[i] Creating symlinks for '$file' in '$target_directory'\e[0m"
filename=$(basename "$file")
source_file="$file"
target_file="$target_directory/$filename"
create_symlink "$source_file" "$target_file"
}
# $1 = source_directory, $2 = target_directory
symlink_dir_files() {
local directory=$1
local target_directory=$2
mkdir -p "$target_directory"
echo -e "\e[1;34m[i] Creating symlinks for '$directory' in '$target_directory'\e[0m"
readarray -t DIR_FILES < <(find "$directory" -maxdepth 1 -type f)
for file in "${DIR_FILES[@]}"; do
filename=$(basename "$file")
source_file=$file
target_file="$target_directory/$filename"
create_symlink "$source_file" "$target_file"
done
}
# $1 = source_directory, $2 = target_directory
symlink_dir() {
local directory=$1
local target_directory=$2
dir_name=$(basename "$directory")
target_dir="$target_directory/$dir_name"
symlink_dir_files "$directory" "$target_dir"
}
symlink_dir_files "$CONFIGS/bash" "$HOME"
symlink_dir_files "$CONFIGS/zsh" "$HOME"
symlink_dir_files "$CONFIGS/shell" "$HOME"
symlink_file "$CONFIGS/.gitconfig" "$HOME"
symlink_file "$CONFIGS/.vimrc" "$HOME"
symlink_file "$CONFIGS/starship.toml" "$HOME/.config"
symlink_dir "$CONFIGS/wezterm" "$HOME/.config"
symlink_dir "$CONFIGS/atuin" "$HOME/.config"
symlink_file "$CONFIGS/mpv.conf" "$HOME/.config/mpv"
echo -e "\e[1;32m[✓] Symlinks created succesfully.\e[0m"