Stop overriding echo, just use printf instead.

This commit is contained in:
Jack L. Frost 2015-02-20 17:50:31 +03:00
parent 4351aa9450
commit 1c136aab43

33
zpac
View File

@ -9,8 +9,7 @@ cfg_workdir="$PWD"
cfg_aur_url='https://aur.archlinux.org'
cfg_aur_api="${cfg_aur_url}/rpc.php"
echo() { printf '%s\n' "$*"; }
err() { echo "$*" >&2; }
err() { printf "$@" >&2; }
_cat() { while read -r; do printf '%s\n' "$REPLY"; done }
@ -29,7 +28,7 @@ usage() {
}
aur.search() {
declare aur_api_search_data aur_search_result_num aur_search_results version description
declare i aur_api_search_data aur_search_result_num aur_search_results version description
aur_api_search_data=$( curl -skL "${cfg_aur_api}?type=search&arg=${1}" )
aur_search_result_num=$( jshon -e resultcount -u <<< "$aur_api_search_data" )
@ -59,11 +58,11 @@ aur.info() {
(( aur_query_result )) || { return 1; }
echo "$pkg_aur_info"
printf '%s' "$pkg_aur_info"
}
aur.get() {
declare pkg_aur_info pkg_base tarball_path depends makedepends dep_name aur_api_multireq dep_name aur_deps_api_data aur_deps_count aur_deps
declare i pkg_aur_info pkg_base tarball_path depends makedepends dep_name aur_api_multireq dep_name aur_deps_api_data aur_deps_count aur_deps
read -r pkg_aur_info
@ -76,18 +75,18 @@ aur.get() {
(( flag_force )) || {
[[ -d "${cfg_workdir}/${pkg_base}" ]] && {
echo "Found ${pkg_base} in ${cfg_workdir}, skipping. Use -f to override."
printf "Found %s in %s, skipping. Use -f to override\n" "${pkg_base}" "${cfg_workdir}"
return 17
}
}
cd "$cfg_workdir"
echo "Working in ${cfg_workdir}"
printf "Working in %s\n" "${cfg_workdir}"
echo "Downloading ${pkg_base}"
printf "Downloading %s\n" "${pkg_base}"
{ curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
err "Fail!"
err "Fail!\n"
return 1
}
@ -104,7 +103,7 @@ aur.get() {
aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" )
if (( aur_deps_count )); then
echo "Getting dependencies for ${pkg_base}."
printf "Getting dependencies for %s\n" "${pkg_base}"
aur_deps=( $( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" ) )
@ -204,7 +203,7 @@ main() {
(-f) flag_force=1;;
(-*)
err "Unknown key: $1"
err "Unknown key: %s\n" "$1"
usage
return 1
;;
@ -234,7 +233,7 @@ main() {
(get)
[[ -d "$cfg_workdir" ]] || {
mkdir -p "$cfg_workdir" || {
err "Can't create workdir: ${cfg_workdir}."
err "Can't create workdir: %s\n" "$cfg_workdir"
return 1
}
}
@ -251,12 +250,12 @@ main() {
done < <( pacman -Si "$package" )
[[ "$repo" ]] || {
err "Can't find package ${package}"
err "Can't find package %s\n" "$package"
return 1
}
fi
echo "Found ${package} in ${repo}."
printf "Found %s in %s\n" "$package" "$repo"
case "$repo" in
(aur)
@ -266,7 +265,7 @@ main() {
abs.get "$package" "$repo";;
(*)
err "Repository $repo not supported."
err "Repository %s not supported\n" "$repo"
return 1;;
esac
;;
@ -274,7 +273,7 @@ main() {
(search)
if (( flag_search_aur )); then
aur.search "$package" || {
err "No packages found."
err "No packages found\n"
return 1
}
elif (( flag_search_syncdb )); then
@ -284,7 +283,7 @@ main() {
pacman -Ss "$package" 2>/dev/null || { flag_pacman_search_fail=1; }
if (( flag_aur_search_fail && flag_pacman_search_fail )); then
err "No packages found."
err "No packages found\n"
return 1
fi
fi