-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfzf_virtualbox.sh
executable file
·54 lines (46 loc) · 1.31 KB
/
fzf_virtualbox.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# path: /home/klassiker/.local/share/repos/fzf/fzf_virtualbox.sh
# author: klassiker [mrdotx]
# github: https://github.com/mrdotx/fzf
# date: 2024-06-20T17:17:29+0200
# speed up script and avoid language problems by using standard c
LC_ALL=C
LANG=C
# help
script=$(basename "$0")
help="$script [-h/--help] -- script to start virtualbox vm
Usage:
$script
Examples:
$script"
[ -n "$1" ] \
&& printf "%s\n" "$help" \
&& exit 0
vboxmanage list vms \
| cut -d '"' -f2 \
| {
while IFS= read -r vm; do
printf "%s [gui]\n" "$vm"
printf "%s [headless]\n" "$vm"
done
} \
| fzf -m --query="[gui] " \
--preview-window "up:75%:wrap" \
--preview "vboxmanage showvminfo {..-2}" \
| while IFS= read -r vm; do
printf "starting %s, please wait..." "$vm"
case "$vm" in
*"[headless]")
vm=$(printf "%s" "$vm" \
| sed "s/ \[headless\]$//" \
)
vboxmanage startvm "$vm" --type headless >/dev/null 2>&1
;;
*"[gui]")
vm=$(printf "%s" "$vm" \
| sed "s/ \[gui\]$//" \
)
vboxmanage startvm "$vm" --type gui >/dev/null 2>&1
;;
esac
done