Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: quick stats #330

Open
nfultz opened this issue Feb 22, 2023 · 2 comments
Open

Feature: quick stats #330

nfultz opened this issue Feb 22, 2023 · 2 comments

Comments

@nfultz
Copy link
Contributor

nfultz commented Feb 22, 2023

It would be neat to add something like mcfly stats to the cli for the curious - it could be roughly equivalent to

sqlite3 .local/share/mcfly/history.db "select substr(cmd,1,instr(cmd,' ')-1), count(1) as n from commands group by 1 order by 2 desc limit 40;"

Inspired by https://www.miskatonic.org/2023/02/21/commands/

@cantino
Copy link
Owner

cantino commented Feb 23, 2023

I'd be happy to accept a pull request!

@nfultz
Copy link
Contributor Author

nfultz commented Feb 23, 2023

Sure, I can add it to my todo list.

nicokosi added a commit to nicokosi/mcfly that referenced this issue Jun 3, 2024
As suggested in issue cantino#330, this commit introduces a "stats" command
that displays quick stats like:

    $ cargo run --quiet -- stats

    📊 Quick stats:
      - history has 51915 items.
      - has 10 distinct commands.
      - 10 first commands, sorted by occurrences:
        gco (2835)
        g (2451)
        z (2348)
        npm (2020)
        sdk (1908)
        git (1615)
        ./run-dev.sh (1490)
        cd (1334)
        docker (1225)
nicokosi added a commit to nicokosi/mcfly that referenced this issue Jun 3, 2024
As suggested in issue cantino#330, this commit introduces a "stats" command
that displays quick stats like:

    $ cargo run --quiet -- stats

    📊 Quick stats:
      - history has 51926 items ;
      - 10 first commands, sorted by occurrences:
        gco (2835)
        g (2452)
        z (2348)
        npm (2020)
        sdk (1908)
        git (1616)
        ./run-dev.sh (1490)
        cd (1334)
        docker (1225)
nicokosi added a commit to nicokosi/mcfly that referenced this issue Jun 4, 2024
Fix these Clippy warnings:

cargo clippy
    Checking mcfly v0.8.6 (/Users/nicolas/work/mcfly)
warning: useless use of `format!`
  --> src/stats_generator.rs:26:24
   |
26 |         lines.push_str(format!("📊 Quick stats:\n").as_mut_str());
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"📊 Quick stats:\n".to_string()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
   = note: `#[warn(clippy::useless_format)]` on by default

warning: deref which would be done by auto-deref
  --> src/stats_generator.rs:29:24
   |
29 |           lines.push_str(&*Self::generate_command_stats(
   |  ________________________^
30 | |             self,
31 | |             limit,
32 | |             most_used_commands,
33 | |         ));
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref
   = note: `#[warn(clippy::explicit_auto_deref)]` on by default
help: try
   |
29 ~         lines.push_str(&Self::generate_command_stats(
30 +             self,
31 +             limit,
32 +             most_used_commands,
33 ~         ));
   |

warning: accessing first element with `vec.get(0)`
  --> src/stats_generator.rs:82:9
   |
82 |         vec.get(0).unwrap().count
   |         ^^^^^^^^^^ help: try: `vec.first()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#get_first
   = note: `#[warn(clippy::get_first)]` on by default

warning: `mcfly` (lib) generated 3 warnings (run `cargo clippy --fix --lib
nicokosi added a commit to nicokosi/mcfly that referenced this issue Jun 5, 2024
Try to fix tests that used to depend on "real history from shell":

    test stats_generator::tests::empty_history ... FAILED
    test stats_generator::tests::full_history ... FAILED
    test stats_generator::tests::partial_history ... FAILED

    failures:

    ---- stats_generator::tests::empty_history stdout ----
    McFly: Importing shell history for the first time. This may take a minute or two...thread 'stats_generator::tests::empty_history' panicked at src/shell_history.rs:62:17:
    McFly error: Please ensure HISTFILE or MCFLY_HISTFILE is set for your shell (environment variable not found)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants