run only one action

prepare for custom quickemu command
This commit is contained in:
zenobit 2023-09-30 06:20:02 +02:00
parent d8446ecd1a
commit be9933defb

View file

@ -27,8 +27,7 @@ QUICKGET=$(command -v quickget) || exit 255
# Display header # Display header
printf '%s: v.%s\nquickemu: v.%s\n' "$progname" "$version" "$(quickemu --version)" printf '%s: v.%s\nquickemu: v.%s\n' "$progname" "$version" "$(quickemu --version)"
if [ -z "$EDITOR" ] if [ -z "$EDITOR" ]; then
then
echo "editor: Not set! edit configs will not work!" echo "editor: Not set! edit configs will not work!"
else else
echo "editor: $EDITOR" echo "editor: $EDITOR"
@ -50,24 +49,22 @@ printf 'Press CTRL+c anytime to kill %s\n\n' "$progname"
# Action prompt # Action prompt
printf " Do you want to create a new VM? (c) printf " Do you want to create a new VM? (c)
edit VM's config file (e) edit VM's config file (e)
or run an existing one? (press anything)\n" quickemu custom command (q)
or run an existing one? (press anything else)\n"
read -rn 1 -s start read -rn 1 -s start
case $start in case $start in
c ) todo="create";; c ) todo="create";;
e ) todo="edit";; e ) todo="edit";;
q ) todo="custom";;
* ) todo="run";;
esac esac
# If the user chose to create a new VM # If the user chose to create a new VM
if [ "$todo" = "create" ]; then if [ "$todo" = "create" ]; then
os=$(quickget | sed 1d | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose OS to download') os=$(quickget | sed 1d | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose OS to download')
fi
# Get the release and edition to download, if necessary
choices=$(quickget "$os" | sed 1d) choices=$(quickget "$os" | sed 1d)
if [ "$todo" = "edit" ]; then # Get the release and edition to download, if necessary
editconfig=$(ls | grep '.conf' | fzf --cycle --header='Choose config to edit') if [ "$(echo "$choices" | wc -l)" = 1 ]; then
"$EDITOR" "$editconfig"
elif [ "$(echo "$choices" | wc -l)" = 1 ]; then
# get release # get release
release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose Release') release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose Release')
# downloading # downloading
@ -83,11 +80,23 @@ else
quickget "$os" "$release" "$edition" quickget "$os" "$release" "$edition"
fi fi
# edit VM's config'
elif [ "$todo" = "edit" ]; then
editconfig=$(ls | grep '.conf' | fzf --cycle --header='Choose config to edit')
"$EDITOR" "$editconfig"
# create quickemu custom command
elif [ "$todo" = "custom" ]; then
echo "custom"
# run VM
elif [ "$todo" = "run" ]; then
# choose VM to run # choose VM to run
chosen=$(echo "$(ls *.conf 2>/dev/null | sed 's/\.conf$//')" | fzf --cycle --header='Choose VM to run') chosen=$(echo "$(ls *.conf 2>/dev/null | sed 's/\.conf$//')" | fzf --cycle --header='Choose VM to run')
# Run chosen VM # Run chosen VM
printf '\n Starting %s...\n\n' "$chosen" printf '\n Starting %s...\n\n' "$chosen"
quickemu -vm "$chosen.conf" quickemu -vm "$chosen.conf"
fi
exit 0 exit 0