My build of nnn with minor changes
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

61 рядки
1.8 KiB

  1. #!/usr/bin/env sh
  2. # Description: Create and verify checksums
  3. #
  4. # If selection is used: it will generate one file containing the checksums with file names
  5. # [and with paths if they are in another directory]
  6. # The output checksum filename will be checksum_timestamp.checksum_type
  7. # If file is used: if the file is a checksum, the plugin does the verification
  8. # if the file is not a checksum, checksum will be generated for it
  9. # The output checksum filename will be filename.checksum_type
  10. #
  11. # Shell: POSIX compliant
  12. # Author: ath3
  13. selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
  14. resp=f
  15. chsum=md5
  16. checksum_type()
  17. {
  18. echo "possible checksums: md5, sha1, sha224, sha256, sha384, sha512"
  19. echo -n "create md5 (m), sha256 (s), sha512 (S) (or type one of the above checksums) [default=m]: "
  20. read chsum_resp
  21. for chks in md5 sha1 sha224 sha256 sha384 sha512
  22. do
  23. if [ "$chsum_resp" = "$chks" ]; then
  24. chsum=$chsum_resp
  25. return
  26. fi
  27. done
  28. if [ "$chsum_resp" = "s" ]; then
  29. chsum=sha256
  30. elif [ "$chsum_resp" = "S" ]; then
  31. chsum=sha512
  32. fi
  33. }
  34. if [ -s "$selection" ]; then
  35. echo -n "work with selection (s) or current file (f) [default=f]: "
  36. read resp
  37. fi
  38. if [ "$resp" = "s" ]; then
  39. checksum_type
  40. sed 's|'"$PWD/"'||g' < "$selection" | xargs -0 -I{} ${chsum}sum {} > "checksum_$(date '+%Y%m%d%H%M').$chsum"
  41. else
  42. if [ -n "$1" ] && [ -f "$1" ]; then
  43. for chks in md5 sha1 sha224 sha256 sha384 sha512
  44. do
  45. if [ "$(echo "$1" | grep \.${chks}$)" ]; then
  46. ${chks}sum -c < "$1"
  47. read dummy
  48. exit
  49. fi
  50. done
  51. checksum_type
  52. file=$(basename "$1").$chsum
  53. ${chsum}sum "$1" > "$file"
  54. fi
  55. fi