Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
523 B

  1. #!/bin/sh
  2. set -e
  3. if [ -z "$1" ]; then
  4. # default to current working directory:
  5. dir="."
  6. else
  7. dir="$1"
  8. fi
  9. # if we got a directory as first param, cd there first:
  10. if [ -e "$dir" ]; then
  11. if [ -d "$dir" ]; then
  12. cd "$dir"
  13. else
  14. echo "Not a directory: $dir"
  15. exit 1
  16. fi
  17. else
  18. echo "No such path: $dir"
  19. exit 1
  20. fi
  21. # probably GNU-dependent
  22. # list (A)lmost all files in
  23. # current dir, sorted by (t)ime,
  24. # and return the first (newest):
  25. basename=$(ls -At | head -1)
  26. # get full path:
  27. readlink -f "$basename"