refactor: Simplify setup script

This commit is contained in:
Ahmad Ansori Palembani 2024-05-18 14:00:46 +07:00
parent 8d2166bfda
commit 4b2fbee244
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
3 changed files with 28 additions and 26 deletions

View file

@ -1,25 +0,0 @@
#!/bin/zsh
printf "Experimental script! Run it anyway? (y/N) "
read choice
[ "$choice" = "y" ] || exit 1
[ ! $1 ] && >&2 echo "Usage: setup-dotfiles [PATH]" && exit 1
cd $1 || { >&2 echo "Invalid path" && exit 1 }
git status 2>/dev/null || { >&2 echo "Directory is not a git directory!" && exit 1 }
cat << EOF
#!/bin/zsh
export DOTFILES="${PWD}"
[ ! \$DOTFILES ] && unset DOTFILES
EOF
echo ""
echo "##############################################################"
echo "# Please replace ~/.config/zsh/dotfiles with the code above. #"
echo "# TIPS: Run 'setup-dotfiles > ~/.config/zsh/dotfiles' #"
echo "##############################################################"

View file

@ -1,3 +1,4 @@
<!-- ZI-DOTFILES -->
<p align="center"> <p align="center">
<a href="https://github.com/null2264/dotfiles"><img width="25%" src="https://github.com/null2264.png"></img></a> <a href="https://github.com/null2264/dotfiles"><img width="25%" src="https://github.com/null2264.png"></img></a>
</p> </p>
@ -30,7 +31,7 @@ My Setup:
> [!WARNING] > [!WARNING]
> This section is still WIP! > This section is still WIP!
First time setup only: run `setup-dotfiles <dotfiles path> > ~/.config/zsh/dotfiles`, e.g. `setup-dotfiles ~/Build/GIT/dotfiles > ~/.config/zsh/dotfiles`. First time setup only: run `./setup-dotfiles` then follow the instruction.
## Recommended Project/Software ## Recommended Project/Software
- TBSM - TBSM

26
setup-dotfiles Executable file
View file

@ -0,0 +1,26 @@
#!/bin/zsh
printf "Experimental script! Run it anyway? (y/N) "
read choice
[ "$choice" = "y" ] || exit 1
[ "$(cat README.md | head -n 1)" = "<!-- ZI-DOTFILES -->" ] || {
>&2 echo "Current working directory is not the dotfiles is located!";
>&2 echo "Please 'cd' to the dotfiles directory before running the script.";
exit 1;
}
info="""
########################################################################
# Please replace '~/.config/zsh/include/dotfiles' with the code above. #
########################################################################
"""
echo "#!/bin/zsh"
echo $info
echo """export ZI_DOTFILES="${PWD}"
[ ! \$ZI_DOTFILES ] && unset ZI_DOTFILES"""
echo $info