Jump to content

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
Link to comment

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
Link to comment
  • 5 weeks later...

"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"
Link to comment
  • 3 months later...

"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 )

Link to comment
  • 2 years later...
  • 3 months later...

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.
Link to comment

- 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.

 

Link to comment

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.

Link to comment

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
Link to comment
  • 1 year later...

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

Link to comment
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.

Link to comment
  • 1 year later...
43 minutes ago, gingerbeardman said:

This has stopped working for me in a recent version of Alfred?

 

man<space> gets me the menu item but any further typing sees it go away and i can therefore not get any useful results.

 

Screen recording: https://imgur.com/a/neDNArt

 

I am guessing it is the same issue that I encountered.

 

Open up alfredman.py and replace lines 29 - 33 with the following

 


    for info in pagelist:
        if len(info) != 2:
            continue
        for item in info[0].split(', '):
            whatis[item] = info[1]
    json.dump(whatis, open(cache, 'w'))
    return whatis

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...