Latest articles

gen-package-version v0.9.0: New tool: Auto-generate version/timestamp info

Automatically generate a D module with version and timestamp information (detected from git) every time your program or library is built.

Even better, all your in-between builds will automatically have their own git-generated version number, including the git commit hash (for example: v1.2.0-1-g78f5cf9). So there's never any confusion as to which "version" of v1.2.0 you're running!

The gen-package-version Homepage

Full usage and instructions are at the link above, but here's a brief primer for those using it with dub:

To use:

Add this to your project's dub.json file:

"dependencies": { "gen-package-version": "~>0.9.0" }, "preGenerateCommands": ["dub run gen-package-version -- --src=path/to/src"]

Now, when you build your project with dub, it'll automatically download, install and run gen-package-version, which will generate the file path/to/src/package/name/packageVersion.d

Then just import that and use it:

module; import std.stdio; import; void main() { writeln("My Cool Program ", packageVersion); writeln("Built on ", packageTimestamp); }

Read more

Scriptlike v0.8.0

A bunch of new updates to Scriptlike: A library to aid in writing script-like programs in D.

Scriptlike links: [Home] [Dub] [Full changelog]

Highlights (more info at full changelog):

  • Change: Minimum officially supported DMD increased from v2.064.2 to v2.066.0.
  • Change: API reference now built using ddox and uses much improved styling (actually uses a stylesheet now).
  • Change: Misc changes to reduce symbol conflict issues with std.file/std.path.
  • Change: Eliminate remnants of the "planned but never enabled" wstring/dstring versions of Path/Ext/Args. There turned out not to be much need for them.
  • Enhancement: Add module scriptlike.only to import all of scriptlike, but omit the helper Phobos imports in scriptlike.std.
  • Enhancement: fail now accepts an arbitrary list of args
  • Enhancement: Added failEnforce.
  • Enhancement: Added runCollect and tryRunCollect, to capture a command's output instead of displaying it.
  • Enhancement: Added pause to pause and prompt the user to press Enter.
  • Enhancement: Added Path-based wrappers for std.file's getcwd, thisExePath and tempDir.
  • Fixed: No longer uses the deprecated std.process.system().

Read more

Ahh, Irony

You'd think a sudden stop to the flood of spam in the comment moderation queue would be a nice relief. Instead, I find it makes me paranoid that "The comment system didn't just suddenly break, did it?!?".

Go figure.

Oh well, I'm sure the spam traffic will pick back up again!

Read more

Bash: Multiline Eval

Maybe this is obvious to all the linux and bash-fu experts out there, but I just discovered it, thought it was pretty cool and worth sharing for anyone else who isn't quite a bash expert.


Ok, so bash has a feature which takes the output of a command and runs it (no, this isn't the part that's new to me ;), I'll get to that part in a bit). Let's use the print working directory command as an example:

$ cd ~ $ pwd /home/my-user-name

Now let's get a command that just simply outputs the command we want:

$ echo pwd pwd

And then bash's basic feature to execute that result (two different ways to do it):

$ `echo pwd` /home/my-user-name $ eval $(echo pwd) /home/my-user-name

Alright, neat, but basic stuff.

The Problem

Unfortunately, that trick only works when you're evaluating a single line. Try to evaluate multiple lines and it won't work. (The newlines get converted to spaces and it all gets interpreted as one command.)

To demonstrate, let's make a basic script:

$ touch display-a-command $ my-favorite-editor display-a-command

Copy-paste, save and exit:

#!/bin/bash echo pwd echo pwd


$ chmod +x display-a-command $ ./display-a-command pwd pwd

Ok. So we have a basic command that outputs two lines of commands. Try to evaluate (You get the same result using either eval method):

$ `./display-a-command` /home/my-user-name

Fucknuggets. It only ran "pwd" once. The two lines got mashed together into one line and bash really executed the single command pwd pwd. The second "pwd" was ignored as an unused argument to the first "pwd". That's not at all what we wanted.

The Cool Part

Turns out there's an easy way to do a multi-line eval:

$ eval "`./display-a-command`" /home/my-user-name /home/my-user-name

Yup. That's it. The internal `./display-a-command` evaluates to our two-line command, and the double-quotes ensure the newline gets preserved when passed to eval.

It even works when display-a-command's output includes backticks and quotes:

$ cat display-a-command2 #!/bin/bash echo \`echo pwd\` echo eval \"pwd\" $ chmod +x display-a-command2 $ ./display-a-command2 `echo pwd` eval "pwd" $ eval "`./display-a-command2`" /home/my-user-name /home/my-user-name

Nice. Cool, huh? At least I think it is, anyway.

Read more

Tagged Scriptlike release: v0.7.0

Scriptlike is a utility library to aid in writing script-like programs in D (available through DUB):

Two things in this release:

  • Easy input-prompting module "scriptlike.interact", by Jesse Phillips. This has actually been in master for quite some time, but now it's part of a tagged release.
  • Fixed: The unittests failed to compile on DMD 2.067.0

Early heads-up warning: While scriptlike currently supports DMDs as early as 2.064.2, I will likely be increasing the minimum supported DMD up to 2.066.0 between now and the next release, due to increasing reliance on the newer parts of std.process (which prior to 2.066.0 had "paths with spaces" problems on Windows, which I was previously able to work around using the outdated system() function).

Read more

Windows Equivalent of sudo

Yea, yea, I know what day today is. And NO, this post isn't some idiotic prank (or any prank at all, for that matter). Irritating psuedo-holiday...

I'd been a Windows guy most of my life, but lately (for various reasons) I've gravitated more to Linux. (Not that I consider any OSes to be all that fantastic). One thing that's quite handy in Linux is the "Don't give me this 'access' shit, I bought and own your circuit board ass, so fucking do what I tell you to" command: sudo.

Last few versions of Windows have started getting uppity about access privileges, so I've occasionally run into a similar need. For example, logging in as an Administrator, firing up an Administrator-priveledge command line, and still getting "access denied" shit from one CLI tool or another regarding files and paths I know damn well I have full access to.

As can probably be expected, the Windows equivalent is all goofy, verbose and awkward (and launches the provided command in a separate auto-closing windows, gee thanks), but at least it's there:

runas /profile /user:YourUserName "C:\Full\Path\To\Program.exe Your Args Here"

Make sure to properly escape anything in those double-quotes (whee...I miss sudo already...). And...oh yea, your PATH won't work here, so you need to know the full path to your program. Luckily, there's an equivalent to "which". Side note: I don't know why that's calling it "where.bat", it behaves more like Linux "which" (shows the path to the one program that would actually get run) than the built-in Windows "where" (shows all programs on the PATH with the given name).

REM This is 'which.bat' @setlocal @set P2=.;%PATH% @for %%e in (%PATHEXT%) do @for %%i in (%~n1%%e) do @if NOT "%%~$P2:i"=="" echo %%~$P2:i

Toss that into a "which.bat", save to your windows directory (yea, not real clean, but hey, it's Windows, I don't give a crap), and get your work done:

> doshit now Fuck off, access denied > sudo doshit now I'm Windows, I don't understand that > which doshit C:\Some\Big\Path\doshit.bat > runas /profile /user:MyUserName "C:\Some\Big\Path\doshit.bat now" Oh, snap!

Read more