mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-30 06:03:49 +08:00
6bd4f52b0d
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
16 lines
586 B
Fish
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
|