import std.stdio; import std.process; import std.string; import std.range; import std.algorithm; import std.typecons; import core.sys.posix.time; bool notNullOrEmpty(T)(T s) { return s != null || !s.empty; } bool notNull(T)(T s) { return s != null; } auto dict(alias kf, alias vf, T)(T items) { alias TK = typeof(kf(items.front)); alias TV = typeof(vf(items.front)); TV[TK] result; foreach (item; items) { result[kf(item)] = vf(item); } return result; } string[string][] getPacmanPackages() { struct Property { string key, value; } auto parseProperty(string line) { auto ix = line.indexOf(':'); if (ix == -1) return null; auto k = line[0..ix].strip; auto v = line[ix+1..$].strip; return new Property(k, v); } auto parsePackage(string lines) { return lines .splitter('\n') .map!parseProperty .filter!notNull .dict!(x => x.key, x => x.value); } return ["pacman", "-Qi"] .execute .output .splitter("\n\n") .filter!notNullOrEmpty .map!parsePackage .array; } auto fmtDateTime(string s) { tm time; strptime(s.ptr, "%a %d %b %Y %I:%M:%S %p %Z", &time); char buf[30]; auto len = strftime(buf.ptr, buf.length, "%Y-%m-%dT%H:%M:%S%Z", &time); auto fmt = buf[0..len].idup; return fmt; } void main() { auto pks = getPacmanPackages(); foreach (pk; pks) { writeln(pk["Install Date"].fmtDateTime, ' ', pk["Name"], ' ', pk["Version"]); } }