Skip to content

Commit 7b31ed5

Browse files
authored
Merge pull request #61 from bojan88/project_creation_date
Project creation date
2 parents 6a73ae1 + 8f22ff5 commit 7b31ed5

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/main.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ fn count_newlines(s: &str) -> usize {
182182
/// escape characters for color display.
183183
///
184184
/// Colors are specified with {0}, {1}... where the number represents
185-
/// the nth element in the colors Vec provided to the function.
185+
/// the nth element in the colors Vec provided to the function.
186186
/// If there are more colors in the ascii than in the Vec it
187-
/// defaults to white.
187+
/// defaults to white.
188188
/// The usize in the tuple refers to the extra padding needed
189189
/// which comes from the added escape characters.
190190
fn colorize_str(line: &str, colors: Vec<Color>) -> (String, usize) {
@@ -363,9 +363,13 @@ fn main() -> Result<()> {
363363
let commits = get_commits(&dir)?;
364364
let repo_size = get_packed_size(&dir)?;
365365
let last_change = get_last_change(&dir)?;
366+
let project_name = match get_creation_time() {
367+
Some(creation_time) => format!("{}, {}", config.repository_name, creation_time),
368+
None => config.repository_name
369+
};
366370

367371
let info = Info {
368-
project_name: config.repository_name,
372+
project_name,
369373
current_commit: current_commit_info,
370374
version,
371375
dominant_language,
@@ -521,7 +525,7 @@ fn get_packed_size(dir: &str) -> Result<String> {
521525
None => "??",
522526
Some(size_str) => &(size_str[11..])
523527
};
524-
528+
525529
let output = Command::new("git")
526530
.arg("-C")
527531
.arg(dir)
@@ -547,7 +551,7 @@ fn get_packed_size(dir: &str) -> Result<String> {
547551
else{
548552
let res =repo_size;
549553
Ok(res.into())
550-
}
554+
}
551555
}
552556

553557
fn is_git_installed() -> bool {
@@ -674,6 +678,23 @@ fn get_total_loc(languages: &tokei::Languages) -> usize {
674678
.fold(0, |sum, val| sum + val.code)
675679
}
676680

681+
fn get_creation_time() -> Option<String> {
682+
let output = Command::new("git")
683+
.arg("log")
684+
.arg("--reverse")
685+
.arg("--pretty=oneline")
686+
.arg("--format=\"%ar\"")
687+
.output()
688+
.expect("Failed to execute git.");
689+
690+
let output = String::from_utf8_lossy(&output.stdout);
691+
692+
match output.lines().next() {
693+
Some(val) => Some(val.to_string().replace('"', "")),
694+
None => None
695+
}
696+
}
697+
677698
/// Convert from tokei LanguageType to known Language type .
678699
impl From<tokei::LanguageType> for Language {
679700
fn from(language: tokei::LanguageType) -> Self {

0 commit comments

Comments
 (0)