Skip to content

Commit

Permalink
feat: optimize output & bump version to v0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
YiNNx committed Sep 1, 2024
1 parent ebfdc80 commit a4e42d2
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 84 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
demo.*
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cmd-wrapped"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
authors = ["YiNNx <[email protected]>"]
description = "A CLI tool to view Unix shell history statistics, with support for zsh, bash, fish, and atuin."
Expand Down
79 changes: 34 additions & 45 deletions README-CN.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,67 @@
<p align="right">
<a href="./README.md">English</a> / 简体中文
# cmd-wrapped

<p>
<img alt="Stars" src="https://img.shields.io/github/stars/YiNNx/cmd-wrapped?style=flat-square&color=68BDB7&labelColor=444B5A">
&nbsp;
<img alt="Release" src="https://img.shields.io/github/v/release/YiNNx/cmd-wrapped?style=flat-square&color=93AF63&labelColor=444B5A">
&nbsp;
<img alt="Release" src="https://img.shields.io/crates/v/cmd-wrapped.svg?style=flat-square&color=C5AB81&labelColor=444B5A">
&nbsp;
</p>
<div align="center">
<h1>cmd-wrapped</h1>
<p>👩‍💻 Rust-Based Unix Shell History Analyzer<br/><p/>
<div>
<img alt="Stars" src="https://img.shields.io/github/stars/YiNNx/cmd-wrapped?style=flat-square&color=87e3dd&labelColor=444B5A">
&nbsp;
<img alt="Release" src="https://img.shields.io/github/v/release/YiNNx/cmd-wrapped?style=flat-square&color=87e3dd&labelColor=444B5A">
</div>
</div>

一个用于查看 shell 历史记录统计信息的 CLI,支持 zsh、bash、fish 和 atuin。

## Features
<img src="https://github.com/user-attachments/assets/fa34598f-3b8c-4f90-8569-7724df787b1c" height="750" />

- 生成过去一年中的命令行活跃分布,如每日最活跃时段,以及常用命令统计。
- 类 Github 的年度命令分布图
- 支持:
- zsh
- bash
- fish
- atuin
## 安装

## 如何使用

### 安装

- #### 使用 [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) 安装
- **使用 [Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html)**

```shell
cargo install cmd-wrapped
```

