mirror of
				https://github.com/oSoWoSo/DistroHopper.git
				synced 2024-08-14 22:46:53 +00:00 
			
		
		
		
	Create quickfzf
This commit is contained in:
		
							parent
							
								
									5c5048aa26
								
							
						
					
					
						commit
						302d4df44b
					
				
					 1 changed files with 102 additions and 0 deletions
				
			
		
							
								
								
									
										102
									
								
								quickfzf
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								quickfzf
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,102 @@ | ||||||
|  | #!/usr/bin/bash | ||||||
|  | 
 | ||||||
|  | # Author: zenobit | ||||||
|  | # Description: Uses fzf to provide a simple TUI for quickemu and quickget | ||||||
|  | # License MIT | ||||||
|  | 
 | ||||||
|  | # Define variables | ||||||
|  | progname="${progname:="${0##*/}"}" | ||||||
|  | version="0.22" | ||||||
|  | vms=(*.conf) | ||||||
|  | 
 | ||||||
|  | # 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 | ||||||
|  | 
 | ||||||
|  | if ! command -v quickemu >/dev/null 2>&1; then | ||||||
|  | 	echo "You are missing quickemu..." && exit 255 | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | QUICKGET=$(command -v quickget)   || exit 255 | ||||||
|  | 
 | ||||||
|  | # Display version and prepared VMs | ||||||
|  | #printf " $progname: $version\n quickemu: $(quickemu --version)\n\n Prepared VMs:\n-------------\n" | ||||||
|  | printf '%s: v.%s\nquickemu: v.%s\n\n Workdir: %s\n\n Prepared VMs:\n-------------\n' "$progname" "$version" "$(quickemu --version)" "$(pwd)" | ||||||
|  | # Check if there are any VMs | ||||||
|  | if [ ${#vms[@]} -eq 0 ]; then | ||||||
|  |     echo "No VMs found." | ||||||
|  |     exit 1 | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | # Print the names of the available VMs | ||||||
|  | printf "%s\n" "${vms[@]%.*}" | ||||||
|  | echo "-------------" | ||||||
|  | 
 | ||||||
|  | # Action prompt | ||||||
|  | printf " Do you want to create a new VM? (c) | ||||||
|  |  or run an existing one? (press anything)\n" | ||||||
|  | read -rn 1 -s start | ||||||
|  | case $start in | ||||||
|  | 	c ) | ||||||
|  | 		todo="create" | ||||||
|  | 	;; | ||||||
|  | esac | ||||||
|  | 
 | ||||||
|  | # If the user chose to create a new VM | ||||||
|  | if [ "$todo" = "create" ]; then | ||||||
|  | 	os=$(quickget | sed 1d | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose OS to download | ||||||
|  |  or CTRL-c or ESC to quit') | ||||||
|  | 	# If the OS is Windows | ||||||
|  | 	if [ "$os" = windows ]; then | ||||||
|  | 		answer=$(echo "Default English | ||||||
|  | Choose other language" | fzf --cycle) | ||||||
|  | 		# If the user wants another windows language | ||||||
|  | 		if [ "$answer" = "Choose other language" ]; then | ||||||
|  | 			wrelease=$(echo "8 | ||||||
|  | 10 | ||||||
|  | 11" | fzf --cycle) | ||||||
|  | 			# get window language list | ||||||
|  | 			wlend=$(($(cat $QUICKGET  | sed '/Arabic/,$!d' | grep -n '}' | cut -d':' -f1 | head -n 1) - 1)) | ||||||
|  | 			# get windows language | ||||||
|  | 			wlang=$(cat $QUICKGET | sed '/Arabic/,$!d' | head -n $wlend | cut -d'=' -f2 | tail -c +2 | head -c -2 | sed 's/^[ \t]*//' | fzf --cycle --header='Choose Language | ||||||
|  |  or CTRL-c or ESC to quit') | ||||||
|  | 			# downloading windows | ||||||
|  | 			printf '\n Trying to download Windows %s %s...\n\n' "$wrelease" "$wlang" | ||||||
|  | 			quickget "windows" "$wrelease" "$wlang" | ||||||
|  | 		fi | ||||||
|  | 	fi | ||||||
|  | 	# Get the release and edition to download, if necessary | ||||||
|  | 	choices=$(quickget "$os" | sed 1d) | ||||||
|  | 	if [ "$(echo "$choices" | wc -l)" = 1 ]; then | ||||||
|  | 		# get release | ||||||
|  | 		release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose Release | ||||||
|  |  or CTRL-c or ESC to quit') | ||||||
|  | 		# downloading | ||||||
|  | 		printf '\n Trying to download %s %s...\n\n' "$os" "$release" | ||||||
|  | 		quickget "$os" "$release" | ||||||
|  | 	else | ||||||
|  | 		# get release | ||||||
|  | 		release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose Release | ||||||
|  |  or CTRL-c or ESC to quit') | ||||||
|  | 		# get edition | ||||||
|  | 		edition=$(echo "$choices" | grep 'Editions' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --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" | ||||||
|  | 	fi | ||||||
|  | fi | ||||||
|  | # choose VM to run | ||||||
|  | chosen=$(echo "$(ls *.conf 2>/dev/null | sed 's/\.conf$//')" | fzf --cycle --header='Choose VM to run | ||||||
|  |  or CTRL-c or ESC to quit') | ||||||
|  | 
 | ||||||
|  | # Run chosen VM | ||||||
|  | printf '\n Starting %s...\n\n' "$chosen" | ||||||
|  | quickemu -vm "$chosen.conf" | ||||||
|  | 
 | ||||||
|  | exit 0 | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue