Skip to content

Commit

Permalink
feat: 🎸 add emoji title for styling (#12)
Browse files Browse the repository at this point in the history
* elixir binary-size for string

* feat: 🎸 add emoji title for styling

* chore: 🤖 0.2.1
  • Loading branch information
ThaddeusJiang committed Feb 20, 2024
1 parent 40588d8 commit ea0bad5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 74 deletions.
94 changes: 48 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# CHR

The commands history report CLI for the Elixir developers.
CHR(Command History Report): A command history report tool base on your shell history file.

> Your data is yours.
[![Hex.pm version](https://img.shields.io/hexpm/v/chr.svg)](https://hex.pm/packages/chr)
[![Twitter: ThaddeusJiang](https://img.shields.io/twitter/follow/ThaddeusJiang.svg?style=social)](https://twitter.com/ThaddeusJiang)

> The name "chr" is derived from "commands history report".
> Inspired by the Fig report, this tool aims to provide a similar experience for those not using Fig.
![Fig 2022 Wrapped](https://pbs.twimg.com/media/FkqSV8hXoAEXqON?format=png&name=small)
Expand Down Expand Up @@ -49,70 +51,70 @@ chr
│ source code: https://github.com/ThaddeusJiang/chr │
│ │
└─────────────────────────────────────────────────────────────┘
┌─Top Commands────┐
│ │
496 git │
200 cd │
110 code │
75 ls
48 clear
48 mix
46 docker │
32 ./chr
30 npm
27 erl
│ │
└─────────────────┘
┌─Top Directories─────────────┐
┌─🏆 Top Commands────┐
810 git
276 cd
183 code
150 mix
111 ls
93 clear
63 docker
59 npm
49 k6
45 ./gitlab_cli
└────────────────────
┌─📂 Top Directories──────────┐
│ │
│ 24 git/work/plugo │
│ 36 git/work/plugo │
│ 24 repos/backend │
│ 16 repos/roaming-gateway │
│ 15 repos/backend │
│ 11 repos/k8s │
│ 10 git/ThaddeusJiang │
│ 14 git/ThaddeusJiang │
│ 13 repos/k8s │
│ │
└─────────────────────────────┘
┌─Busiest Day──────────────────┐
┌─💦 Busiest Day───────────────┐
│ │
274 commands on 2024-02-08
372 commands on 2024-02-19
│ │
└──────────────────────────────┘
┌─Weekly Activity────────────┐
┌─📅 Weekly Activity─────────┐
│ │
│ Mon │
│ Tue ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
│ Wed ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
│ Thu ▓▓▓▓▓▓▓▓▓
│ Fri ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
│ Sat ▓▓▓▓▓▓▓▓▓▓
│ Sun
│ Tue ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
│ Wed ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
│ Thu ▓▓▓▓▓▓▓
│ Fri ▓▓▓▓▓▓▓▓▓▓▓
│ Sat ▓▓▓▓▓▓▓▓▓▓
│ Sun
│ │
└────────────────────────────┘
┌─Daily Activity────────────┐
┌─🕑 Daily Activity─────────┐
│ │
│ 01 │
│ 02 │
│ 03 │
│ 04 │
│ 05
│ 06
│ 07
│ 05
│ 06 ▓▓
│ 07
│ 08 │
│ 09 │
│ 10 ▓ │
│ 11 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
│ 12 ▓▓▓▓▓▓▓▓
│ 13 ▓▓▓▓▓▓▓▓▓▓▓
│ 14 ▓▓▓▓▓▓▓
│ 15 ▓▓▓▓▓▓▓▓▓▓▓▓▓
│ 16 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
│ 17 ▓▓▓▓▓▓▓▓
│ 18 ▓▓▓▓▓▓▓▓
│ 19 ▓▓▓▓▓▓▓
│ 20 ▓▓▓▓▓
│ 11 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
│ 12 ▓▓▓▓▓▓▓▓▓▓
│ 13 ▓▓▓▓▓▓▓▓▓▓▓
│ 14 ▓▓▓▓▓▓▓▓▓
│ 15 ▓▓▓▓▓▓▓▓▓▓▓▓▓
│ 16 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
│ 17 ▓▓▓▓▓▓▓▓▓▓
│ 18 ▓▓▓▓▓▓▓▓▓▓▓▓
│ 19 ▓▓▓▓▓▓▓
│ 20 ▓▓▓▓▓▓▓▓▓▓▓
│ 21 ▓▓▓▓▓▓▓ │
│ 22 ▓▓▓▓▓▓
│ 23 ▓▓▓▓
│ 22 ▓▓▓▓▓▓
│ 23 ▓▓▓▓
│ 24 ▓ │
│ │
└───────────────────────────┘
Expand Down
33 changes: 20 additions & 13 deletions lib/chr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,36 @@ defmodule Chr do

{:error, _} ->
[]

_ ->
[]
end
end

@doc """
pick up command from history record
## Examples
iex> Chr.pick_up_command(": 1707397937:0;cat ~/.zsh_history")
"cat"
iex> Chr.pick_up_command(": 1707397937:0;clear")
"clear"
"""
def pick_up_command(string) do
string
|> String.split(" ")
|> String.split(";")
|> List.delete_at(0)
|> List.first()
|> String.split(";")
|> List.last()
|> String.split(" ")
|> List.first()
end

@doc """
pick up directory from history record
## Examples
iex> Chr.pick_up_directory(": 1707397937:0;cd ~/projects/chr")
"~/projects/chr"
"""
def pick_up_directory(string) do
[head | tail] =
Expand Down Expand Up @@ -91,7 +101,7 @@ defmodule Chr do
history_list
|> Enum.map(&pick_up_directory/1)
|> Enum.reject(&is_nil/1)
|> Enum.reject(&(String.length(&1) < 2 || String.ends_with?(&1, "..")))
|> Enum.reject(&(String.length(&1) < 2 || String.ends_with?(&1, ".")))
|> Enum.reduce(%{}, fn directory, acc ->
Map.update(acc, directory, 1, &(&1 + 1))
end)
Expand All @@ -117,12 +127,9 @@ defmodule Chr do
~U[2024-02-08 22:12:17Z]
"""
def pick_up_local_datetime(string) do
string
|> String.split(":")
|> List.delete_at(0)
|> List.first()
|> String.split(" ")
|> List.last()
<<_::binary-size(2), timestamp::binary-size(10), _::binary>> = string

timestamp
|> String.to_integer()
|> DateTime.from_unix!()
|> DateTime.add(Chr.timezone_offset(), :hour)
Expand Down
16 changes: 5 additions & 11 deletions lib/chr/print.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ defmodule Chr.Print do
count_stringify(5, count |> Integer.to_string(), command)
end)
|> Enum.join("\n")
# FIXME: Owl's bug: right border malposition when title has emoji
# |> print_count_number("🏆 Top Commands", :red)
|> print_count_number("Top Commands", :red)
|> print_count_number("🏆 Top Commands", :red)
end

@doc """
Expand All @@ -106,8 +104,7 @@ defmodule Chr.Print do
count_stringify(5, count |> Integer.to_string(), directory)
end)
|> Enum.join("\n")
# |> print_count_number("📂 Top Directories", :red, 5)
|> print_count_number("Top Directories", :red)
|> print_count_number("📂 Top Directories", :red, 5)
end

defp busiest_day_stringify({day, count}) do
Expand All @@ -121,8 +118,7 @@ defmodule Chr.Print do
histories
|> Chr.busiest_day()
|> busiest_day_stringify()
# |> print_count_number("💦 Busiest Day", :green)
|> print_count_number("Busiest Day", :green)
|> print_count_number("💦 Busiest Day", :green)
end

@doc """
Expand All @@ -135,8 +131,7 @@ defmodule Chr.Print do
percent_stringify(day, count)
end)
|> Enum.join("\n")
# |> print_count_bar("📅 Weekly Activity", :yellow)
|> print_count_bar("Weekly Activity", :yellow)
|> print_count_bar("📅 Weekly Activity", :yellow)
end

@doc """
Expand All @@ -149,8 +144,7 @@ defmodule Chr.Print do
percent_stringify(hour, count)
end)
|> Enum.join("\n")
# |> print_count_bar("🕑 Daily Activity", :magenta)
|> print_count_bar("Daily Activity", :magenta)
|> print_count_bar("🕑 Daily Activity", :magenta)
end

@doc """
Expand Down
7 changes: 4 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ defmodule Chr.MixProject do
def project do
[
app: :chr,
version: "0.2.0",
version: "0.2.1",
elixir: "~> 1.15",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
description: description(),
package: package(),
deps: deps(),
escript: escript(),
name: "chr",
name: "CHR",
source_url: "https://github.com/ThaddeusJiang/chr",
authors: ["ThaddeusJiang"],
docs: [
Expand All @@ -32,7 +32,8 @@ defmodule Chr.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:owl, "~> 0.8"},
{:owl, "~> 0.9"},
{:ucwidth, "~> 0.2"},
{:ex_doc, "~> 0.14", only: :dev, runtime: false}
]
end
Expand Down
3 changes: 2 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.4", "29563475afa9b8a2add1b7a9c8fb68d06ca7737648f28398e04461f008b69521", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f4ed47ecda66de70dd817698a703f8816daa91272e7e45812469498614ae8b29"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"owl": {:hex, :owl, "0.8.0", "0ef925cb784311093d4e3734822960cbdbdb13b095d748bb5bc82abcd5b56732", [:mix], [], "hexpm", "0a5586ceb1a12f4bbda90e330c20e6ea034552335d09466c10e4218c98977529"},
"owl": {:hex, :owl, "0.9.0", "9b33d64734bd51d3fc1d6ed01b12f8c2ed23e1fbf8c43658a6dfbff62578bd03", [:mix], [{:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: true]}], "hexpm", "cd70b55327985f8f24d38cb7de5bf8a8d24040e1b49cca2345508f8119ce81fd"},
"ucwidth": {:hex, :ucwidth, "0.2.0", "1f0a440f541d895dff142275b96355f7e91e15bca525d4a0cc788ea51f0e3441", [:mix], [], "hexpm", "c1efd1798b8eeb11fb2bec3cafa3dd9c0c3647bee020543f0340b996177355bf"},
}

0 comments on commit ea0bad5

Please sign in to comment.