Last active
May 27, 2025 21:44
-
-
Save tnn4/4a4dc0029fb2e0905e4c21b132a802f4 to your computer and use it in GitHub Desktop.
remove or make symlink script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# see: https://stackoverflow.com/questions/1494178/how-to-define-hash-tables-in-bash | |
# Create symlinks | |
# ln -s /path/to/file /path/to/symlink # path >> linkname | |
# remove symlinks | |
# ln -sf /path/to/file /path/to/symlink | |
declare -A symlink_list | |
# Add list of links here | |
love2d="/home/t/bin/love-11.5-x86_64.AppImage" | |
neovim="/home/t/bin/nvim-linux-x86_64.appimage" | |
symlink_list=( ["love"]=${love2d} ["nvim"]=${neovim} ) | |
# | |
# remove symlinks | |
rm_symlinks() { | |
for item in "${!symlink_list[@]}";do | |
ln -sf ${symlink_list[${link}]} ${link} | |
echo "Removinb symlink ${symlink_list[${link}]} >> ${link}" | |
done | |
} | |
# add symlinks | |
mk_symlinks() { | |
for link in "${!symlink_list[@]}";do | |
ln -s ${symlink_list[${link}]} ${link} | |
echo "Creating symlink ${link} >> ${symlink_list[${link}]}" | |
done | |
} | |
# main | |
main() { | |
## remove symlinks if --reset | |
if [ "${1}" == "--reset" ] || [ "${1}" == "--rm" ]; then | |
echo 'removing symlinks' | |
rm_symlinks | |
else | |
echo 'Creating symlinks' | |
mk_symlinks | |
fi | |
} | |
main ${@} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment