Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmartinfr committed May 18, 2020
0 parents commit 34cf224
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
.DS_Store
composer.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Till Krüss

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Pest PHP Docs Workflow for Alfred

An ultra-fast Pest PHP docs search workflow for [Alfred](https://www.alfredapp.com).

![Screenshot](screenshot.png)

## Installation

1. [Download the latest version](https://github.com/AlexMartinFR/alfred-pestphp-docs/releases/download/v0.1.0/pestphp-docs.alfredworkflow)
2. Install the workflow by double-clicking the `.alfredworkflow` file
3. You can add the workflow to a category, then click "Import" to finish importing. You'll now see the workflow listed in the left sidebar of your Workflows preferences pane.

## Usage

Just type `pest` followed by your search query:

```
pest <query>
pest test
```

Either press `⌘Y` to Quick Look the result, or press `<enter>` to open it in your web browser.

## Credits

This workflow is based on Till Kruss' [Laravel Docs workflow](https://github.com/tillkruss/alfred-laravel-docs).
Binary file added google.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 added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 156 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bundleid</key>
<string>com.alexmartinfr.alfred-pestphp-doc</string>
<key>category</key>
<string>Productivity</string>
<key>connections</key>
<dict>
<key>5F3B3AF3-9709-4EE5-8742-31952977E46C</key>
<array>
<dict>
<key>destinationuid</key>
<string>3A309868-3B85-42B4-AA2F-26EB0FB9F4BE</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
</dict>
<key>createdby</key>
<string>Alex Martin</string>
<key>description</key>
<string>An ultra-fast Pest PHP docs search workflow</string>
<key>disabled</key>
<false/>
<key>name</key>
<string>Pest PHP Docs</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>spaces</key>
<string></string>
<key>url</key>
<string>{query}</string>
<key>utf8</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>3A309868-3B85-42B4-AA2F-26EB0FB9F4BE</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>4</integer>
<key>keyword</key>
<string>pest</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Searching docs for "{query}"...</string>
<key>script</key>
<string>php pest.php "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Search the Pest PHP docs...</string>
<key>title</key>
<string>Pest Docs</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>5F3B3AF3-9709-4EE5-8742-31952977E46C</string>
<key>version</key>
<integer>3</integer>
</dict>
</array>
<key>readme</key>
<string># Pest PHP Docs Workflow for Alfred
An ultra-fast Pest PHP docs search workflow for Alfred.
## Installation
1. Download the latest version: https://github.com/AlexMartinFR/alfred-pestphp-docs/releases/download/v0.1.0/pestphp-docs.alfredworkflow
2. Install the workflow by double-clicking the `.alfredworkflow` file
3. Click "Import" to finish importing. You'll now see the workflow listed in the left sidebar of your Workflows preferences pane.
## Usage
Just type `pest` followed by your search query:
```
pest &lt;query&gt;
pest test
```
Either press `⌘Y` to Quick Look the result, or press `&lt;enter&gt;` to open it in your web browser.
## Credits
This workflow is based on Till Kruss' Laravel Docs workflow:
https://github.com/tillkruss/alfred-laravel-docs</string>
<key>uidata</key>
<dict>
<key>3A309868-3B85-42B4-AA2F-26EB0FB9F4BE</key>
<dict>
<key>xpos</key>
<integer>545</integer>
<key>ypos</key>
<integer>145</integer>
</dict>
<key>5F3B3AF3-9709-4EE5-8742-31952977E46C</key>
<dict>
<key>xpos</key>
<integer>235</integer>
<key>ypos</key>
<integer>145</integer>
</dict>
</dict>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>0.1.0</string>
<key>webaddress</key>
<string>https://github.com/AlexMartinFR/alfred-pestphp-docs</string>
</dict>
</plist>
70 changes: 70 additions & 0 deletions pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

use Alfred\Workflows\Workflow;

use AlgoliaSearch\Client as Algolia;
use AlgoliaSearch\Version as AlgoliaUserAgent;

require __DIR__ . '/vendor/autoload.php';

$query = $argv[1];
$subtext = empty($_ENV['alfred_theme_subtext']) ? '0' : $_ENV['alfred_theme_subtext'];

$workflow = new Workflow;
$parsedown = new Parsedown;
$algolia = new Algolia('BH4D9OD16A', 'd25b0b281fd72e7b8ce770857fff45bf'); // Pest PHP
AlgoliaUserAgent::addSuffixUserAgentSegment('Pest PHP Docs Alfred Workflow', '0.1.0');
$index = $algolia->initIndex('pestphp');
$search = $index->search($query);
$results = $search['hits'];

$subtextSupported = $subtext === '0' || $subtext === '2';

if (empty($results)) {
$google = sprintf('https://www.google.com/search?q=%s', rawurlencode("pestphp {$query}"));

$workflow->result()
->title($subtextSupported ? 'Search Google' : 'No match found. Search Google...')
->icon('google.png')
->subtitle(sprintf('No match found. Search Google for: "%s"', $query))
->arg($google)
->quicklookurl($google)
->valid(true);

$workflow->result()
->title($subtextSupported ? 'Open Docs' : 'No match found. Open docs...')
->icon('icon.png')
->subtitle('No match found. Open https://pestphp.com/docs/installation/...')
->arg('https://pestphp.com/docs/installation/')
->quicklookurl('https://pestphp.com/docs/installation/')
->valid(true);

echo $workflow->output();
exit;
}

$urls = [];

foreach ($results as $hit) {

$highestLvl = $hit['hierarchy']['lvl6'] ? 6 : ($hit['hierarchy']['lvl5'] ? 5 : ($hit['hierarchy']['lvl4'] ? 4 : ($hit['hierarchy']['lvl3'] ? 3 : ($hit['hierarchy']['lvl2'] ? 2 : ($hit['hierarchy']['lvl1'] ? 1 : 0)))));

$title = $hit['hierarchy']['lvl' . $highestLvl];
$currentLvl = 0;
$subtitle = $hit['hierarchy']['lvl0'];
while ($currentLvl < $highestLvl) {
$currentLvl = $currentLvl + 1;
$subtitle = $subtitle . ' » ' . $hit['hierarchy']['lvl' . $currentLvl];
}

$workflow->result()
->uid($hit['objectID'])
->title($title)
->autocomplete($title)
->subtitle($subtitle)
->arg($hit['url'])
->quicklookurl($hit['url'])
->valid(true);
}

echo $workflow->output();
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 34cf224

Please # to comment.