quickfzf 0.21

This commit is contained in:
zenobit 2023-02-11 19:03:09 +01:00
parent 6b60fa91de
commit 2cff4194b0

100
quickfzf
View File

@ -4,63 +4,93 @@
# Description: Uses fzf to provide a simple GUI for quickemu and quickget # Description: Uses fzf to provide a simple GUI for quickemu and quickget
# script must be in same directory as quickget and quickemu! # script must be in same directory as quickget and quickemu!
# License MIT # License MIT
#
# Define variables
progname="${progname:="${0##*/}"}" progname="${progname:="${0##*/}"}"
version="0.2" version="0.21"
if [ ! -f /usr/bin/fzf ]; then vms=(*.conf)
echo "You are missing fzf..."
exit 255 # Set traps to catch the signals and exit gracefully
trap "exit" INT
trap "exit" EXIT
# Dependency check: check if fzf is installed and can be executed
if ! command -v fzf >/dev/null 2>&1; then
echo "You are missing fzf..." && exit 255
fi fi
echo # Dispaly version and prepared VMs
echo "Enjoy using quickemu!" #printf " $progname: $version\n quickemu: $(quickemu --version)\n\n Prepared VMs:\n-------------\n"
echo printf '%s: v.%s\nquickemu: v.%s\n\n Prepared VMs:\n-------------\n' "$progname" "$version" "$(quickemu --version)"
echo "Press ctrl + c anytime for killing script..." # Check if there are any VMs
echo if [ ${#vms[@]} -eq 0 ]; then
echo "Prepared VMs:" echo "No VMs found."
exit 1
fi
# Print the names of the available VMs
printf "%s\n" "${vms[@]%.*}"
echo "-------------" echo "-------------"
echo "$(ls *.conf 2>/dev/null | cut -d'.' -f1)"
echo "-------------" # Action prompt
echo printf " Do you want to create a new VM? (c)
read -p "Do you want to create new VM? (c) or run an existing one? (press anything)\n"
run created one? (just Enter)" start read -rn 1 -s start
case $start in case $start in
c ) c )
todo="create" todo="create"
;; ;;
esac esac
# 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) os=$(quickget | sed 1d | cut -d':' -f2 | grep -o '[^ ]*' | fzf --header='Choose OS to download
or CTRL-c or ESC to quit')
# If the OS is Windows
if [ "$os" = windows ]; then if [ "$os" = windows ]; then
answer=$(echo "Default English answer=$(echo "Default English
Choose other language" | fzf) Choose other language" | fzf)
# If the user wants another windows language
if [ "$answer" = "Choose other language" ]; then if [ "$answer" = "Choose other language" ]; then
release=$(echo "8 wrelease=$(echo "8
10 10
11" | fzf) 11" | fzf)
wlstart=$(cat quickget | grep -n '(A' | cut -d':' -f1) # get window language list
wlend=$(($(cat quickget | sed '/Arabic/,$!d' | grep -n '}' | cut -d':' -f1 | head -n 1) - 1)) wlend=$(($(cat quickget | sed '/Arabic/,$!d' | grep -n '}' | cut -d':' -f1 | head -n 1) - 1))
wlang=$(cat quickget | sed '/Arabic/,$!d' | head -n $wlend | cut -d'=' -f2 | tail -c +2 | head -c -2 | sed 's/^[ \t]*//' | fzf) # get windows language
echo wlang=$(cat quickget | sed '/Arabic/,$!d' | head -n $wlend | cut -d'=' -f2 | tail -c +2 | head -c -2 | sed 's/^[ \t]*//' | fzf --header='Choose Language
echo "Trying to download..." or CTRL-c or ESC to quit')
quickget "windows" "$release" "$wlang" # downloading windows
printf '\n Trying to download Windows %s %s...\n\n' "$wrelease" "$wlang"
quickget "windows" "$wrelease" "$wlang"
fi fi
fi fi
# Get the release and edition to download, if necessary
choices=$(quickget "$os" | sed 1d) choices=$(quickget "$os" | sed 1d)
if [ $(echo "$choices" | wc -l) = 1 ]; then if [ "$(echo "$choices" | wc -l)" = 1 ]; then
release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf) # get release
echo release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --header='Choose Release
echo "Trying to download..." or CTRL-c or ESC to quit')
# downloading
printf '\n Trying to download %s %s...\n\n' "$os" "$release"
quickget "$os" "$release" quickget "$os" "$release"
else else
release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf) # get release
edition=$(echo "$choices" | grep 'Editions' | cut -d':' -f2 | grep -o '[^ ]*' | fzf) release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --header='Choose Release
echo or CTRL-c or ESC to quit')
echo "Trying to download..." # get edition
edition=$(echo "$choices" | grep 'Editions' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --header='Choose Edition
or CTRL-c or ESC to quit')
# downloading
printf '\n Trying to download %s %s %s...\n\n' "$os" "$release" "$edition"
quickget "$os" "$release" "$edition" quickget "$os" "$release" "$edition"
fi fi
fi fi
choosed=$(echo "$(ls *.conf 2>/dev/null)" | fzf) # choose VM to run
echo choosed=$(echo "$(ls *.conf 2>/dev/null | sed 's/\.conf$//')" | fzf --header='Choose VM to run
quickemu -vm "$choosed" or CTRL-c or ESC to quit')
echo
# Run choosed VM
printf '\n Starting %s...\n\n' "$choosed"
quickemu -vm "$choosed.conf"
exit 0 exit 0