Skip to content

Commit

Permalink
s/echo/printf/ -- and some extra juju to go with
Browse files Browse the repository at this point in the history
  • Loading branch information
falconindy committed Dec 29, 2010
1 parent 3dcc61d commit a4726de
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 103 deletions.
4 changes: 2 additions & 2 deletions aurcomm
Expand Up @@ -37,7 +37,7 @@ getpkgID() {

if ! (( $# )); then
if [[ ! -f PKGBUILD ]]; then
echo "error: no PKGBUILD found and no arg provided"
printf "error: no PKGBUILD found and no arg provided\n"
exit 1
fi
eval $(grep '^pkgname=' PKGBUILD)
Expand All @@ -46,7 +46,7 @@ fi
pkgname=${1:-$pkgname}

pkgID=$(getpkgID $pkgname)
[[ $pkgID ]] || { echo "error: package \`$pkgname' not found"; exit 1; }
[[ $pkgID ]] || { printf "error: package \`%s' not found" "$pkgname"; exit 1; }

curl -s "$AURURL/packages.php?ID=$pkgID$showall" | commfilter

4 changes: 2 additions & 2 deletions aurdiff
Expand Up @@ -7,13 +7,13 @@
DIFF=${DIFF:-diff}

if [[ ! -f PKGBUILD ]]; then
echo "error: No PKGBUILD found in working directory."
printf "error: No PKGBUILD found in working directory.\n"
exit 1
fi >&2

eval $(grep '^pkgname=' PKGBUILD)
if [[ -z $pkgname ]]; then
echo "error: pkgname not found in PKGBUILD"
printf "error: pkgname not found in PKGBUILD\n"
exit 1
fi >&2

Expand Down
4 changes: 2 additions & 2 deletions ethstat
@@ -1,6 +1,6 @@
#!/bin/bash

echo "Network Device Statistics (in mb)"
printf "Network Device Statistics (in mb)\n"
printf "\n%8s%10s%10s%8s\n" "Device" "Sent" "Received" "Ratio"
#echo ---------------------------------------
for dev in /sys/class/net/*; do
Expand All @@ -11,4 +11,4 @@ for dev in /sys/class/net/*; do
ratio=$(posty <<< ":2 $sent $recv /")
printf "%8s%10.2f%10.2f%8.2f\n" $dev $sent $recv $ratio
done
echo

22 changes: 10 additions & 12 deletions flac2mp3
Expand Up @@ -30,21 +30,19 @@ die() {
} >&2

mkdir_vp() {
mkdir -p "$1" && echo "$ARG0: created directory ``$1'"
mkdir -p "$1" && printf "%s: created directory \`%s'" "$ARG0" "$!"
}

usage() {
echo "usage: $ARG0 [options] SOURCE... DESTINATION"
echo " $ARG0 [options] -t DESTINATION SOURCE..."
echo
echo " -f overwrite existing files"
echo " -h display this help message"
echo " -l ARGS additional parameters to pass to lame"
echo " -q don't print to stdout"
echo " -r convert directories recursively (implies -p)"
echo " -t PATH use PATH as destination for converted SOURCEs"
echo " -w quit on warnings"
echo
printf "usage: $ARG0 [options] SOURCE... DESTINATION\n"
printf " $ARG0 [options] -t DESTINATION SOURCE...\n\n"
printf " -f overwrite existing files\n"
printf " -h display this help message\n"
printf " -l ARGS additional parameters to pass to lame\n"
printf " -q don't print to stdout\n"
printf " -r convert directories recursively (implies -p)\n"
printf " -t PATH use PATH as destination for converted SOURCEs\n"
printf " -w quit on warnings\n\n"
} >&2

# find flac files in a given dir, recursing unless told otherwise
Expand Down
12 changes: 6 additions & 6 deletions git-all
Expand Up @@ -50,7 +50,7 @@ breadlink() {
pwd -P
)
else
echo "$path"
printf "%s\n" "$path"
fi
}
do_all_action() {
Expand All @@ -72,28 +72,28 @@ stat_repos() {
local repo=$(breadlink ${repo%.git})

cd "$repo"
[[ -n $(git status -s | grep -v "^??") ]] && echo "$repo"
[[ -n $(git status -s | grep -v "^??") ]] && printf "%s\n" "$repo"
done
}

job_summary() {
echo
printf "\n"
msg "Job Summary For $count Repos: git $*"

if [[ ${#fail[@]} -eq 0 ]]; then
msg2 "No errors were reported"
else
for repo in "${fail[@]}"; do
repofail "$repo"
(( VERBOSE )) && { sed 's/^/ /' <<< "${output[$repo]}"; echo; } >&2
(( VERBOSE )) && { sed 's/^/ /' <<< "${output[$repo]}"; printf "\n"; } >&2
done
fi
echo
printf "\n"

for repo in "${pass[@]}"; do
repopass "$repo"
done
echo
printf "\n"
}

# sanity check
Expand Down
8 changes: 4 additions & 4 deletions git-retrotag
Expand Up @@ -87,8 +87,8 @@ review_candidates() {

ask_abort() {
read -N1 -p "Satisfied? Continue with tagging? (y/N) " reply
echo
[[ ! "$reply" =~ [Yy] ]] && { echo "Aborting..."; exit 1; }
printf "\n"
[[ ! "$reply" =~ [Yy] ]] && { printf "Aborting...\n"; exit 1; }
}

tag_commits() {
Expand Down Expand Up @@ -118,10 +118,10 @@ tag_commits() {
done

if (( count > 0 )); then
echo
printf "\n"
msg "Finished: Added $count new tags. Use \`git push --tags\` to update the remote."
else
echo
printf "\n"
msg "Finished: No new tags were added."
fi
}
Expand Down
8 changes: 4 additions & 4 deletions hex2rgb
@@ -1,21 +1,21 @@
#!/bin/bash

[[ -z $1 ]] && {
echo "Usage: ${0##*/} <XResources color file>" >&2
printf "Usage: %s <XResources color file>" "${0##*/}" >&2
exit 1
}

hex2dec() {
for val; do
printf "%3d " 0x$val
printf "%3d " "0x$val"
done
echo
printf "\n"
}

printf "\t\t%3s %3s %3s\n" "R" "G" "B"
while read line; do
[[ ! $line =~ ^\*color ]] && continue
echo -ne "${line% *}\t"
printf "${line% *}\t"
hexcode=${line/\*color* /}
hex2dec ${hexcode:1:2} ${hexcode:3:2} ${hexcode:5:2}
done < $1
Expand Down
18 changes: 9 additions & 9 deletions hglink
Expand Up @@ -13,20 +13,20 @@ get_hgroot() {
while [[ $curpath && ! -d $curpath/.hg ]]; do
curpath=${curpath%/*}
done
[[ $curpath ]] && echo "$curpath"
[[ $curpath ]] && printf "%s\n" "$curpath"
}

usage() {
echo "Usage: ${0##*/} [ -l linenum ] [ -b ] <file> [ hash ]"
printf "Usage: %s [ -l linenum ] [ -b ] <file> [ hash ]" "${0##*/}"
} >&2

while getopts ":bhl:" opt; do
case $opt in
b) OPENINBROWSER=1 ;;
h) usage; exit 1 ;;
l) LINE=$OPTARG ;;
\:) echo "Argument required for -$OPTARG" ;;
\?) echo "error: bad arg, no bisuit" ;;
\:) printf "Argument required for -%s\n" "$OPTARG" ;;
\?) printf "error: bad arg, no bisuit\n" ;;
esac >&2
done
shift $(( OPTIND - 1 ))
Expand All @@ -35,7 +35,7 @@ shift $(( OPTIND - 1 ))

