Skip to content

Commit

Permalink
Merge pull request #2 from ticky/shell-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ticky authored Aug 4, 2023
2 parents b277828 + 6baa8ab commit 01a55bb
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 7 deletions.
159 changes: 154 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ clap = { version = "4.0", features = ["derive"] }
ecoji = "1.0.0"
itertools = "0.10.5"

[target.'cfg(unix)'.dependencies]
sysinfo = "0.13.1"
which = { version = "3.1.1", default-features = false }

[dev-dependencies]
indoc = "2.0.3"

Expand Down
24 changes: 24 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,27 @@ md5sum [file] | coloursum
```

Coloursum also prints full usage information if you run `coloursum --help`.

### Shell Integration

You can also integrate coloursum into your shell, to output colourful checksums by default!

By default, it will search for known checksum commands' presence, and generate shell functions for those which are found.

If this behaviour is not acceptable, or your checksum command is not in the list, you can optionally specify a checksum command as the last argument to `coloursum shell-setup` to generate a shell function just for it.

#### bash, zsh, and other similar shells

Add this line to your ~/.bash_profile, ~/.zshrc or equivalent file:

```sh
eval "$(coloursum --mode=1password shell-setup)"
```

#### fish shell

Add this line to ~/.config/fish/config.fish:

```fish
status --is-interactive; and coloursum --mode=ecoji shell-setup | source
```
10 changes: 10 additions & 0 deletions src/ansi_coloured_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ impl Line for ANSIColouredLine {

#[cfg(test)]
mod tests {
#[test]
fn display_works() {
use super::ANSIColouredLine;

assert_eq!(
format!("{}", ANSIColouredLine::from("MD5 (./src/main.rs) = b7527e0e28c09f6f62dd2d4197d5d225".to_string())),
"MD5 (./src/main.rs) = \u{1b}[38;5;183mb7\u{1b}[0m\u{1b}[38;5;82m52\u{1b}[0m\u{1b}[38;5;126m7e\u{1b}[0m\u{1b}[38;5;14m0e\u{1b}[0m\u{1b}[38;5;40m28\u{1b}[0m\u{1b}[38;5;192mc0\u{1b}[0m\u{1b}[38;5;159m9f\u{1b}[0m\u{1b}[38;5;111m6f\u{1b}[0m\u{1b}[38;5;98m62\u{1b}[0m\u{1b}[38;5;221mdd\u{1b}[0m\u{1b}[38;5;45m2d\u{1b}[0m\u{1b}[38;5;65m41\u{1b}[0m\u{1b}[38;5;151m97\u{1b}[0m\u{1b}[38;5;213md5\u{1b}[0m\u{1b}[38;5;210md2\u{1b}[0m\u{1b}[38;5;37m25\u{1b}[0m"
)
}

#[test]
fn format_hash_works() {
use super::ANSIColouredLine;
Expand Down
12 changes: 12 additions & 0 deletions src/base_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ fn find_sum_prefixed_line(line: &str) -> Option<usize> {

#[cfg(test)]
mod tests {
#[test]
fn from_string_works() {
use super::FormattableLine;

let string = "MD5 (./src/main.rs) = b7527e0e28c09f6f62dd2d4197d5d225".to_string();
let line = FormattableLine::from(string.clone());

assert_eq!(line.contents, string);
assert_eq!(line.formattable_start, Some(22));
assert_eq!(line.formattable_end, None);
}

#[test]
fn find_bsd_tag_line_works() {
use super::find_bsd_tag_line;
Expand Down
15 changes: 15 additions & 0 deletions src/ecoji_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ impl Line for EcojiLine {

#[cfg(test)]
mod tests {
#[test]
fn display_works() {
use super::EcojiLine;

assert_eq!(
format!(
"{}",
EcojiLine::from(
"MD5 (./src/main.rs) = b7527e0e28c09f6f62dd2d4197d5d225".to_string()
)
),
"MD5 (./src/main.rs) = ๐Ÿ˜จ๐Ÿธ๐Ÿคฐ๐Ÿ“บ๐Ÿ™Ž๐Ÿ“‡๐ŸฆŽ๐Ÿ˜จ๐Ÿฝ๐Ÿ‡ฎ๐Ÿ“†๐Ÿ’ฃ๐Ÿœโ˜•โ˜•โ˜•"
)
}

#[test]
fn format_hash_works() {
use super::EcojiLine;
Expand Down
Loading

0 comments on commit 01a55bb

Please sign in to comment.