Skip to content

Commit

Permalink
Code clean up part 2
Browse files Browse the repository at this point in the history
- avoid using escaped double quotes where possible
- use "+=" where possible
- remove "useless use of cat"
- "awk" statement refactoring
- replace 'echo ""' with 'echo'
  • Loading branch information
Steven Penny committed Mar 16, 2014
1 parent 135b3ab commit 54d23fc
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions apt-cyg
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ fi
function usage()
{
echo apt-cyg: Installs and removes Cygwin packages.
echo " \"apt-cyg install <package names>\" to install packages"
echo " \"apt-cyg remove <package names>\" to remove packages"
echo " \"apt-cyg update\" to update setup.ini"
echo " \"apt-cyg show\" to show installed packages"
echo " \"apt-cyg find <patterns>\" to find packages matching patterns"
echo " \"apt-cyg describe <patterns>\" to describe packages matching patterns"
echo " \"apt-cyg packageof <commands or files>\" to locate parent packages"
echo "Options:"
echo " --mirror, -m <url> : set mirror"
echo " --cache, -c <dir> : set cache"
echo " --file, -f <file> : read package names from file"
echo " --noupdate, -u : don't update setup.ini from mirror"
echo " --help"
echo " --version"
echo ' "apt-cyg install <package names>" to install packages'
echo ' "apt-cyg remove <package names>" to remove packages'
echo ' "apt-cyg update" to update setup.ini'
echo ' "apt-cyg show" to show installed packages'
echo ' "apt-cyg find <patterns>" to find packages matching patterns'
echo ' "apt-cyg describe <patterns>" to describe packages matching patterns'
echo ' "apt-cyg packageof <commands or files>" to locate parent packages'
echo 'Options:'
echo ' --mirror, -m <url> : set mirror'
echo ' --cache, -c <dir> : set cache'
echo ' --file, -f <file> : read package names from file'
echo ' --noupdate, -u : dont update setup.ini from mirror'
echo ' --help'
echo ' --version'
}

function version()
Expand Down Expand Up @@ -204,11 +204,11 @@ if test $dofile = 1
then
if test -f "$file"
then
filepackages="$filepackages `cat "$file" | awk '{printf "%s ", $0}'`"
filepackages+=$(awk '{printf " %s", $0}' "$file")
else
echo File $file not found, skipping
fi
packages="$packages $filepackages"
packages+=" $filepackages"
fi

case "$command" in
Expand All @@ -220,7 +220,7 @@ case "$command" in

show)
echo The following packages are installed: >&2
cat /etc/setup/installed.db | awk '/[^ ]+ [^ ]+ 0/ {print $1}'
awk 'NR>1 && $0=$1' /etc/setup/installed.db
;;

find)
Expand All @@ -229,10 +229,10 @@ case "$command" in
getsetup
for pkg in $packages
do
echo ""
echo
echo Searching for installed packages matching $pkg:
awk '/[^ ]+ [^ ]+ 0/ {if ($1 ~ query) print $1}' query="$pkg" /etc/setup/installed.db
echo ""
awk 'NR>1 && $1~query && $0=$1' query="$pkg" /etc/setup/installed.db
echo
echo Searching for installable packages matching $pkg:
awk '$1 ~ query && $0 = $1' RS='\n\n@ ' FS='\n' query="$pkg" setup.ini
done
Expand Down Expand Up @@ -260,7 +260,7 @@ case "$command" in
fi
for manifest in /etc/setup/*.lst.gz
do
found=`cat $manifest | gzip -d | grep -c "$key"`
found=$(gzip -cd $manifest | grep -c "$key")
if test $found -gt 0
then
package=`echo $manifest | sed -e "s:/etc/setup/::" -e "s/.lst.gz//"`
Expand Down Expand Up @@ -315,7 +315,7 @@ case "$command" in

if test "-$install-" = "--"
then
echo "Could not find \"install\" in package description: obsolete package?"
echo 'Could not find "install" in package description: obsolete package?'
exit 1
fi

Expand Down

0 comments on commit 54d23fc

Please sign in to comment.