[zfs] Limit snapshots to spelled-out dataset

Use the `-d` parameter to `zfs list` to limit snapshots to the dataset
named in the current token being completed. Thanks to @Debilski for the
tip.

Closes #7472
This commit is contained in:
Mahmoud Al-Qudsi
2020-11-20 15:28:19 -06:00
parent be78e9dc28
commit 01f239188d

View File

@@ -5,11 +5,13 @@ function __fish_print_zfs_snapshots -d "Lists ZFS snapshots"
# Don't retrieve all snapshots for all datasets until an @ is specified,
# or if there is only one possible matching dataset. (See #7472)
set current_token (commandline --current-token)
set filtered_results (string match -e -- $current_token $fast_results)
set current_dataset (string replace -rf "([^@]+)@?.*" '$1' -- $current_token)
set filtered_results (string match -ie -- $current_dataset $fast_results)
if contains -- --force $argv ||
not set -q filtered_results[2] ||
string match -eq @ -- $current_token
string match -ieq @ -- $current_token ||
not set -q filtered_results[2]
zfs list -t snapshot -o name -H
# Ignore errors because the dataset specified could be non-existent
zfs list -t snapshot -o name -H -d 1 $current_dataset 2>/dev/null
end
end