Jump to content

Workflow for formatting C/C++ files using astyle


Recommended Posts

I'm trying to write a workflow, which would clean a C/C++ file, via astyle command line program, using clipboard copy and paste. 

 

It has to be the simplest workflow, yet I cannot make it preserve new lines.

 

What is the best way to output something into stdin and read from there?

 

So far I'm trying this in a bash script (with argv) but it removes all the new lines characters:

 

echo -n $1 | /usr/local/bin/astyle

https://www.dropbox.com/s/bkffs7j6nchwbog/astyle clean.alfredworkflow?dl=0

Edited by hyperknot
Link to comment

Oh, you’re using Run Script. I don’t know what Alfred does with the input to that, or if it alters the clipboard data.

 

In any case, you could ignore Alfred’s clipboard support and replace your “echo” with “pbpaste”:

 

pbpaste -Prefer txt | /usr/local/bin/astyle

 

The -Prefer flag tells pbpaste to emit plaintext (there may be a richtext version on the clipboard, too).

Link to comment

With pbpaste it work perfectly.

I tried rewriting it to a script filter, but I couldn't even launch it with a keyword, when I pressed Return it just disappeared and offered me to google my keyword instead. Probably a totally newbie setting somewhere, but at the end I went back to run script.

Link to comment
59 minutes ago, hyperknot said:

I tried rewriting it to a script filter

 

Script Filters are for showing items in Alfred. If your Script Filter doesn't print XML/JSON in the format understood by Alfred (or if it crashes), Alfred shows its Fallback Searches.

 

You don't want a Script Filter. (I couldn't download your workflow, as I was replying from my phone earlier.)

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