public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Better way to do this? (bash scripting)
@ 2004-03-02  7:22 Yaakov Selkowitz
  2004-03-02 17:13 ` Igor Pechtchanski
  0 siblings, 1 reply; 2+ messages in thread
From: Yaakov Selkowitz @ 2004-03-02  7:22 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 831 bytes --]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I hope this isn't considered too far OT, but perhaps someone will find
this useful.

I wrote the attached scripts, which I place in /etc/profile.d/, in order
to get quicker access to the original-package and Cygwin-specific
documentation.  (pkgdoc and cygdoc respectively)

What I wanted to know is:

1) is there a better and/or more precise way of searching for the file?
2) is there a better and/or more precise way of verifying that there's
actually such a file to feed to less, instead of calling find twice?

Thanks,

Yaakov
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFARDYUpiWmPGlmQSMRAu1aAKDdA7+M+wnPOicNdyWjifcVUhNe8wCglX41
sG4Xcs2dK0s6UxN0inASeBY=
=kLLr
-----END PGP SIGNATURE-----

[-- Attachment #2: pkgdoc.sh --]
[-- Type: text/plain, Size: 1886 bytes --]

#############################################################################
#
#  Quick command-line access to package documentation files.
#
#  Copyright (C) 2004 by Yaakov Selkowitz.  All Rights Reserved.
#
#  This script is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as 
#  published by the Free Software Foundation; either version 2 of the 
#  License, or (at your option) any later version.
#
#  This script is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#############################################################################

version=0.1

if [ ! "${PKGDOC_PATH}" ] ; then \
  PKGDOC_PATH=/usr/doc:/usr/share/doc:/usr/X11R6/doc
  export PKGDOC_PATH
fi


function pkgdoc {

case $1 in 
  -p|--path)
	echo "PKGDOC_PATH=${PKGDOC_PATH}" ; STATUS=$? ;;

  -h|--help)
	echo "Usage: pkgdoc [OPTIONS] PACKAGE FILE

Displays the upstream FILE documentation for specified PACKAGE.

OPTIONS:
  -h, --help		Displays this help and exits.
  -V, --version		Displays version information and exits.
  -p, --path		Displays the current PKGDOC_PATH and exits.
" ; STATUS=$? ;;

  -V|--version)
	echo "pkgdoc $version
Copyright (C) 2004 by Yaakov Selkowitz.  All Rights Reserved.
This script is released under the GNU General Public License.

Bug reports, patches, etc. can be sent to yselkowitz AT users.sourceforge.net.
" ; STATUS=$? ;;

  *)
	for d in `echo ${PKGDOC_PATH} | sed 's%:% %g'` ; do
	for pd in $d/$1-* $d/$1 ; do
	  if [ -d $pd ] ; then
	  if [ $(find $pd -name $2) ] ; then
	    find $pd -name $2 | xargs less
	  else
	    echo "No $2 documentation was found for the $1 package."
	  fi
	  fi
	done
	done ; STATUS=$? ;;

esac
}

[-- Attachment #3: cygdoc.sh --]
[-- Type: text/plain, Size: 1889 bytes --]

#############################################################################
#
#  Quick command-line access to Cygwin README files.
#
#  Copyright (C) 2004 by Yaakov Selkowitz.  All Rights Reserved.
#
#  This script is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as 
#  published by the Free Software Foundation; either version 2 of the 
#  License, or (at your option) any later version.
#
#  This script is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#############################################################################

version=0.1

if [ ! "${CYGDOC_PATH}" ] ; then \
  CYGDOC_PATH=/usr/doc/Cygwin:/usr/share/doc/Cygwin:/usr/X11R6/doc/Cygwin
  export CYGDOC_PATH
fi


function cygdoc {

case $1 in 
  -p|--path)
	echo "CYGDOC_PATH=${CYGDOC_PATH}" ; STATUS=$? ;;

  -h|--help)
	echo "Usage: cygdoc [OPTIONS] PKG

Displays the Cygwin README documentation for specified package.

OPTIONS:
  -h, --help		Displays this help and exits.
  -V, --version		Displays version information and exits.
  -p, --path		Displays the current CYGDOC_PATH and exits.
" ; STATUS=$? ;;

  -V|--version)
	echo "cygdoc $version
Copyright (C) 2004 by Yaakov Selkowitz.  All Rights Reserved.
This script is released under the GNU General Public License.

Bug reports, patches, etc. can be sent to yselkowitz AT users.sourceforge.net.
" ; STATUS=$? ;;

  *)
	if [ $(find `echo ${CYGDOC_PATH} | sed 's%:% %g'` -name $1-*.README -o -name $1.README) ] ; then
	  find `echo ${CYGDOC_PATH} | sed 's%:% %g'` -name $1-*.README -o \
	    -name $1.README | xargs less
	else
	  echo "No Cygwin README file was found for the $1 package."
	fi ; STATUS=$? ;;

esac
}


[-- Attachment #4: Type: text/plain, Size: 218 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Better way to do this? (bash scripting)
  2004-03-02  7:22 Better way to do this? (bash scripting) Yaakov Selkowitz
@ 2004-03-02 17:13 ` Igor Pechtchanski
  0 siblings, 0 replies; 2+ messages in thread
From: Igor Pechtchanski @ 2004-03-02 17:13 UTC (permalink / raw)
  To: Yaakov Selkowitz; +Cc: cygwin

On Tue, 2 Mar 2004, Yaakov Selkowitz wrote:

> I hope this isn't considered too far OT, but perhaps someone will find
> this useful.
>
> I wrote the attached scripts, which I place in /etc/profile.d/, in order
> to get quicker access to the original-package and Cygwin-specific
> documentation.  (pkgdoc and cygdoc respectively)
>
> What I wanted to know is:
>
> 1) is there a better and/or more precise way of searching for the file?

Well, every way I can think of will use 'find' at least once (maybe cache
the results, like 'locate' does).

> 2) is there a better and/or more precise way of verifying that there's
> actually such a file to feed to less, instead of calling find twice?
>
> Thanks,
> Yaakov

a) You can supply multiple directories as starting points to GNU find,
e.g.,

find /usr/bin /usr/include -type f -name \*cygwin\* -print

b) Use the "-r" parameter to xargs, so that the program won't be invoked
unless something is found, e.g.,

find /usr/bin /usr/include -type f -name \*cygwin\* -print0 | xargs -r0 ls -l

c) Use the -path predicate rather than -name.

Also, your scripts are not space-in-filename friendly -- a no-no for
Cygwin -- and the "no documentation" message will be printed for every
directory (which is not quite what you want).  So, with the above fixed,
the first set of 'for' loops in your pkgdoc.sh could become something like

# -------------------
package_dirs=`echo "'${PKGDOC_PATH}'" | sed "s%:%' '%g"`
readme_files=`eval "find $package_dirs -path '*$1-*/$2' -o \
                         -path '*$1/*/$2' -o -path '*$1/$2' -print | \
                    sed -e "s%^%'%" -e "s%$%'%"`
if [ -n "$readme_files" ]; then
  echo $readme_files | xargs -r less
else
  echo "No $2 documentation was found for the $1 package"
fi
STATUS=$? ;;
# -------------------

HTH,
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-03-02 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-02  7:22 Better way to do this? (bash scripting) Yaakov Selkowitz
2004-03-02 17:13 ` Igor Pechtchanski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).