How to run shell commands and capture there output into a UML diagram - plantuml

I have a footer that generates info about the diagram, like the date and user who created the image. I would like to include the git SHA. I need some sort of built-in function, probably a preprocessor function, that lets me envoke system commands. I'm thinking something like the %date() command, only where I pass in the command and arguments I want to be executed and I get back the text from it being run in the shell. Something like
%sys_call("git rev-parse --short=10 HEAD")

There are different ways you could achieve this but it would require a bit of scripting:
Solution 1/:
Pass the git sha through an environment variable and use
%getenv function to retrieve it from the plantuml file
see here: https://plantuml.com/en/preprocessing#291cabbe982ff775
Solution 2/:
Have a script that write the sha in a text file and include this file from your plantuml file:
https://plantuml.com/en/preprocessing#393335a6fd28a804

Related

Run with stdin in CLion

I would like to ask if there is any possibility to run code with custom parameters in CLion. And where to put the file.txt in project folder.
Something equivalent to ./program <file.txt
It seems as if redirection of stdin for the program to be run or debugged is still not implemented. See the issue "Add an option to specify default input and output streams for console applications" at JetBrain's bugtracker.
Other IDEs like Eclipse can do this.
In CLion, go to your Run/Debug Configurations. There's a field named Program arguments. This field allows you to set "a custom parameter":
You can find the corresponding documentation here.
An excerpt from the documentation to help finding the correct dialog:
With the Navigation bar visible (View | Appearance | Navigation Bar), the available run/debug configurations are displayed in the run/debug configuration selector in the Run area:
Note that this of course only works for executable targets (or non executable targets that have an executable set).
Also note that this will most likely not allow you to do any shell redirection. Setting the field to < myfile.txt will not have the effects you are looking for. It will literally copy the strings < and myfile.txt as input arguments 1 and 2 (0 being the binary name).
If you want to pass file contents in this manner you'll have to just pass the file path using this method and then open & load the file in your application.
This is now possible.
In the Run/Debug Configuration, you’ll find a new field called
Redirect input from. Enable it, and fill in the file path/name:
Source: https://blog.jetbrains.com/clion/2020/03/clion-2020-1-eap-input-redirection-config-macros/#input_redirection

How to get the diff of a single file with libgit2?

Is there a function equivalent to git diff FILE in libgit2? In other words, how to efficiently retrieve the diff of a single file without having libgit2 to look at other files in the working directory?
git diff FILE will display the changes you've made relative to the index.
This can be achieved through the use of the libgit2 git_diff_index_to_workdir() function.
This function accepts a git_diff_options structure as a parameter into which you can provide a pathspec, or a list of pathspecs, you're specifically interested in.
More information about this:
Documentation of this function.
Unit test leveraging this use case.

Shell Script to typeset Lilypond files with Textwrangler

