Skip to content

Commit

Permalink
List manual pages by searching directories
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorgalvao committed Mar 18, 2024
1 parent 7a5be5d commit 3b90094
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 44 deletions.
Binary file modified Workflow/images/about/pdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Workflow/images/about/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Workflow/images/about/text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 61 additions & 44 deletions Workflow/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@
<dict>
<key>config</key>
<dict>
<key>displaymode</key>
<integer>0</integer>
<key>stackview</key>
<false/>
</dict>
Expand Down Expand Up @@ -508,6 +510,33 @@
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>adduuid</key>
<true/>
<key>allowemptyfiles</key>
<true/>
<key>createintermediatefolders</key>
<true/>
<key>filename</key>
<string>/tmp/{const:alfred_workflow_bundleid}/manual.{var:format}</string>
<key>filetext</key>
<string>{query}</string>
<key>ignoredynamicplaceholders</key>
<false/>
<key>relativepathmode</key>
<integer>0</integer>
<key>type</key>
<integer>1</integer>
</dict>
<key>type</key>
<string>alfred.workflow.output.writefile</string>
<key>uid</key>
<string>FADD8B56-CD2D-413B-9832-B8CBEEC9D8EC</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -540,7 +569,7 @@
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>/usr/bin/mandoc -T "${format}" "$(/usr/bin/man -S "${section_number}" -w "${1}")"</string>
<string>/usr/bin/mandoc -T "${format}" "${1}"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -637,6 +666,8 @@
<integer>0</integer>
<key>fontmode</key>
<integer>0</integer>
<key>fontsizing</key>
<integer>0</integer>
<key>footertext</key>
<string></string>
<key>inputfile</key>
Expand All @@ -649,6 +680,8 @@
<integer>0</integer>
<key>scriptinput</key>
<integer>0</integer>
<key>spellchecking</key>
<integer>0</integer>
<key>stackview</key>
<false/>
</dict>
Expand All @@ -674,33 +707,6 @@
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>adduuid</key>
<true/>
<key>allowemptyfiles</key>
<true/>
<key>createintermediatefolders</key>
<true/>
<key>filename</key>
<string>/tmp/{const:alfred_workflow_bundleid}/manual.{var:format}</string>
<key>filetext</key>
<string>{query}</string>
<key>ignoredynamicplaceholders</key>
<false/>
<key>relativepathmode</key>
<integer>0</integer>
<key>type</key>
<integer>1</integer>
</dict>
<key>type</key>
<string>alfred.workflow.output.writefile</string>
<key>uid</key>
<string>FADD8B56-CD2D-413B-9832-B8CBEEC9D8EC</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -914,12 +920,12 @@ function envVar(varName) {
.objectForKey(varName).js
}
function manuals(sections) {
function runCommand(...arguments) {
const task = $.NSTask.alloc.init
const stdout = $.NSPipe.pipe
task.executableURL = $.NSURL.fileURLWithPath("/usr/bin/man")
task.arguments = ["-S", sections.join(":"), "-k", "."]
task.executableURL = $.NSURL.fileURLWithPath("/usr/bin/env")
task.arguments = arguments
task.standardOutput = stdout
task.launchAndReturnError(false)
Expand All @@ -929,6 +935,19 @@ function manuals(sections) {
return stringOut
}
function dirContents(path) {
const arguments = [
$.NSURL.fileURLWithPath(path),
undefined,
$.NSDirectoryEnumerationSkipsHiddenFiles,
undefined
]
return $.NSFileManager.defaultManager
.contentsOfDirectoryAtURLIncludingPropertiesForKeysOptionsError(...arguments)
.js.map(p =&gt; p.path.js)
}
// Main
function run() {
const chosenSections = [
Expand All @@ -951,21 +970,19 @@ function run() {
}]})
// Grab manuals
const allManuals = manuals(chosenSections).slice(0, -1).split("\n")
const uniqueManuals = [...new Set(allManuals)] // Remove duplicate entries
const sfItems = uniqueManuals.map(manLine =&gt; {
const manName = manLine.match(/.*\(\d\)\s+- /)[0].replace(/\s+- $/, '')
const manDesc = manLine.match(/\(\d\)\s+- .*/)[0].replace(/^\(\d\)\s+- /, '')
const mainMan = manName.split(/\(\d\)/)[0]
const section = manName.match(/\(\d\)/)[0].match(/\d/)[0]
const manualFiles = runCommand("/usr/bin/manpath")
.trim().split(":")
.flatMap(dir =&gt; dirContents(dir))
.filter(dir =&gt; chosenSections.includes(dir.slice(-1)))
.flatMap(dir =&gt; dirContents(dir))
.filter(file =&gt; file.match(/\.\d$/))
const sfItems = manualFiles.map(manFile =&gt; {
return {
variables: { section_number: section },
uid: manName,
title: manName,
subtitle: manDesc,
arg: mainMan
uid: manFile,
title: $(manFile).lastPathComponent.js.slice(0, -2),
subtitle: manFile,
arg: manFile
}
})
Expand Down

0 comments on commit 3b90094

Please sign in to comment.