Skip to content

Commit 8f22ff5

Browse files
committed
Added project creation date
1 parent 0994a5c commit 8f22ff5

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) {
@@ -355,9 +355,13 @@ fn main() -> Result<()> {
355355
let commits = get_commits(&dir)?;
356356
let repo_size = get_packed_size(&dir)?;
357357
let last_change = get_last_change(&dir)?;
358+
let project_name = match get_creation_time() {
359+
Some(creation_time) => format!("{}, {}", config.repository_name, creation_time),
360+
None => config.repository_name
361+
};
358362

359363
let info = Info {
360-
project_name: config.repository_name,
364+
project_name,
361365
current_commit: current_commit_info,
362366
version,
363367
dominant_language,
@@ -513,7 +517,7 @@ fn get_packed_size(dir: &str) -> Result<String> {
513517
None => "??",
514518
Some(size_str) => &(size_str[11..])
515519
};
516-
520+
517521
let output = Command::new("git")
518522
.arg("-C")
519523
.arg(dir)
@@ -539,7 +543,7 @@ fn get_packed_size(dir: &str) -> Result<String> {
539543
else{
540544
let res =repo_size;
541545
Ok(res.into())
542-
}
546+
}
543547
}
544548

545549
fn is_git_installed() -> bool {
@@ -666,6 +670,23 @@ fn get_total_loc(languages: &tokei::Languages) -> usize {
666670
.fold(0, |sum, val| sum + val.code)
667671
}
668672

673+
fn get_creation_time() -> Option<String> {
674+
let output = Command::new("git")
675+
.arg("log")
676+
.arg("--reverse")
677+
.arg("--pretty=oneline")
678+
.arg("--format=\"%ar\"")
679+
.output()
680+
.expect("Failed to execute git.");
681+
682+
let output = String::from_utf8_lossy(&output.stdout);
683+
684+
match output.lines().next() {
685+
Some(val) => Some(val.to_string().replace('"', "")),
686+
None => None
687+
}
688+
}
689+
669690
/// Convert from tokei LanguageType to known Language type .
670691
impl From<tokei::LanguageType> for Language {
671692
fn from(language: tokei::LanguageType) -> Self {

0 commit comments

Comments
 (0)