I need a shell script which will allow me to typeset Lilypond files from TextWrangler (A Mac App).
So far I have come up with this:
#!/bin/sh
/Applications/LilyPond.app/Contents/Resources/bin/lilypond -o $1
which, of course, doesn't work. (That's why I'm at Stack Overflow.)
When I run that script from the shebang menu in TextWrangler, I get this output:
/Applications/LilyPond.app/Contents/Resources/bin/lilypond: option faultpaper,
--output'' requires an argument
What gives?
I'm running Snow Leopard, TextWrangler, and Lilypond.
Help appreciated.
EDIT: Found a way to get the document path in a Unix Script launched by TextWrangler, so I've rewritten this.
There are multiple ways to work with scripts in TextWrangler through the #! menu, and I'm not sure which one you're trying to use. It looks, though, like you're trying to create a Unix Script to convert your LilyPond document.
As your error hints, Unix Scripts unfortunately aren't given any arguments at all, so $1 will be empty. However, it turns out that recent versions of BBEdit/TextWrangler do set some environment variables before running your script (see BBEdit 9.3 Release Notes and scroll down to Changes). In particular, you can use the following environment variable:
BB_DOC_PATH path of the document (not set if doc is unsaved)
So, save this script to ~/Library/Application Support/TextWrangler/Unix Support/Unix Scripts and you should be good to go.
Other ways you might be trying to do this that don't work well:
Using a Unix Filter: to do this you would have to select all of your LilyPond code in the document, and it would be saved into a temporary file, which is passed as an argument to your script. OK, so that gets you an input filename, at the cost of some hassle. But then the output of that script (i.e. the LiiyPond compiler output) by default replaces whatever you just selected, which is probably not what you want. Wrong tool for the job.
Using #! → Run on a LilyPond file: This involves putting a #! line at the top of your file and having TextWrangler attempt to execute your file as a script, using the #! as a guide to selecting the script interpreter. Unfortunately, the #! line only works with certain scripting languages, and LilyPond (not quite a scripting language) isn't one of them. This is what Peter Hilton is trying to do, and as he notes, you will get LilyPond syntax errors if you try to add a #! line to the top of a LilyPond file. (If you're curious, there is technically a way to get #! → Run to work, which is to embed your LilyPond code inside an executable shell or perl script, using here-document syntax. But this is a gross hack that will quickly become unwieldly.)
There are a few limitations to the script linked above:
It doesn't check to see whether you saved your document before running LilyPond. It would be nice to have TextWrangler automatically save before running LilyPond.
It can't take snippets of text or unsaved documents as input, only saved documents.
You can make more sophisticated solutions that would address these by turning to AppleScript. Two ways of doing this:
Create a script that's specific to TextWrangler and drop it in ~/Library/Application Support/TextWrangler/Scripts. It then shows up in the AppleScript menu (the weird scrolly S), or you can get at it by bringing up Window → Palettes → Scripts. I believe two folks out there have gone down this path and shared their results:
Henk van Voorthuijsen (Lilypond.applescript extracted from MacOS 10.5 Applescript for TextWrangler thread on lilypond-devel, 21-Jul-2008)
Dr Nicola Vitacolonna (LilyPond in TextWrangler – uses TeXShop).
Create a Mac OS Service, which would potentially be a method that would be reusable across just about any text editor. This was how we used to compile Common Music files way back in the NeXT days, so I can testify to its elegance. I don't have a good up-to-date example of this, unfortunately.
Good question. It actually runs Lilypond on my system if you do this:
#!/Applications/LilyPond.app/Contents/Resources/bin/lilypond -o $1
… but fails because # is not a line-comment character so Lilypond tries to parse the line.
Surrounding it with a block comment fails because TextWrangler cannot find the ‘shebang’ line.
%{
#!/Applications/LilyPond.app/Contents/Resources/bin/lilypond -o $1
%}
An alternative is to use Smultron 3, which lets you define commands that you can run with a keyboard shortcut.

How to execute Vim commands in a file, like .vimrc?

I need to create a file with a list of commands (in particular key mappings) that I may sometimes need, like a .vimrc that I can execute inside Vim when I need them.
Try :source file

Easiest way to have a true "file tasks" in ANT

I am still learning how to use ANT well, and I wanted to understand if there is some reasonable way to do file tasks in it, similar to Rake and Make:
http://martinfowler.com/articles/rake.html#FileTasks
"With a file you are referring to actual files rather than task names. So 'build/dev/rake.html' and 'dev/rake.xml' are actual files. The html file is the output of this task and the xml file is the input. You can think of a file task as telling the build system how to make the output file - indeed this is exactly the notion in make - you list the output files you want and tell make how to make them.
An important part of the file task is that it's not run unless you need to run it. The build system looks at the files and only runs the task if the output file does not exist or it's modification date is earlier than the input file. File tasks therefore work extremely well when you're thinking of things at a file by file basis."
So in other words, let's say I want to run a custom binary and I only want that binary to run if any of the files have changed. This is related to this question, but I don't want to run the binary at all, not only pass a part of the fileset (i.e. there is only one in the fileset and I don't want the tool to run at all).
The ideal solution would also not be a loooong thing, but rather could be easily applied to any target -- perhaps using some ANT JavaScript or custom task?
Use ant-contrib outofdate task. It has exactly the properties you are asking for. Here is ant-contrib website.
Here is a template on how to integrate it into your build:
<taskdef
resource="net/sf/antcontrib/antlib.xml"
>
<classpath>
<pathelement location="${ant-contrib.jar}"/>
</taskdef>
<outofdate>
<sourcefiles path="dev/rake.xml"/>
<targetfiles path="build/dev/rake.html"/>
<sequential>
... do your work here ...
... will only run if rake.html is older than rake.xml ...
</sequential>
</outofdate>

Resources