diff --git a/scripts/dev.sh b/scripts/dev.sh index 3248b16..38e6bf2 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -1,5 +1,10 @@ #!/bin/bash +# Set the script directory and project root directory +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$script_dir" || exit 1 +project_root=$(git rev-parse --show-toplevel) + # Function to install packwiz and add it to the system path install_packwiz() { # Download packwiz executable @@ -12,36 +17,36 @@ install_packwiz() { # Add packwiz to the system path if [[ ! ":$PATH:" == *":/usr/local/bin:"* ]]; then - echo 'export PATH="$PATH:/usr/local/bin"' >> ~/.bashrc + echo "export PATH='$PATH:/usr/local/bin'" >> ~/.bashrc fi # Generate autocompletion script packwiz completion bash > ~/.packwiz - if ! grep -q "source ~/.packwiz" ~/.bashrc; then + if ! grep -q "source ~/.packwiz" ~/.bashrc; then echo 'source ~/.packwiz' >> ~/.bashrc - echo "Successfully enabled packwiz autocompletion"; + echo "Successfully enabled packwiz autocompletion"; else - echo "packwiz autocompletion already enabled" + echo "packwiz autocompletion already enabled" fi + source ~/.bashrc } # Function to create symlink for pre-commit hook create_symlink() { # Check if .git/hooks directory exists - if [ ! -d ".git/hooks" ]; then - echo "Error: .git/hooks directory does not exist" - exit 1 + if [ ! -d "$project_root/.git/hooks" ]; then + mkdir -p "$project_root/.git/hooks" fi # Delete old symlink - rm -f "$(pwd)/.git/hooks/post-commit" + rm -f "$project_root/.git/hooks/post-commit" - # Create symlink for pre-commit hook - ln -s "$(pwd)/scripts/hooks/post-commit" "$(pwd)/.git/hooks/post-commit" + # Create symlink for post-commit hook + ln -s "$project_root/scripts/hooks/post-commit" "$project_root/.git/hooks/post-commit" # Verify symlink creation - ls -l .git/hooks/post-commit + ls -l "$project_root/.git/hooks/post-commit" } # Main function