Merge pull request #178 from saveriomiroddi/sort_disks_on_selection

Sort disks in selection dialog
This commit is contained in:
Saverio Miroddi 2021-04-25 20:22:54 +02:00 committed by GitHub
commit 06b83382c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -342,7 +342,7 @@ function find_suitable_disks {
candidate_disk_ids=$(find /dev/disk/by-id -regextype awk -regex '.+/(ata|nvme|scsi|mmc)-.+' -not -regex '.+-part[0-9]+$' | sort)
mounted_devices="$(df | awk 'BEGIN {getline} {print $1}' | xargs -n 1 lsblk -no pkname 2> /dev/null | sort -u || true)"
while read -r disk_id || [[ -n "$disk_id" ]]; do
while read -r disk_id || [[ -n $disk_id ]]; do
local device_info
local block_device_basename
@ -370,7 +370,6 @@ function find_suitable_disks {
$(udevadm info --query=property "$(readlink -f "$disk_id")")
LOG
done < <(echo -n "$candidate_disk_ids")
if [[ ${#v_suitable_disks[@]} -eq 0 ]]; then
@ -472,11 +471,16 @@ function select_disks {
local disk_selection_status=OFF
fi
# St00pid simple way of sorting by block device name. Relies on the tokens not including whitespace.
for disk_id in "${v_suitable_disks[@]}"; do
block_device_basename="$(basename "$(readlink -f "$disk_id")")"
menu_entries_option+=("$disk_id" "($block_device_basename)" "$disk_selection_status")
menu_entries_option+=("$disk_id ($block_device_basename) $disk_selection_status")
done
# shellcheck disable=2207 # cheating here, for simplicity (alternative: add tr and mapfile).
menu_entries_option=($(printf $'%s\n' "${menu_entries_option[@]}" | sort -k 2))
local dialog_message="Select the ZFS devices.
Devices with mounted partitions, cdroms, and removable devices are not displayed!