- #### [Release](https://github.com/YiNNx/cmd-wrapped/releases/latest) 下载
- **[Release](https://github.com/YiNNx/cmd-wrapped/releases/latest) 下载**

下载对应包并解压,在命令行中运行(可能需要 chmod)
解压,赋予执行权限,然后在终端中运行二进制文件。

- #### Nix❄️
- **Archlinux**

```nix
nix run nixpkgs#cmd-wrapped
```shell
yay -S cmd-wrapped
```

- #### Arch
- **Nix❄️**

```shell
yay -S cmd-wrapped
```nix
nix run nixpkgs#cmd-wrapped
```

### 参数
## 使用

```shell
# fetch current stats
```sh
# 获取当前统计数据
cmd-wrapped

# fetch annual shell history stats for a specific year
# 获取特定年份的年度 shell 历史统计数据
cmd-wrapped 2024

# specify the target shell
# 指定目标 shell
cmd-wrapped -s <shell>
```

所支持的 `<shell>` 选项`zsh`, `bash`, `fish`, `atuin`.
`<shell>` 支持的选项`zsh``bash``fish``atuin`

> [!NOTE]
>
> 对于某些命令行环境,可能无法输出正确的数据 (比如 [所有数据都为 0](https://github.com/YiNNx/cmd-wrapped/issues/3) ). 这是因为 Zsh / Bash 只有配置了对应的选项后,才会记录下你每一条命令对应的时间
> 在某些情况下,cmd-wrapped 可能无法输出正确的数据(例如 [所有输出均为 0](https://github.com/YiNNx/cmd-wrapped/issues/3))。这是因为它依赖于每个命令的时间戳记录,有时需要额外配置特定选项
>
> - Zsh - [EXTENDED_HISTORY](https://zsh.sourceforge.io/Doc/Release/Options.html#History) (oh-my-zsh 则会默认开启此选项)
> - Bash - [HISTTIMEFORMAT](https://www.gnu.org/software/bash/manual/bash.html#index-HISTTIMEFORMAT)
> - 对于 Zsh - [EXTENDED_HISTORY](https://zsh.sourceforge.io/Doc/Release/Options.html#History)oh-my-zsh 默认启用)
> - 对于 Bash - [HISTTIMEFORMAT](https://www.gnu.org/software/bash/manual/bash.html#index-HISTTIMEFORMAT)
>
> 在没有配置选项前的命令,对应的命令时间不会被持久化记录,因此 cmd-wrapped 也无法获取并生成对应的数据分析。如果运行 cmd-wrapped 发现无法输出正确的数据,也许只能现在配置好选项等待明年来用了 :P
> **在配置选项之前执行的命令将不会记录时间戳,这将影响 cmd-wrapped 的统计数据**
## 致谢 & 开源协议
## 致谢与许可证

- 感谢 [@jyi2ya](https://github.com/jyi2ya) 的绝妙想法!
- 开源协议: [MIT](https://github.com/YiNNx/cmd-wrapped/blob/master/LICENSE)
- 特别感谢 [@jyi2ya](https://github.com/jyi2ya) 的绝妙想法!
- 许可证:[MIT](https://github.com/YiNNx/cmd-wrapped/blob/master/LICENSE)
58 changes: 24 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,45 @@
<p align="right">
English / <a href="./README-CN.md">简体中文</a>
# cmd-wrapped

<p>
<img alt="Stars" src="https://img.shields.io/github/stars/YiNNx/cmd-wrapped?style=flat-square&color=68BDB7&labelColor=444B5A">
&nbsp;
<img alt="Release" src="https://img.shields.io/github/v/release/YiNNx/cmd-wrapped?style=flat-square&color=93AF63&labelColor=444B5A">
&nbsp;
<img alt="Release" src="https://img.shields.io/crates/v/cmd-wrapped.svg?style=flat-square&color=C5AB81&labelColor=444B5A">
&nbsp;
</p>
<div align="center">
<h1>cmd-wrapped</h1>
<p>👩‍💻 Rust-Based Unix Shell History Analyzer<br/><p/>
<div>
<img alt="Stars" src="https://img.shields.io/github/stars/YiNNx/cmd-wrapped?style=flat-square&color=87e3dd&labelColor=444B5A">
&nbsp;
<img alt="Release" src="https://img.shields.io/github/v/release/YiNNx/cmd-wrapped?style=flat-square&color=87e3dd&labelColor=444B5A">
</div>
</div>

## Features
A CLI to view your shell history stats, with support for zsh, bash, fish, and atuin.

- Analyze the commandline activity distribution for months, days and hours
- Github-style command distribution graph
- Supported shell / history tool:
- zsh
- bash
- fish
- atuin
<img src="https://github.com/user-attachments/assets/fa34598f-3b8c-4f90-8569-7724df787b1c" height="750" />

## How to Use
## Installation

### Installation

- #### Using [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html)
- **Use [Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html)**

```shell
cargo install cmd-wrapped
```

- #### Download from [Release](https://github.com/YiNNx/cmd-wrapped/releases/latest)
- **Download from [Release](https://github.com/YiNNx/cmd-wrapped/releases/latest)**

Unzip, chmod and run the binary file in the terminal.

- #### Nix❄️
- **Archlinux**

```nix
nix run nixpkgs#cmd-wrapped
```shell
yay -S cmd-wrapped
```

- #### Arch
- **Nix❄️**

```shell
yay -S cmd-wrapped
```nix
nix run nixpkgs#cmd-wrapped
```

### Usage
## Usage

```shell
```sh
# fetch current stats
cmd-wrapped

Expand All @@ -64,12 +54,12 @@ Supported options for `<shell>` : `zsh`, `bash`, `fish`, `atuin`.

> [!NOTE]
>
> In some cases, cmd-wrapped may fail to output correct data (such as [all outputs being 0](https://github.com/YiNNx/cmd-wrapped/issues/3)). This is because it relies on Zsh / Bash tracking the timestamp for each command, which requires configuring specific options extraly:
> In some cases, cmd-wrapped may fail to output correct data (such as [all outputs being 0](https://github.com/YiNNx/cmd-wrapped/issues/3)). This is because it relies on the timestamp track for each command, which sometimes requires configuring specific options extraly:
>
> - For Zsh - [EXTENDED_HISTORY](https://zsh.sourceforge.io/Doc/Release/Options.html#History) (oh-my-zsh has it enabled by default)
> - For Bash - [HISTTIMEFORMAT](https://www.gnu.org/software/bash/manual/bash.html#index-HISTTIMEFORMAT)
>
> Commands executed before configuring the option won't be recorded with a timestamp and this will affect cmd-wrapped’s stats. If you find all your stats showing as 0, consider configuring the option now to view the cmd-wrapped stats next year :P
> **Commands executed before configuring the option won't be recorded with a timestamp and this will affect cmd-wrapped’s stats**.
## Credits & License

Expand Down
3 changes: 2 additions & 1 deletion src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl Statistic {
let mut monthly_commands: Vec<_> =
self.map_command_monthly[m as usize].iter().collect();
monthly_commands.sort_by(|a, b| b.1.cmp(a.1));
let fav_commands: Vec<_> = monthly_commands.iter().take(4).cloned().collect();
let fav_commands: Vec<_> = monthly_commands.iter().take(3).cloned().collect();
component.monthly_stat(
m,
self.list_month[m as usize],
Expand All @@ -334,5 +334,6 @@ impl Statistic {

component.break_line();
component.edge();
println!()
}
}
4 changes: 2 additions & 2 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl Component {
.repeat(
(current_count as f64
* ((bar_max_len - command_padding) as f64 / max_count as f64))
as usize
.round() as usize
)
.dimmed()
.to_string()
Expand Down Expand Up @@ -359,7 +359,7 @@ impl Component {
));
self.content("│");
for (command, &count) in fav_commands {
self.content(&format!("• {:<44}{:<6}", command.green().bold(), count));
self.content(&format!("• {:<45}{:<5}", command.green().bold(), count));
}
if !end {
self.content("│");
Expand Down

0 comments on commit a4e42d2

Please sign in to comment.