From 01f239188d73ecbf40d7f14d1075ead1474d73a7 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 20 Nov 2020 15:28:19 -0600 Subject: [PATCH] [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 --- share/functions/__fish_print_zfs_snapshots.fish | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/share/functions/__fish_print_zfs_snapshots.fish b/share/functions/__fish_print_zfs_snapshots.fish index 47f331df8..384877685 100644 --- a/share/functions/__fish_print_zfs_snapshots.fish +++ b/share/functions/__fish_print_zfs_snapshots.fish @@ -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