Jump to content
isometry

Unix man page workflow

Recommended Posts

Open man pages with name and section filtering.

 

The 'man' keyword exploits the x-man-page: protocol handler, so will default to opening in Terminal.app but can easily be switched to iTerm2.app. 'hman' opens pages in your default browser, and 'pman' opens PDFs in the default PDF reader.

 

Download / Source

 

 

Usage

man open(1)  # open a specific page

pman style   # open a PDF of the style(9) manpage

man open     # search all sections for pages matching 'open*'

man *open    # search all sections for pages matching '*open*'

man 2 open   # search section 2 for pages with 'open' in the name

 

Enjoy.

Edited by isometry

Share this post


Link to post

I use a similar workflow based on that shell code fragment: 

 

man -t {query} | open -f -a Skim

as proposed in the Skim FAQ. Maybe somebody else likes this too :)

 

I wasn't keen to rely on additional third-party software. However, I have just updated the workflow with another keyword: 'hman' will open a HTML copy of the man page in Safari; change to Chrome or your browser of choice by tweaking the BROWSER variable at the top of the hman Run Script your default browser.

 

Known issue: some pages aren't rendered properly in HTML (a groff bug?). Any tips on how to fix this gratefully received.

Edited by isometry

Share this post


Link to post

"can easily be switched to iTerm2.app" - How?

 

Something along the following lines should do the job:

 

  1. Create a new profile named "Man Page Handler" (or whatever)
  2. Set its command to "/usr/bin/man $$HOST$$" (without the quotes)
  3. Select "x-man-page" under "Schemes Handled"

Share this post


Link to post

"can easily be switched to iTerm2.app" - How?

 

 

 

Something along the following lines should do the job:

 

  1. Create a new profile named "Man Page Handler" (or whatever)
  2. Set its command to "/usr/bin/man $$HOST$$" (without the quotes)
  3. Select "x-man-page" under "Schemes Handled"

 

 

The command I use is /bin/bash -c "/usr/bin/man  -S `echo $$HOST$$` `echo $$PATH$$|tr -d /`"

 

since $$HOST$$ is set to the man page section  and $$PATH$$ is equal to /command (so the leading / must be stripped )

Share this post


Link to post

Can someone help with this. I tried doing what was said above but it still opens everything in Terminal. :(

 

How can I make it work? :(

 

Here is a screencast of me trying to set it up : http://quick.as/b04as8aep

 

If anyone knows a way to fix this, that would be incredible. Thank you for any help.

Share this post


Link to post

Nice!

 

But...it doesn't access stuff installed via MacPorts. In terminal (or iTerm) "man nmap" gets me the manpage for nmap. In Alfred, "man nmap" gets me a 404. 

Share this post


Link to post

Nice!

 

But...it doesn't access stuff installed via MacPorts. In terminal (or iTerm) "man nmap" gets me the manpage for nmap. In Alfred, "man nmap" gets me a 404. 

 

 

You probably need to make sure MANPATH is set in the workflow.

Share this post


Link to post

You probably need to make sure MANPATH is set in the workflow.

 

 

In the workflow? MANPATH is set export MANPATH=/opt/local/share/man:$MANPATH) and works in iTerm2 and Terminal. How do I add it to the workflow?

Share this post


Link to post

In the workflow? MANPATH is set export MANPATH=/opt/local/share/man:$MANPATH) and works in iTerm2 and Terminal. How do I add it to the workflow?

 

 

Dunno, tbh. I'd add it to /etc/manpaths instead.
 
Can you find the man page for any MacPort program?
 
If you've just installed nmap, it's also possible that the manpage index simply hasn't been updated yet. Updating the indices might help. Try:
 
sudo /usr/libexec/makewhatis
 
You'll also need to delete the workflow's cache files in ~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/net.isometry.alfred.man/ so it re-reads the indices.
 

 

Finally, it's also possible that you need to enter Nmap, not nmap.

Share this post


Link to post

- path is in /etc/manpaths

- reindexed

- cleared Alfred/Workflow cache (didn't do that before...had high hopes)

- Tried nmap and Nmap

 

Still not working. 

 

I tried several (of course not all) ports (some of them installed for ages, others recently) in iTerm2 with man. nmap, bonnie, iozone, htop....they all work, but none with the Alfred workflow. 

 

 

 

 

 

Dunno, tbh. I'd add it to /etc/manpaths instead.
 
Can you find the man page for any MacPort program?
 
If you've just installed nmap, it's also possible that the manpage index simply hasn't been updated yet. Updating the indices might help. Try:
 
sudo /usr/libexec/makewhatis
 
You'll also need to delete the workflow's cache files in ~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/net.isometry.alfred.man/ so it re-reads the indices.
 

 

Finally, it's also possible that you need to enter Nmap, not nmap.

 

Share this post


Link to post

Interesting...they don't. 

 

Apparently "man -k -Pcat ." dumps the man pages from OSX while man also accesses the MacPorts man pages....

 

Neither nmap, bonnie, htop, aria2c appear in the dump but man works with them...

 

 

Do the programs appear when you run:

 

man -k -Pcat .

 

That dumps a list of all man files.

Share this post


Link to post

So it's your man command that's not working properly, not the workflow.

 

Is there a whatis file in the MacPorts man directory? That's the index man -k (and apropos and whatis) uses.

 

The plain man command doesn't use the index. That's why it works when -k doesn't.

Edited by deanishe

Share this post


Link to post

IS this considered solved?

 

My installation does not work (latest OS, latest Alfred 3, latest workflow).

 

This is the debug log when typing "man g" into Alfred:

Starting debug for 'man'

[2018-02-21 10:04:37][ERROR: input.scriptfilter] Code 1: Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "alfredman.py", line 80, in complete
    whatis = fetch_whatis()
  File "alfredman.py", line 20, in fetch_whatis
    cache = path.join(alfred.work(volatile=True), u'whatis.1.json')
  File "alfred.py", line 70, in work
    return _create(os.path.join(os.path.expanduser(path), bundleid))
  File "alfred.py", line 83, in _create
    os.mkdir(path)
OSError: [Errno 2] No such file or directory: '/Users/tschloss/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/net.isometry.alfred.man'

 

Any suggestions? I am not able to heal it myself.

 

Thank you

Thomas

Share this post


Link to post
22 minutes ago, tschloss said:

Any suggestions? I am not able to heal it myself.

 

The problem is that this workflow has Alfred 2's directories hardcoded, but your system doesn't have them because you're using Alfred 3.

 

Going by the error, the workflow uses the alfred.py library. You should open that file in an editor and change Alfred-2 and Alfred 2 to Alfred-3 and Alfred 3 respectively.

Share this post


Link to post

In that case, an easier solution might be to create the Alfred 2 directories they're expecting to find.

 

I never deleted mine for the same reason. It's a lot easier than fixing a dozen or more workflows.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...