Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target

.DS_Store
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ then jump to `demo` with:
gg demo
```

### Show Git Tags

List git tags in chronological order. By default, it shows the latest 10 tags.

```bash
in tags
```

Example output:
```
Showing the last 10 of 12 tags (from 2025-07-31 to 2025-07-31). Use --all to see all.

2025-07-31 v0.1.03 Test tag 3
2025-07-31 v0.1.04 Test tag 4
2025-07-31 v0.1.05 Test tag 5
2025-07-31 v0.1.06 Test tag 6
2025-07-31 v0.1.07 Test tag 7
2025-07-31 v0.1.08 Test tag 8
2025-07-31 v0.1.09 Test tag 9
2025-07-31 v0.1.10 Test tag 10
2025-07-31 v0.1.11 Test tag 11
2025-07-31 v0.1.12 Test tag 12
```

To view all tags, use the `--all` flag.

```bash
in tags --all
```

### License

MIT
10 changes: 10 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum InspectionCommand {
ListFileSize(InspectForFileSize),
DirMark(InspectForDirMark),
FinishBranch(InspectForFinishBranch),
ShowTags(InspectForTags),
}

/// command for inspecting IP addresses.
Expand All @@ -29,6 +30,15 @@ pub struct InspectForIp {
pub detailed: bool,
}

/// command for showing tags.
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "tags")]
pub struct InspectForTags {
/// show all tags
#[argh(switch, long = "all")]
pub all: bool,
}

/// command for copying files.
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "cpfile")]
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
mod dir_marks;
mod git;
mod show_file_size;
mod tags;

use sysinfo::System;

Expand All @@ -21,12 +22,12 @@
let network_interfaces = list_afinet_netifas().unwrap();

for (name, ip) in network_interfaces.iter() {
println!("{}:\t{:?}", name, ip);

Check warning on line 25 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/main.rs:25:11 | 25 | println!("{}:\t{:?}", name, ip); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 25 - println!("{}:\t{:?}", name, ip); 25 + println!("{name}:\t{ip:?}"); |
}
} else {
let my_local_ip = local_ip().unwrap();
cli_clipboard::set_contents(my_local_ip.to_string()).expect("write to clipboard");
println!("{}\t\t(copied to clipboard)", my_local_ip);

Check warning on line 30 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/main.rs:30:9 | 30 | println!("{}\t\t(copied to clipboard)", my_local_ip); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 30 - println!("{}\t\t(copied to clipboard)", my_local_ip); 30 + println!("{my_local_ip}\t\t(copied to clipboard)"); |
}
}
CopyFile(options) => {
Expand Down Expand Up @@ -61,10 +62,10 @@
for (pid, process) in sys.processes() {
println!("{}\t#{pid}", process.name().to_string_lossy());
if let Some(v) = process.cwd() {
print!("\t{:?}", v);

Check warning on line 65 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/main.rs:65:11 | 65 | print!("\t{:?}", v); | ^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 65 - print!("\t{:?}", v); 65 + print!("\t{v:?}"); |
}
if let Some(v) = process.user_id() {
print!("\t{:?}", v);

Check warning on line 68 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/main.rs:68:11 | 68 | print!("\t{:?}", v); | ^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 68 - print!("\t{:?}", v); 68 + print!("\t{v:?}"); |
}
println!();
// println!(" {}", process.cmd().join(" "));
Expand All @@ -78,7 +79,7 @@
};
let dir_str = dir.display().to_string();
cli_clipboard::set_contents(dir_str.to_owned()).expect("write to clipboard");
println!("{}\t\t(copied to clipboard)", dir_str);

Check warning on line 82 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/main.rs:82:7 | 82 | println!("{}\t\t(copied to clipboard)", dir_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 82 - println!("{}\t\t(copied to clipboard)", dir_str); 82 + println!("{dir_str}\t\t(copied to clipboard)"); |
}
ListFileSize(options) => {
show_file_size::show_file_size(options)?;
Expand Down Expand Up @@ -119,10 +120,16 @@
},
FinishBranch(_) => {
if let Err(e) = git::finish_branch() {
eprintln!("Error finishing branch: {}", e);

Check warning on line 123 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/main.rs:123:9 | 123 | eprintln!("Error finishing branch: {}", e); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 123 - eprintln!("Error finishing branch: {}", e); 123 + eprintln!("Error finishing branch: {e}"); |
std::process::exit(1);
}
}
ShowTags(options) => {
if let Err(e) = tags::show_tags(&options) {
eprintln!("Error showing tags: {}", e);

Check warning on line 129 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/main.rs:129:9 | 129 | eprintln!("Error showing tags: {}", e); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 129 - eprintln!("Error showing tags: {}", e); 129 + eprintln!("Error showing tags: {e}"); |
std::process::exit(1);
}
}
}

Ok(())
Expand Down
93 changes: 93 additions & 0 deletions src/tags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use crate::args::InspectForTags;
use std::process::Command;

#[derive(Clone)]
struct TagInfo {
date: String,
name: String,
subject: String,
}

pub fn show_tags(options: &InspectForTags) -> Result<(), String> {
let output = Command::new("git")
.args([
"for-each-ref",
"--sort=creatordate", // Sort by date ascending
"--format=%(creatordate:short)\t%(refname:short)\t%(subject)",
"refs/tags",
])
.output()
.map_err(|e| e.to_string())?;

if !output.status.success() {
return Err(String::from_utf8_lossy(&output.stderr).to_string());
}

let output_str = String::from_utf8_lossy(&output.stdout);
if output_str.is_empty() {
println!("No tags found.");
return Ok(());
}

let all_tags: Vec<TagInfo> = output_str
.lines()
.filter_map(|line| {
let parts: Vec<&str> = line.splitn(3, '\t').collect();
if parts.len() == 3 {
Some(TagInfo {
date: parts[0].to_string(),
name: parts[1].to_string(),
subject: parts[2].to_string(),
})
} else {
None
}
})
.collect();

let total_tags = all_tags.len();
let tags_to_display = if options.all {
all_tags.clone()
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary clone of the entire all_tags vector when options.all is true. Consider using a reference or moving the vector instead of cloning.

Suggested change
all_tags.clone()
all_tags

Copilot uses AI. Check for mistakes.
} else {
let tags: Vec<TagInfo> = all_tags.iter().rev().take(10).cloned().collect();
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 10 is hardcoded. Consider making this configurable or defining it as a named constant for better maintainability.

Suggested change
let tags: Vec<TagInfo> = all_tags.iter().rev().take(10).cloned().collect();
let tags: Vec<TagInfo> = all_tags.iter().rev().take(DEFAULT_TAGS_TO_DISPLAY).cloned().collect();

Copilot uses AI. Check for mistakes.
tags.into_iter().rev().collect()
};

if tags_to_display.is_empty() {
println!("No tags to display.");
return Ok(());
}

if !options.all && total_tags > tags_to_display.len() {
if let (Some(first_tag), Some(last_tag)) = (all_tags.first(), all_tags.last()) {
println!(
"Showing the last {} of {} tags (from {} to {}). Use --all to see all.",
tags_to_display.len(),
total_tags,
first_tag.date,
last_tag.date
);
println!(); // Add a blank line for separation
}
}


let mut max_tag_width = 0;
for tag in &tags_to_display {
if tag.name.len() > max_tag_width {
max_tag_width = tag.name.len();
}
}

for tag in tags_to_display {
println!(
"{} {:<width$} {}",
tag.date,
tag.name,
tag.subject,
width = max_tag_width
);
}

Ok(())
}
Loading