Update zrep script to handle cases where installed.json is empty or contains no packages. Add checks to handle empty JSON objects or arrays.
This commit is contained in:
		
							
								
								
									
										12
									
								
								zrep
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								zrep
									
									
									
									
									
								
							@@ -299,9 +299,21 @@ end' "$installed_json" > "$installed_json.tmp" && mv "$installed_json.tmp" "$ins
 | 
			
		||||
function zrep_list_installed_packages() {
 | 
			
		||||
    zrep_installed_json
 | 
			
		||||
 | 
			
		||||
    # Check if installed.json exists and is not empty
 | 
			
		||||
    if [[ ! -s "${installed_json}" ]]; then
 | 
			
		||||
        zrep_msg info "No packages installed."
 | 
			
		||||
        return
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    # Parse installed.json and list packages
 | 
			
		||||
    zrep_msg sub "\nInstalled packages:"
 | 
			
		||||
 | 
			
		||||
    # Check if the JSON file is effectively empty ({} or [])
 | 
			
		||||
    if jq -e 'if type == "object" then . == {} elif type == "array" then . == [] else false end' "${installed_json}" >/dev/null; then
 | 
			
		||||
        zrep_msg info "No packages installed."
 | 
			
		||||
        return
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    # Iterate through each author and their packages
 | 
			
		||||
    jq -r 'to_entries | .[] | .key as $author | .value[] | "\($author)/\(.script) (\(.version))"' "${installed_json}" | while IFS= read -r package_info; do
 | 
			
		||||
        local package_name=$(echo "${package_info}" | cut -d ' ' -f1)  # Extract package name before the version
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user