My build of nnn with minor changes
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

55 lines
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. echo
  20. echo "Make sure you aren't still in the mounted device."
  21. echo -n "$prompt"
  22. read dev
  23. while ! [ -z "$dev" ]
  24. do
  25. if [ "$dev" = "l" ]; then
  26. lsblk
  27. elif [ "$dev" = "q" ]; then
  28. exit
  29. else
  30. if grep -qs "$dev " /proc/mounts; then
  31. sync
  32. pumount "$dev"
  33. if [ "$?" -eq "0" ]; then
  34. echo "$dev" unmounted.
  35. udisksctl power-off -b /dev/"$dev"
  36. if [ "$?" -eq "0" ]; then
  37. echo "$dev" ejected.
  38. fi
  39. fi
  40. else
  41. pmount "$dev"
  42. echo "$dev" mounted to "$(lsblk -n /dev/"$dev" | rev | cut -d' ' -f1 | rev)".
  43. fi
  44. fi
  45. echo
  46. echo -n "$prompt"
  47. read dev
  48. done