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

54 строки
1.4 KiB

  1. #!/usr/bin/env sh
  2. # Description: Toggle mount status of a device using pmount
  3. # If the device is not mounted, it will be mounted.
  4. # If the device is mounted, it will be unmounted and powered down.
  5. #
  6. # Runs `lsblk` if 'l' is entered, exits on 'Return`.
  7. #
  8. # Note:
  9. # - The script uses Linux-specific lsblk to list block devices. Alternatives:
  10. # macOS: "diskutil list"
  11. # BSD: "geom disk list"
  12. # - The script uses udisksctl (from udisks2) to pwoer down devices. This is also Linux-specific.
  13. # Users on non-Linux platforms can comment it and use an alterntive to power-down disks.
  14. #
  15. # Shell: POSIX compliant
  16. # Author: Arun Prakash Jana
  17. prompt="device name ['l' lists]: "
  18. lsblk
  19. printf "\nEnsure you aren't still in the mounted device.\n"
  20. printf "%s" "$prompt"
  21. read -r dev
  22. while ! [ -z "$dev" ]
  23. do
  24. if [ "$dev" = "l" ]; then
  25. lsblk
  26. elif [ "$dev" = "q" ]; then
  27. exit
  28. else
  29. if grep -qs "$dev " /proc/mounts; then
  30. sync
  31. if pumount "$dev"
  32. then
  33. echo "$dev" unmounted.
  34. if udisksctl power-off -b /dev/"$dev"
  35. then
  36. echo "$dev" ejected.
  37. fi
  38. fi
  39. else
  40. pmount "$dev"
  41. echo "$dev" mounted to "$(lsblk -n /dev/"$dev" | rev | cut -d' ' -f1 | rev)".
  42. fi
  43. fi
  44. echo
  45. printf "%s" "$prompt"
  46. read -r dev
  47. done