My build of nnn with minor changes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

67 lignes
2.1 KiB

  1. #!/usr/bin/env sh
  2. # Description: Create and verify checksums
  3. #
  4. # For selection: 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. # For file: 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. # For directory: recursively calculates checksum for all the files in the directory
  11. # the output checksum filename will be directory.checksum_type
  12. #
  13. # Shell: POSIX compliant
  14. # Authors: ath3, Arun Prakash Jana
  15. selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
  16. resp=f
  17. chsum=md5
  18. checksum_type()
  19. {
  20. echo "possible checksums: md5, sha1, sha224, sha256, sha384, sha512"
  21. printf "create md5 (m), sha256 (s), sha512 (S) (or type one of the above checksums) [default=m]: "
  22. read -r chsum_resp
  23. for chks in md5 sha1 sha224 sha256 sha384 sha512
  24. do
  25. if [ "$chsum_resp" = "$chks" ]; then
  26. chsum=$chsum_resp
  27. return
  28. fi
  29. done
  30. if [ "$chsum_resp" = "s" ]; then
  31. chsum=sha256
  32. elif [ "$chsum_resp" = "S" ]; then
  33. chsum=sha512
  34. fi
  35. }
  36. if [ -s "$selection" ]; then
  37. printf "work with selection (s) or current file (f) [default=f]: "
  38. read -r resp
  39. fi
  40. if [ "$resp" = "s" ]; then
  41. checksum_type
  42. sed 's|'"$PWD/"'||g' < "$selection" | xargs -0 -I{} ${chsum}sum {} > "checksum_$(date '+%Y%m%d%H%M').$chsum"
  43. elif [ -n "$1" ]; then
  44. if [ -f "$1" ]; then
  45. for chks in md5 sha1 sha224 sha256 sha384 sha512
  46. do
  47. if echo "$1" | grep -q \.${chks}$; then
  48. ${chks}sum -c < "$1"
  49. read -r _
  50. return
  51. fi
  52. done
  53. checksum_type
  54. file=$(basename "$1").$chsum
  55. ${chsum}sum "$1" > "$file"
  56. elif [ -d "$1" ]; then
  57. checksum_type
  58. file=$(basename "$1").$chsum
  59. find "$1" -type f -exec ${chsum}sum "{}" + > "$file"
  60. fi
  61. fi