Added zsh functions for managing zrep packages. Fixed bugs in zrep functions. Updated zrep version to 0.0.7.

This commit is contained in:
Stig-Ørjan Smelror 2024-04-05 21:43:51 +02:00
parent ae6becb2cc
commit aee45ba2ee
2 changed files with 20 additions and 47 deletions

34
t
View File

@ -1,34 +0,0 @@
#!/usr/bin/zsh
function zrep_fpath_2() {
local base_dir="${1}"
# Ensure globbing finds dotfiles and nullglob avoids empty directory issues
setopt local_options dotglob nullglob
# Check if the base directory exists
if [[ ! -d "${base_dir}" ]]; then
echo "Error: Base directory '${base_dir}' does not exist."
return 1
fi
# Iterate over directories within $base_dir with exactly one character
for one_char_dir in ${base_dir}/?; do
# Check if it's indeed a directory
[[ -d "${one_char_dir}" ]] || continue
# Recursively find all final directories under one_char_dir with the pattern first_letter/author/script
for script_dir in ${one_char_dir}/*/*(/); do
local script_name=$(basename "${script_dir}")
local matching_files=("${script_dir}/${script_name}")
# Check if there's at least one file matching the script directory's name
if (( ${#matching_files} )); then
echo "${script_dir}"
fi
done
done
}
zrep_fpath_2 /home/stig/.zrep

View File

@ -2,7 +2,7 @@
setopt extendedglob setopt extendedglob
VERSION="0.0.7" # Fri-2024-04-05 VERSION="0.0.8" # Fri-2024-04-05
ZREP="Zsh Repository Tool" ZREP="Zsh Repository Tool"
# Define the default path to .zreprc # Define the default path to .zreprc
ZREP_CONFIG="${HOME}/.zreprc" ZREP_CONFIG="${HOME}/.zreprc"
@ -540,6 +540,17 @@ function zrep_global_downloader() {
eval ${dloader} "${1}" eval ${dloader} "${1}"
} }
function zrep_process_updates() {
for package in ${(k)updatesAvailable}; do
local updateDetails=(${(s/|/)updatesAvailable[${package}]})
local author=${updateDetails[1]}
local script=${updateDetails[2]}
local version=${updateDetails[3]}
echo "Updating ${author}/${script} to version ${version}..."
zrep_install_package u "${author}/${script}" "${version}"
done
}
typeset -A updatesAvailable typeset -A updatesAvailable
function zrep_check_for_updates() { function zrep_check_for_updates() {
@ -567,7 +578,9 @@ function zrep_check_for_updates() {
'.authors[] | select(.name==$author) | .scripts[] | select(.name==$script) | .version' <<<"$remotePackages") '.authors[] | select(.name==$author) | .scripts[] | select(.name==$script) | .version' <<<"$remotePackages")
if [[ "${remote_version}" > "${installed_version}" ]]; then if [[ "${remote_version}" > "${installed_version}" ]]; then
updatesAvailable[${author}/${script}]="${remote_version}" # updatesAvailable[${author}/${script}]="${remote_version}"
# Store author, script, and version in a single string, separated by "|"
updatesAvailable[${author}/${script}]="${author}|${script}|${remote_version}"
zrep_msg info "\n${author}/${script} can be updated from ${installed_version} to ${remote_version}" zrep_msg info "\n${author}/${script} can be updated from ${installed_version} to ${remote_version}"
updates=true # Mark that updates are available updates=true # Mark that updates are available
fi fi
@ -598,8 +611,8 @@ function zrep_update_package() {
else else
if [[ ${updates} == "true" ]]; then if [[ ${updates} == "true" ]]; then
# Prompt the user only if updates are available # Prompt the user only if updates are available
echo "New updates are available. Do you want to proceed with updating? (Y/n): " zrep_msg sub "New updates are available. Do you want to proceed with updating? (Y/n): \c"
read -q "response?" read "response"
echo # Move to a new line echo # Move to a new line
# Set the default response to 'Y' if no input is entered # Set the default response to 'Y' if no input is entered
@ -607,14 +620,8 @@ function zrep_update_package() {
# Proceed with update if the response is 'Y' or 'y' # Proceed with update if the response is 'Y' or 'y'
if [[ $response =~ ^[Yy]$ ]]; then if [[ $response =~ ^[Yy]$ ]]; then
# General update mode: update all packages listed in updatesAvailable # Call zrep_process_updates to handle all updates.
for package in ${(k)updatesAvailable}; do zrep_process_updates
local author=${package%%/*}
local script=${package#*/}
local version=${updatesAvailable[${package}]}
local install_pkg="${author}/${script}"
zrep_install_package u ${install_pkg}
done
else else
zrep_msg info "Update canceled." zrep_msg info "Update canceled."
fi fi
@ -715,7 +722,7 @@ function zrep_install_package() {
# If not installed, proceed with fetching the package information # If not installed, proceed with fetching the package information
# Using the new zrep API to get the package version # Using the new zrep API to get the package version
zrep_parse_remote "${config[global_repo_url]}/getver.php\?p\=${package}" ${package} # zrep_parse_remote "${config[global_repo_url]}/getver.php\?p\=${package}" ${package}
local tmpDir="${config[main_zrep_install_dir]}/tmp" local tmpDir="${config[main_zrep_install_dir]}/tmp"