fullpath=$(readlink -m "$1")
hg_root=$(get_hgroot "$fullpath")
[[ -z $hg_root ]] && { echo "error: '$1' is not in an hg repo"; exit 1; }
[[ -z $hg_root ]] && { printf "error: '%s' is not in an hg repo\n" "$1"; exit 1; }

# we need to operate from within the hg repo. if we're not in it, go there
[[ ${PWD#$hg_root} = $PWD ]] && cd $hg_root
Expand All @@ -53,7 +53,7 @@ rev=${2:-$(hg log -r $remotetip | awk -F: 'NR == 1 { print $3 }')}
# relative path from repo root to file
relpath=${fullpath#$hg_root/}
if [[ -z $relpath ]]; then
echo "error: failed to determine path to $1. tell dave he sucks at bash"
printf "error: failed to determine path to %s. tell dave he sucks at bash\n" "$1"
exit 1
fi

Expand All @@ -64,11 +64,11 @@ urlout="${remotepath}/file/$rev/$relpath${LINE:+#l$LINE}"
if type -P curl >/dev/null; then
# hgweb kindly responds with a 404 on an invalid link -- so let's validate!
if ! curl -sf "$urlout" >/dev/null; then
echo "error: failed to create a valid link to '$1'. check your repo and filepath"
printf "error: failed to create a valid link to '%s'. check your repo and filepath\n" "$1"
exit 1
fi
fi

# echo or open in browser
(( OPENINBROWSER )) && ${BROWSER:-chromium} "$urlout" || echo "$urlout"
# print or open in browser
(( OPENINBROWSER )) && ${BROWSER:-chromium} "$urlout" || printf "%s\n" "$urlout"

49 changes: 22 additions & 27 deletions list2html
@@ -1,41 +1,36 @@
#!/bin/bash

if [[ $# -ne 2 ]]; then
echo "Usage: $0 <columns> <input file>" >&2
exit 1
fi
(( $# != 2 )) && { printf "Usage: %s <columns> <input file>\n" "${0##*/}"; exit 1; } >&2

# Redirect STDOUT to an html file
exec >> output.html

# Start table
echo "<table>"
printf "<table>\n"

count=0 # Initialize a counter for columns
while read line; do
if [[ $count -eq 0 ]]; then
# We're at the start of a new row, open it.
printf "\t<tr>\n"
fi

if [[ $count -lt $1 ]]; then
# Print next line from data file
printf "\t\t<td>%s</td>\n" "$line"
fi

(( count++ ))

if [[ $count -eq $1 ]]; then
# We're at the end of a row, close it.
printf "\t</tr>\n"
count=0
fi
done < $2
if [[ $count -eq 0 ]]; then
# We're at the start of a new row, open it.
printf "\t<tr>\n"
fi

if [[ $count -lt $1 ]]; then
# Print next line from data file
printf "\t\t<td>%s</td>\n" "$line"
fi

(( count++ ))

if [[ $count -ne 0 ]]; then
# Kludge for when columns doesn't divide equally into data size
if [[ $count -eq $1 ]]; then
# We're at the end of a row, close it.
printf "\t</tr>\n"
fi
count=0
fi
done < $2

# Kludge for when columns doesn't divide equally into data size
(( count )) && printf "\t</tr>\n"

# End table
echo "</table>"
printf "</table>\n"
4 changes: 2 additions & 2 deletions mancx
Expand Up @@ -11,7 +11,7 @@ XPATH_EXPR='//*[@id="manpage"]/*[self::pre or self::h3]'
DETAG='$d;s|</\?[^>]\+>||g;s|&lt\;|<|g;s|&gt\;|>|g'

usage() {
echo "Usage: ${0##*/} [section] manpage" >&2
printf "Usage: %s [section] manpage" "${0##*/}" >&2
}

# less gets color, else its a NOOP
Expand All @@ -37,4 +37,4 @@ esac
man ${SECTION//[^[:digit:]]/} $PAGE 2>/dev/null && exit

manpage=$(curl -s $BASEURL/$PAGE$SECTION | $XMLLINT --xpath "$XPATH_EXPR" - 2>/dev/null | sed "$DETAG" | colorify)
[[ $manpage ]] && "${PAGER:-less}" <<< "$manpage" || echo "No mancx entry for $PAGE"
[[ $manpage ]] && "${PAGER:-less}" <<< "$manpage" || printf "No mancx entry for %s\n" "$PAGE"
10 changes: 5 additions & 5 deletions pkgfile
Expand Up @@ -18,7 +18,7 @@ createfileball() {
[[ -f repos.files.tar.gz ]] && rm repos.files.tar.gz
mkdir -p {testing,core,extra,community{,-testing}}

echo -n "Downloading and extracting repo tarballs... "
printf "Downloading and extracting repo tarballs... "
for repo in "${repos[@]}"; do
(
curl -s "${mirror/\$repo/$repo/}/$repo.files.tar.gz" | tar -xz --wildcards -C $repo '*/files'
Expand All @@ -29,11 +29,11 @@ createfileball() {
) &
done
wait
echo "done!"
printf "done!\n"

echo -n "Creating master file tarball... "
printf "Creating master file tarball... "
tar czf repos.files.tar.gz *
echo "done!"
printf "done!\n"

rm -r "${repos[@]}"
}
Expand All @@ -49,7 +49,7 @@ whoowns() {
local needle="${1//\//\\/}"
tar -Oxvf "$CACHEDIR/repos.files.tar.gz" |& awk '/%FILES%/{ pkg = prev; next }
{ sub("/files", ""); prev = $0 }
/'"$needle"'[^\/]+$/{ printf "%-30s %s\n",pkg,$0 }'
/'"$needle"'/{ printf "%-30s %s\n",pkg,$0 }'
}

[[ $1 ]] || exit 1
Expand Down
10 changes: 5 additions & 5 deletions pp
Expand Up @@ -23,7 +23,7 @@ done

(( !SYNC || BORING_OPT )) && exec pacman $@

(( UID != 0 )) && { echo "Must be root!"; exit 1; } >&2
(( UID != 0 )) && { printf "Must be root!\n"; exit 1; } >&2

# find alternate pacman cache location
paccache=$(awk -F' *= *' '/[^#]CacheDir/{ print $2 }' /etc/pacman.conf)
Expand All @@ -34,7 +34,7 @@ unset paccache
IFS=$'\n' read -r -d'\0' -a pkgs < <(pacman -p "${PACARGS[@]}" | grep -E '^(ht|f)tp')

# exit on null array
[[ -z "${pkgs[@]}" ]] && { echo "Nothing to do!"; exit 0; }
[[ -z "${pkgs[@]}" ]] && { printf "Nothing to do!\n"; exit 0; }

# create a dl manifest, so we don't pass superfluous URLs to aria
manifest=()
Expand All @@ -43,9 +43,9 @@ for pkg in "${pkgs[@]}"; do
done

if [[ ${manifest[@]} ]]; then
echo ":: Packages to be downloaded:"
printf ":: Packages to be downloaded:\n"
for pkg in "${manifest[@]}"; do
echo " ==> ${pkg##*/}"
printf " ==> %s\n" "${pkg##*/}"
done
fi

Expand All @@ -56,6 +56,6 @@ for arg; do
ARGS+=("$arg")
done

aria2c --dir "$PACCACHE" -i - < <(for pkg in "${manifest[@]}"; do echo "$pkg"; done)
aria2c --dir "$PACCACHE" -i - < <(for pkg in "${manifest[@]}"; do printf "%s" "$pkg"; done)
(( DL_ONLY )) || pacman "${ARGS[@]}"

4 changes: 2 additions & 2 deletions randomJunk
Expand Up @@ -3,8 +3,8 @@
ALLOWEDCHARS='[:alnum:][:punct:]'

if [[ $# -eq 0 ]]; then
echo "Usage: ${0##*/} <string length> [output quantity]" >&2
exit 1
printf "Usage: %s <string length> [output quantity]" "${0##*/}" >&2
exit 1
fi

quantity=${2:-1}
Expand Down

0 comments on commit a4726de

Please sign in to comment.