Created
October 28, 2025 20:20
-
-
Save baldwindavid/c36639349f1c150a0a506b9ea4974fef to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| # Reruns the last command executed via run.sh in the current directory | |
| # Shows an error message if no previous command exists | |
| set -e | |
| # Find the cached command for this directory | |
| CACHE_DIR="/tmp/helix_last_command_$USER" | |
| # Use same hash logic as run.sh (portable across macOS and Linux) | |
| if command -v md5sum &> /dev/null; then | |
| PWD_HASH=$(echo -n "$PWD" | md5sum | cut -d' ' -f1) | |
| elif command -v md5 &> /dev/null; then | |
| PWD_HASH=$(echo -n "$PWD" | md5) | |
| else | |
| # Fallback: use base64-encoded path (less elegant but works everywhere) | |
| PWD_HASH=$(echo -n "$PWD" | base64 | tr -d '=\n' | tr '/' '_') | |
| fi | |
| CACHE_FILE="$CACHE_DIR/$PWD_HASH" | |
| # Check if cache file exists | |
| if [ ! -f "$CACHE_FILE" ]; then | |
| echo "No previous command to rerun in this directory" >&2 | |
| exit 1 | |
| fi | |
| # Source the cache file to get PWD and ARGS as an array | |
| source "$CACHE_FILE" | |
| # Change to the cached directory and re-execute run.sh | |
| cd "$PWD" | |
| # Re-execute run.sh with the cached arguments (ARGS is now an array) | |
| exec "$(dirname "$0")/run.sh" "${ARGS[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment