Skip to content

Commit

Permalink
[bash] return all restorable snapshots on multipass restore tab compl…
Browse files Browse the repository at this point in the history
…etion
  • Loading branch information
sharder996 committed Oct 17, 2023
1 parent 20da5bb commit 21f81cd
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions completions/bash/multipass
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ _multipass_complete()

_multipass_snapshots()
{
local instance="${cur%%.*}"
local cmd="multipass list --snapshots --format=csv 2>/dev/null | \tail -n +2 | \awk -F',' '\$1 == \"$1\"'"
local snapshots=$( \eval $cmd | \cut -d',' -f 1,2 | \tr ',' '.' | \tr '\r\n' ' ' )

Expand All @@ -38,21 +37,23 @@ _multipass_complete()
_multipass_instances_and_snapshots()
{
if [[ "${cur}" =~ '.' ]]; then
_multipass_snapshots
_multipass_snapshots "${cur%%.*}"
fi

_multipass_instances
}

_multipass_restorable_instances()
_multipass_restorable_snapshots()
{
local instances=$( multipass info --all --no-runtime-information --format=csv \
| \tail -n +2 \
| \awk -F',|\r?\n' '$2 == "Stopped" && $16 > 0' \
| \cut -d',' -f 1 \
| \tr '\r\n' ' ')

_add_nonrepeating_args "$instances"
for instance in ${instances}; do
_multipass_snapshots "${instance}"
done
}

# Set $opts to the list of available networks.
Expand Down Expand Up @@ -353,11 +354,7 @@ _multipass_complete()
_multipass_instances "Stopped"
;;
"restore")
if [[ "${cur}" =~ '.' ]]; then
_multipass_snapshots
else
_multipass_restorable_instances
fi
_multipass_restorable_snapshots
;;
"mount")
local source_set=0
Expand Down

0 comments on commit 21f81cd

Please sign in to comment.