Skip to content

Commit

Permalink
Refactoring and alias removal.
Browse files Browse the repository at this point in the history
- Refactor workflow and execute via External Script
- Usage instructions improved
- Enable built-ins to be disabled
- Allow custom aliases to be removed
  • Loading branch information
isometry committed Sep 9, 2017
1 parent 8b7bc15 commit bdbf4e8
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 203 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
._*
*.py[cod]
*~
pipe.alfredworkflow
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 Robin Breathe
Copyright (c) 2013-2017 Robin Breathe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
zip -j9 --filesync pipe.alfredworkflow *.{json,plist,png,py}
57 changes: 26 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,48 @@
# pipe workflow by isometry
# pipe transformation workflow for Alfred

A workflow for [Alfred](http://www.alfredapp.com/) to transform the currently selected text or the contents of the clipboard by passing it through an arbitrary shell one-liner.
An [Alfred](http://www.alfredapp.com/) workflow enabling easy transformation of the current contents of the clipboard by piping through arbitrary shell one-liners.

## Requirements

- [Alfred](http://www.alfredapp.com/) (version 2.0+)
- The [Alfred Powerpack](http://www.alfredapp.com/powerpack/).
- [pipe.alfredworkflow](https://raw.github.com/isometry/alfredworkflows/master/pipe.alfredworkflow)

## Usage

(Optional) assign hotkeys for the two Hotkey handlers in the workflow. I recommend `Cmd+Shift+|` and `Cmd+Ctrl+\`, respectively.
Trigger the workflow by hotkey or keyword (default=`|`, override with the `keyword` variable) followed by an arbitrarily simple or complex shell one-liner to transform the contents of the clipboard in-place; optionally use the `Cmd`-modifier to immediately paste the results into the foreground app.

Two actions are available, both taking an arbitrarily complex shell pipe as their argument:
### Examples

1. triggered by the first hotkey or by the `|` or `pipe` keywords, will transform the clipboard in-place by passing its contents through the pipe given as argument.
2. triggered by the second hotkey, will transform the currently selected text in-place by passing its contents through the pipe given as argument.
- Transform to UPPERCASE: `| perl -nle 'print uc'` or `| tr a-z A-Z`
- Base64 encode: `| base64`
- Base64 decode: `| base64 --decode`
- Top 10 unique lines with counts: `| sort | uniq -c | sort -rn | head -10`

A number of built-in pipelines are [included](https://raw.github.com/isometry/alfredworkflows/net.isometry.alfred.pipe/builtins.json), and custom aliases can also be defined with the following syntax:
### Built-ins

`| alias NAME=PIPE | LINE@@`
A number of example pipelines (including those above) are [built-in](https://github.com/isometry/alfred-pipe/raw/master/builtins.json).

`| alias tac=sed '1!G;h;$!d'@@`
Built-ins can be disabled en-mass by setting the `load_builtins` variable to any value other than `yes`.

## Contributions & Thanks
### Aliases

- ctwise
To save repetitive typing, custom aliases can be defined with the following syntax:

`| alias NAME=PIPE | LINE @@@`

The trailing `@@@` (override with the `alias_terminator` variable) terminates the alias definition and causes it to be saved.

## License
#### Examples

(The MIT License)
- `| alias tac=sed '1!G;h;$!d' @@@`
- `| alias top10=sort | uniq -c | sort -rn | head -10 @@@`

Copyright (c) 2013 Robin Breathe
#### Alias removal

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:
Any custom alias can be removed with:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
`| alias NAME=@@@`

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.
## Contributions & Thanks

- ctwise
4 changes: 2 additions & 2 deletions alfred.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def unescape(query, characters=None):

def work(volatile):
path = {
True: os.getenv('alfred_workflow_cache'),
False: os.getenv('alfred_workflow_data')
True: os.getenv('alfred_workflow_cache', os.getenv('TMPDIR', '/tmp')),
False: os.getenv('alfred_workflow_data', os.getenv('HOME', '/tmp'))
}[bool(volatile)]
return _create(os.path.expanduser(path))

Expand Down
4 changes: 2 additions & 2 deletions builtins.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"openssl base64 -d": "decode base64",
"openssl base64 -e": "encode base64",
"base64": "encode base64",
"base64 --decode": "decode base64",
"openssl enc -d -base64 -aes256 -k X": "AES-256 decrypt with passphrase 'X'",
"openssl enc -e -base64 -aes256 -k X": "AES-256 encrypt with passphrase 'X'",
"openssl x509 -noout -fingerprint": "x509 fingerprint",
Expand Down
Loading

0 comments on commit bdbf4e8

Please sign in to comment.