Simplify System.cmd with W sigil
Say we have the following shell command to get the the unix timestamp of the last commit:
$ git log -1 --date=short --pretty=format:%ct
1470067380
In elixir. One might do it like so:
System.cmd("git", ["log", "-1", "--date=short", "--pretty=format:%ct])
|> elem(0)
#=> "1470067380"
And here is just a simpler syntax for the same thing:
System.cmd("git", ~w[log -1 --date=short --pretty=format:%ct])
|> elem(0)
#=> "1470067380"
This is just a little clean and feels more like the original command.
Tweet