Hacker News new | ask | show | jobs
by k4rthik 4373 days ago
I have

for cmd in $(compgen -c); do if [[ $cmd =~ ^[0-9a-zA-Z]+$ ]]; then eval "alias $cmd?='man $cmd'"; fi; done

in my .bashrc to alias command?=man command, saves some typing to get to man pages ( which I do very often )

3 comments

Speaking of man pages, in earlier versions of Unix and Linux, I used to want to redirect the output of many man commands to files for later reading, e.g. if working on C, say I wanted to read 'man ioctl', 'man stdio', 'man signal', etc. But the man output had {n|t}roff formatting characters in it, for print output, which used to mess up vi. So I used to use this script I wrote, called m:

# Put this script in a directory in your PATH.

# m: pipe man output through col and save to file(s).

mkdir -p ~/man # Only creates the dir first time, including all dirs in the path.

for name: # in $* is implied

    man $name | col -bx > ~/man/$name.m
done

Do a "chmod u+x m" to be able to run it.

Then run it like this:

m ioctl stdio signal # or any other commands

Then:

pushd ~/man; view ioctl.m stdio.m signal.m; popd

to read those pages, now stripped of formatting characters.

Wow. I never knew about the `compgen -c` command to show bash command completions. Also from this reference [1] I found these:

    % compgen -b # built-ins
    % compgen -k # keywords
    % compgen -A function # functions
    % compgen -abckA function # everything
[1] http://www.cyberciti.biz/open-source/command-line-hacks/comp...
For zsh:

  for cmd in $(compgen -c); do if [[ $cmd =~ ^[0-9a-zA-Z]+$ ]]; then eval "alias $cmd\?='man $cmd'"    ; fi; done
# had to escape the ? in the alias name

Cool trick :)