fish-shell/share/functions/__fish_print_zfs_snapshots.fish
Mahmoud Al-Qudsi 6bd4f52b0d [zfs] Optimize enumeration of snapshots
Only generate the list of snapshots when
a) the argument must be a snapshot and nothing else, or
b) the argument as typed contains a literal @, or
c) a snapshot is a valid completion and there is only one dataset
   matching the argument as entered.

Unfortunately, it seems the `zfs` command itself is extremely primitive
and doesn't support listing snapshots by dataset so when we need to
generate completions, we end up needing to enumerate all snapshots
(ever) across all datasets. I'd be very happy to be proven wrong, but I
think the only other way would be manually parse `zdb` output.

See #7472
2020-11-12 22:24:29 -06:00

16 lines
586 B
Fish

function __fish_print_zfs_snapshots -d "Lists ZFS snapshots"
set fast_results (zfs list -o name -H)
printf "%s\n" $fast_results
# 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)
if contains -- --force $argv ||
not set -q filtered_results[2] ||
string match -eq @ -- $current_token
zfs list -t snapshot -o name -H
end
end