0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

Gitって便利だけど、たまにしか使わないコマンドはすぐ忘れますよね。
git diff --staged とか git reflog とか、名前は聞いたことあるけど使ってないな…みたいな。

そこで、毎回実行するたびに1つランダムでGitコマンドのTipを表示してくれるCLIツールを作ってみました。

git-tips-cli とは?

•	git-tips と打つだけで、Gitの便利なコマンドとその説明をランダムに表示
•	JSONファイルにコマンドを管理しているので、拡張も簡単
•	Python製 / clickライブラリ使用
•	pip install で簡単に導入可能

使い方

インストール

pip install git-tips-cli

※ Python 3.7 以上が必要です。

実行

git-tips

表示例:

git restore .
作業ツリーの変更をすべて元に戻します。

中身はどうなってるの?

ディレクトリ構成(一部)

git-tips-cli/
├── git_tips/
│   ├── __main__.py     ← CLI本体
│   └── tips.json       ← Git Tipsデータ
├── setup.py            ← CLI登録
├── README.md
└── LICENSE
tips.json(抜粋)
[
  {
    "command": "git diff --staged",
    "description": "ステージングされた変更の差分を表示します。"
  },
  {
    "command": "git reflog",
    "description": "HEADやブランチの移動履歴を確認できます。"
  }
]

コマンド実行部分(main.py)

@click.command()
def main():
    with open(tips_path, "r", encoding="utf-8") as f:
        tips = json.load(f)
    tip = random.choice(tips)
    click.echo(f"📌 {tip['command']}\n{tip['description']}")

なぜ作ったの?

•	OSS活動の一歩目として「小さくても便利なものを作ってみたかった」
•	自分自身がGitのコマンドをよく忘れるので、学習を習慣化したかった
•	JSONにしておけば、Pull Requestでどんどん追加してもらえる構成にできる

今後やりたいこと

•	--search で特定コマンドの検索機能
•	英語/日本語切り替え対応
•	PyPIへの正式公開
•	ブラウザでも見られるTips一覧サイト

リンク集

おわりに

「CLIツールを作ってみたいけど、何を作ればいいかわからない」
そんな方にこそおすすめしたいのが、小さな学習補助ツールです。

自分のためになる、かつ他人にも使ってもらえる。
そういうOSS活動、これからも続けていきたいと思います!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?