diff options
Diffstat (limited to 'source/comp')
-rw-r--r-- | source/comp/git.d | 28 | ||||
-rw-r--r-- | source/comp/hr.d | 2 | ||||
-rw-r--r-- | source/comp/path.d | 33 |
3 files changed, 62 insertions, 1 deletions
diff --git a/source/comp/git.d b/source/comp/git.d new file mode 100644 index 0000000..4f68e95 --- /dev/null +++ b/source/comp/git.d @@ -0,0 +1,28 @@ +module comp.git; + +import std.stdio; +import std.file : dirEntries, SpanMode; +import std.process; +import std.string : strip; + +string gitBranch() { + auto result = execute(["git", "rev-parse", "--abbrev-ref", "HEAD"]); + + if (result.status != 0) + return null; + + return result.output.strip(); +} + +string gitStatus() { + auto result = execute(["git", "status", "--porcelain"]); + + if (result.status != 0) + return null; + + if (result.output.length >= 1) { + return "*"; + } + + return ""; +} diff --git a/source/comp/hr.d b/source/comp/hr.d index fa4d32b..76f7098 100644 --- a/source/comp/hr.d +++ b/source/comp/hr.d @@ -4,7 +4,7 @@ string hr(int col) { string ps; foreach (i; 0 .. col) { - ps ~= '—'; + ps ~= '─'; } return ps; diff --git a/source/comp/path.d b/source/comp/path.d new file mode 100644 index 0000000..b8f9914 --- /dev/null +++ b/source/comp/path.d @@ -0,0 +1,33 @@ +module comp.path; + +import std.conv; +import std.regex; +import std.array; + +import std.file : getcwd; +import std.path : expandTilde; +import std.algorithm : reverse; + +string path(int pathlen) { + string ps; + + string home = expandTilde("~"); + string path = replaceFirst(getcwd(), regex(home), "~"); + + string[] splitPath = path.split("/").reverse(); + + string[] revSplitPath; + for (int i = 0; i < pathlen; i++) { + if (i >= splitPath.length) + break; + + revSplitPath ~= splitPath[i]; + } + + splitPath = revSplitPath.reverse(); + + ps ~= splitPath.join("/"); + + return ps ~ "/"; + +} |