Skip to content

Commit

Permalink
πŸ› Add creation of target parent folder in create_symbolic_links.sh
Browse files Browse the repository at this point in the history
In the script for creating symbolic links, a line was added to create the parent directory of the target file, if it does not exist already. This is to prevent errors when trying to create a symbolic link where the target folder path does not exist yet. The folder creation step is added to both 'if' and 'elif' conditions to handle all possible cases.
  • Loading branch information
wingy3181 committed Nov 29, 2023
1 parent 07677cf commit a511d93
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/os/create_symbolic_links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ create_symlinks() {
# using regex '.*\/\(.*\)' and replacing topic folder with its contents
# For example, 'shell/bash_aliases' to 'bash_aliases'
targetFile="$HOME/.$(printf "%s" "$i" | sed "s/[^\/]*\/\(.*\)/\1/g")"

targetFolder="$(printf "%s" "$targetFile" | sed "s|/[^/]*$||")"
print_in_purple "$targetFolder β†’ $targetFile"
if [ "$(readlink "$targetFile")" == "$sourceFile" ]; then

print_success "$targetFile β†’ $sourceFile"

elif [ ! -e "$targetFile" ] || $skipQuestions; then # -e : True if file exists (regardless of type).

if [ "$targetFolder" != "$HOME" ]; then
print_success "mkdir -p \"$targetFolder\""
fi

execute_without_spinner \
"ln -fs $sourceFile $targetFile" \
"$targetFile β†’ $sourceFile"
Expand All @@ -91,6 +96,10 @@ create_symlinks() {

rm -rf "$targetFile"

# if [ "$targetFolder" != "$HOME/." ]; then
# mkdir -p "$targetFolder"
# fi

execute_without_spinner \
"ln -fs $sourceFile $targetFile" \
"$targetFile β†’ $sourceFile"
Expand Down

0 comments on commit a511d93

Please sign in to comment.