2017-08-28 03:41:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-05-13 19:50:14 +00:00
|
|
|
# @improve this path stuff
|
|
|
|
source_helpers="$HOME/.game-libs/project-templates/_helpers"
|
|
|
|
source "$source_helpers/printing.sh"
|
|
|
|
source "$source_helpers/file_ops.sh"
|
2017-08-28 03:41:20 +00:00
|
|
|
|
|
|
|
abort() {
|
|
|
|
error "\nAborting...\n"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2019-05-13 19:50:14 +00:00
|
|
|
# If the path is not symbolic or an absolute drive path then we return it in an expanded form.
|
|
|
|
clean_path() {
|
2017-08-28 03:41:20 +00:00
|
|
|
path=$1
|
2019-05-13 19:50:14 +00:00
|
|
|
if [[ $(is_absolute_unix_path $path) -eq 0 && $(is_sym_file $path) -eq 0 ]]; then
|
|
|
|
path=$(expand_path "$path")
|
2017-08-28 03:41:20 +00:00
|
|
|
fi
|
2019-05-13 19:50:14 +00:00
|
|
|
echo $path
|
2017-08-28 03:41:20 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 19:50:14 +00:00
|
|
|
path_debug() {
|
|
|
|
path=$1
|
|
|
|
printf "\ninfo on path '$path'\n"
|
|
|
|
printf "abs unix path: $(is_absolute_unix_path $path)\n"
|
|
|
|
printf "sym file: $(is_sym_file $path)\n"
|
|
|
|
if [[ $path =~ \/+ ]]; then echo "unix path\n"; else echo "not unix path\n"; fi
|
|
|
|
expanded_path=$(expand_path "$path")
|
|
|
|
printf "expanded version: $expanded_path\n"
|
|
|
|
if [[ $(is_absolute_unix_path $path) -eq 0 && $(is_sym_file $path) -eq 0 ]]; then
|
|
|
|
printf "needs cleaning\n"
|
|
|
|
else
|
|
|
|
printf "no cleaning needed\n"
|
2017-08-28 03:41:20 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cwd=$PWD
|
|
|
|
platform=`uname` # 'Linux', 'Darwin', etc
|
2019-05-13 19:50:14 +00:00
|
|
|
source_path=""
|
|
|
|
dest_path=""
|
2017-08-28 03:41:20 +00:00
|
|
|
|
2019-05-13 19:50:14 +00:00
|
|
|
#echo "got $1 and $2"
|
|
|
|
#path_debug $1
|
|
|
|
#path_debug $2
|
|
|
|
|
|
|
|
if [[ $1 ]]; then
|
|
|
|
source_path=$1
|
|
|
|
else
|
|
|
|
printf "${BOLD}${YELLOW}Enter full path to source file/dir:\n${NORMAL}"
|
|
|
|
read -e source_path
|
2017-08-28 03:41:20 +00:00
|
|
|
fi
|
|
|
|
|
2019-05-13 19:50:14 +00:00
|
|
|
source_path=$(clean_path "$source_path")
|
|
|
|
! test -d "$source_path" && ! test -e "$source_path" && error "Source path '$source_path' doesn't exist!" && abort
|
2017-08-28 03:41:20 +00:00
|
|
|
|
2019-05-13 19:50:14 +00:00
|
|
|
if [[ $2 ]]; then
|
|
|
|
dest_path=$2
|
|
|
|
else
|
|
|
|
printf "${BOLD}${YELLOW}Enter full path to symlink destination:\n${NORMAL}"
|
|
|
|
read -e dest_path
|
2017-08-28 03:41:20 +00:00
|
|
|
fi
|
|
|
|
|
2019-05-13 19:50:14 +00:00
|
|
|
dest_path=$(clean_path $dest_path)
|
|
|
|
test -d "$dest_path" && error "Dest folder '$dest_path' already exists!" && abort
|
|
|
|
test -e "$dest_path" && error "Dest file '$dest_path' already exists!" && abort
|
|
|
|
|
|
|
|
source_path=$(windows_path $source_path)
|
|
|
|
dest_path=$(windows_path $dest_path)
|
|
|
|
|
|
|
|
cmd="cmd //c 'mklink $dest_path $source_path'"
|
2017-08-28 03:41:20 +00:00
|
|
|
|
2019-05-13 19:50:14 +00:00
|
|
|
echo "${BOLD}${BLUE}Will attempt to link ${GREEN}$source_path${BLUE} to ${GREEN}$dest_path${BLUE}"
|
2017-08-28 03:41:20 +00:00
|
|
|
printf "\n${BOLD}Enter 1 to proceed\n${YELLOW}> ${NORMAL}"
|
|
|
|
read confirm
|
|
|
|
|
|
|
|
if [[ $confirm == 1 ]]; then
|
|
|
|
eval "$cmd"
|
|
|
|
else
|
|
|
|
abort
|
|
|
|
fi
|