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?

ターミナル起動時に ひといき つきたい

0
Last updated at Posted at 2026-03-10

何がしたいのか

ターミナルをただ開いても味気ないので、起動時に fortune で取得した英語の名言を cowsay + lolcat でカラフルに表示させました。

image.png

install

brew install fortune cowsay lolcat

.zshrc への設定

以下のスクリプトを ~/.zshrc に追記します。
設定が反映されると、ターミナル起動時に牛が喋ります。

function translate_to_japanese() {
    local msg="$1"
    echo "$msg" | docker run -i --rm --platform linux/amd64 soimort/translate-shell:latest -no-auto -no-ansi -no-autocorrect -no-bidi -b -e google {en=ja} 2>/dev/null
}

function print_colorful_cow() {
    local msg="$1"

    command -v cowsay >/dev/null 2>&1 || { echo "$msg"; return 0; }
    command -v lolcat >/dev/null 2>&1 || { echo "$msg"; return 0; }

    echo "$msg" | cowsay -r | lolcat
}

function show_startup_fortune() {
    command -v fortune >/dev/null 2>&1 || return 0

    local msg_en
    msg_en=$(fortune)

    print_colorful_cow "$msg_en"
    # 翻訳が不要な場合、削除してください。
    # コンテナ起動するので長文の場合時間がかかります。
    echo ""
    translate_to_japanese "$msg_en"
}

# 実行!
show_startup_fortune

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?