Re: ed2man: my newest quick hack

  • From: Tyler Spivey <tspivey@xxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 14 May 2011 17:30:08 -0700

I modified the function as follows, similar to Don's method. Assuming you don't 
want to use $EDITOR:
function e2m
{
if [ $# -lt 1 ];then
echo "Syntax: e2m <manpage>"
return
fi
local tmpfile="$(mktemp)"
man "$@"> "$tmpfile" && ed "$tmpfile"
rm -f "$tmpfile"
} 
The if statement could be replaced with a strung together command list,
but we need local in front of tmpfile; otherwise it's global.
Also, the $1 is replaced with $@. The reason being that some manpages are
in two sections, for example open(2) and open(3p),
accessed by either man 2 open or man 3p open.
On Sat, May 14, 2011 at 08:08:02PM -0400, Don Marang wrote:
> That is pretty much how I learned over the years as well.  A quick
> bash tutorial or two helps as well.  I will look up a useful link or
> two and provide below.  In bash there are many ways to get things
> done.  Your script function works well.  Below I will present a
> slightly different method.
> 
> function e2m{
> [ $# -ne 1 ] && echo "Syntax: e2m <manpage>" && return -1
> tmpfile=$(mktemp)
> man "$1"> "$tmpfile" && ed "$tmpfile" || echo "man command failed."
> rm -rf $tmpfile
> }
> 
> 
> The ; character can be used to string commands together on the same
> line.  The && (AND) operator is similar, but the second command does
> not get executed if the first command fails.  Many commands can be
> strung together like this.  The || (OR) operator is normally used at
> the end of such a sequence.  It is executed when any of the commands
> in the sequence fail.  I also added a return value, which will be
> the ErrorCode of the new command.  This is absolutely necessary if
> this function is used for a conditional statement in a script.
> 
> Bash Guide for Beginners
> http://tldp.org/LDP/Bash-Beginners-Guide/html/
> 
> Main Page - Linux Shell Scripting Tutorial - A Beginner's handbook
> http://bash.cyberciti.biz/guide/Main_Page
> 
> GNU Bash Reference Manual
> http://www.gnu.org/software/bash/manual/bashref.html
> *Don Marang*
> Vinux Software Development Coordinator - vinuxproject.org
> <http://www.vinuxproject.org/>
> There is just so much stuff in the world that, to me, is devoid of
> any real substance, value, and content that I just try to make sure
> that I am working on things that matter.
> -- Dean Kamen
> 
> On 5/14/2011 5:08 PM, Littlefield, Tyler wrote:
> >I've known bits and pieces of it for a long time, I just google
> >the syntaxes that I need and go from there. It's a bit slow, but
> >I've not had the motivation quite yet to sit down and learn bash.
> >On 5/14/2011 3:06 PM, Don Marang wrote:
> >>Thanks.  Looks like you are picking up bash pretty well.
> >>
> >>
> >>*Don Marang*
> >>Vinux Software Development Coordinator - vinuxproject.org
> >><http://www.vinuxproject.org/>
> >>There is just so much stuff in the world that, to me, is devoid
> >>of any real substance, value, and content that I just try to
> >>make sure that I am working on things that matter.
> >>-- Dean Kamen
> >>
> >>On 5/14/2011 4:33 PM, Littlefield, Tyler wrote:
> >>>Hello all:
> >>>I got kind of tired of messing with my client and it's weird
> >>>issues with manpages, cutting off the top when I page with the
> >>>pager, etc etc. So, I give you ed2man (which should actually
> >>>be man2ed, but I'm already stuck on writing e2m.
> >>>Just pop this in your .bashrc file and you should be set, enjoy!
> >>>function e2m
> >>>{
> >>>if [ $# -ne 1 ];then
> >>>echo "Syntax: e2m <manpage>"
> >>>return
> >>>fi
> >>>tmpfile=$(mktemp)
> >>>if ! man "$1"> "$tmpfile";then
> >>>rm -rf "$tmpfile"
> >>>else
> >>>ed "$tmpfile"
> >>>rm -rf $tmpfile
> >>>fi
> >>>}
> >>>
> >>>
> >
> >
> >-- 
> >
> >Take care,
> >Ty
> >my website:
> >http://tds-solutions.net
> >my blog:
> >http://tds-solutions.net/blog
> >skype: st8amnd127
> >“Programmers are in a race with the Universe to create bigger and better 
> >idiot-proof programs, while the Universe is trying to create bigger and 
> >better
> >idiots.  So far the Universe is winning.”
> >“If Java had true garbage collection, most programs would delete themselves 
> >upon execution.”
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: