LoginSignup
7
5

More than 5 years have passed since last update.

zsh ログイン時に格言を表示する

Posted at

sorin-ionescu/prezto でやってたので真似してみた。

zsh-fortune.png

fortune コマンドをインストール

まずは格言を表示するためのコマンド fortune をインストールします。

以下は Mac の場合

$ brew install fortune

zsh ログイン時に fortune を実行

~/.zlogin ファイルに以下のコードを追加します。
(ファイルがない場合は新規作成して下さい)

.zlogin
# Print a random, hopefully interesting, adage.
if (( $+commands[fortune] )); then
    fortune -a
    print
fi

if 文では fortune コマンドの有無をチェックしています。
zsh 特有の書き方なので、bash や他のシェルでは typewhich コマンドなどでチェックして下さい。
(zsh でも typewhich でチェックしても問題ありません)

.zlogin
# Print a random, hopefully interesting, adage.
if type fortune > /dev/null 2>&1; then
    fortune -a
    print
fi
7
5
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
7
5