cdtemp 427 B

123456789101112131415161718192021
  1. #!/usr/bin/env bash
  2. TEMPSPACE=$HOME/Workspace/temp
  3. set -euo pipefail
  4. cmd="${1:-}"
  5. if [ "$cmd" = "last" ]; then
  6. dir=$(find "$TEMPSPACE" -type d -mindepth 1 -maxdepth 1 | sort | tail -n 1)
  7. cd "$dir"
  8. elif [ "$cmd" = "prune" ]; then
  9. echo "Deleting empty directories"
  10. find "$TEMPSPACE" -mindepth 1 -maxdepth 1 -type d -empty -delete -print
  11. exit
  12. else
  13. dir="$TEMPSPACE/$(date +%s)"
  14. mkdir "$dir"
  15. cd "$dir"
  16. fi
  17. $SHELL