chore: create symlinks helpers function moved to utils folder

This commit is contained in:
hesam-init 2024-03-24 10:21:55 +03:30
parent f714c19c58
commit 0e38fd06a7
2 changed files with 38 additions and 36 deletions

37
scripts/utils/helpers.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
create_symlinks() {
local source_dir=$1
local target_dir=$2
if [ ! -d "$source_dir" ] || [ ! -d "$target_dir" ]; then
echo "Source or target directory does not exist."
return 1
fi
for item in "$source_dir"/* "$source_dir"/.*; do
[ -e "$item" ] && [ "$item" != "$source_dir/." ] && [ "$item" != "$source_dir/.." ] && ln -sfn "$item" "$target_dir/"
done
}
delete_symlinks() {
local source_dir=$1
local target_dir=$2
if [ ! -d "$source_dir" ] || [ ! -d "$target_dir" ]; then
echo "Source or target directory does not exist."
return 1
fi
for config in $source_dir/*; do
config_name=$(basename $config)
target_config=$target_dir/$config_name
if [ -e $target_config ]; then
rm -rf $target_config
echo "Removed: $target_config"
else
echo "Not found: $target_config"
fi
done
}

37
stow.sh
View file

@ -1,6 +1,7 @@
#!/bin/bash
source ./scripts/utils/main.sh
source ./scripts/utils/helpers.sh
CONFIGS_DIR="$(pwd)/configs"
DOTFILES_DIR="$CONFIGS_DIR/dotfiles"
@ -15,42 +16,6 @@ display_help() {
echo " -h Display this help message"
}
create_symlinks() {
local source_dir=$1
local target_dir=$2
if [ ! -d "$source_dir" ] || [ ! -d "$target_dir" ]; then
echo "Source or target directory does not exist."
return 1
fi
for item in "$source_dir"/* "$source_dir"/.*; do
[ -e "$item" ] && [ "$item" != "$source_dir/." ] && [ "$item" != "$source_dir/.." ] && ln -sfn "$item" "$target_dir/"
done
}
delete_symlinks() {
local source_dir=$1
local target_dir=$2
if [ ! -d "$source_dir" ] || [ ! -d "$target_dir" ]; then
echo "Source or target directory does not exist."
return 1
fi
for config in $source_dir/*; do
config_name=$(basename $config)
target_config=$target_dir/$config_name
if [ -e $target_config ]; then
rm -rf $target_config
echo "Removed: $target_config"
else
echo "Not found: $target_config"
fi
done
}
create_target_dir() {
mkdir -p ~/.local/share/applications
mkdir -p ~/.config