mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 22:22:40 +00:00
103 lines
2.2 KiB
Bash
Executable File
103 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
scripts="${HOME}/.local/scripts"
|
|
uninstall=1
|
|
remove=1
|
|
copy=1
|
|
link=0
|
|
|
|
_usage() {
|
|
printf "\n" >&2
|
|
printf "Usage: setup [OPTIONS]\n" >&2
|
|
printf "\n" >&2
|
|
printf "Installs or Uninstalls zsh configuration files.\n" >&2
|
|
printf "\n" >&2
|
|
printf "Options:\n" >&2
|
|
printf "\t-c | --copy : Copy the configuration files, instead of creating symlinks.\n" >&2
|
|
printf "\t-h | --help : Print usage information.\n" >&2
|
|
printf "\t-l | --link : Create symlinks to the configuration files (Default).\n" >&2
|
|
printf "\t-r | --remove : Removes the entire ~/.config/scripts directory.\n" >&2
|
|
printf "\t-u | --uninstall : Uninstalls configuration files.\n" >&2
|
|
printf "\n" >&2
|
|
printf "If called without the uninstall option then it will install the configuration files.\n" >&2
|
|
printf "The copy and link options are ignored if called with the uninstall or remove option.\n" >&2
|
|
printf "\n" >&2
|
|
}
|
|
|
|
_parse_options() {
|
|
arg=
|
|
while ! test -z "$1"; do
|
|
arg="$1"
|
|
case $arg in
|
|
-c | --copy)
|
|
copy=0
|
|
link=1
|
|
shift;;
|
|
-h | --help)
|
|
_usage
|
|
exit;;
|
|
-l | --link)
|
|
copy=1
|
|
link=0
|
|
shift;;
|
|
-r | --remove)
|
|
remove=0
|
|
shift;;
|
|
-u | --uninstall)
|
|
uninstall=0
|
|
shift;;
|
|
*)
|
|
echo "Unknown option $arg" >&2
|
|
shift;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
|
|
_make_dirs() {
|
|
if ! test -d "${HOME}/.local"; then
|
|
mkdir "${HOME}/.local"
|
|
fi
|
|
if ! test -d "${HOME}/.local/bin"; then
|
|
mkdir "${HOME}/.local/bin"
|
|
fi
|
|
}
|
|
|
|
_remove_scripts() {
|
|
echo "Removing scripts..."
|
|
test -e "${scripts}" && rm "${scripts}"
|
|
}
|
|
|
|
_link_scripts() {
|
|
echo "Linking scripts..."
|
|
ln -sfv "${PWD}/scripts" "${scripts}"
|
|
}
|
|
|
|
_copy_scripts() {
|
|
echo "Copying scripts..."
|
|
cp -r "${PWD}/scripts" "${scripts}"
|
|
}
|
|
|
|
_install() {
|
|
|
|
_make_dirs
|
|
|
|
test "$copy" -eq 0 && _copy_scripts && return "$?"
|
|
test "$link" -eq 0 && _link_scripts && return "$?"
|
|
|
|
echo "Neither link nor copy was passed, see --help for usage"
|
|
exit 1
|
|
}
|
|
|
|
#--------------- main ---------------
|
|
main() {
|
|
_parse_options "$@"
|
|
test "$remove" -eq 0 && _remove_scripts && exit "$?"
|
|
test "$uninstall" -eq 0 && _remove_scripts && exit "$?"
|
|
_install && exit "$?"
|
|
}
|
|
|
|
main "$@"
|