LoginSignup
5
1

More than 3 years have passed since last update.

cmd.exeのプロンプトを変えて黒画面を10倍楽しむ

Last updated at Posted at 2020-09-02

TL;DR

プロンプトとはシェルが対話モードで出力するubuntu@ubuntu:~ $のような文字列のことで、環境変数PS1で設定されます。Linux界隈ではずいぶん前からシェルのプロンプトをカスタマイズすることが流行っています。

Windowsでコマンドラインを使う場合はWSLやmsys2などを入れてしまうので、コマンドプロンプトをそのままガッツリ使うことはあまりないのかもしれませんが、cmd.exeのプロンプトをいろいろいじってみることでWindowsでのコマンドラインライフがより楽しいものになるかもしれませんよ?

promptコマンド

promptコマンドでプロンプトを変えることができます。試しに何か入れてみましょう。

prompt hello,windows!

screenshot-nimbus-capture-2020.09.03-01_38_05.png

次にパラメータを試してみましょう。

prompt $v:$p$s

screenshot-nimbus-capture-2020.09.03-01_43_45.png

promptの引数

promptコマンドの引数は

prompt <text>

と、非常にシンプルです。

また、引数なしで

prompt

を実行すると、プロンプトがリセットされます。

screenshot-nimbus-capture-2020.09.03-01_47_44.png

使えそうなパラメータいろいろ

他のコマンド同様、prompt /?でいろいろなパラメータを確認できますが、その中でも使えそうなものを試してみましょう。

パラメータ 説明
$t 時刻 1:56:10.07
$d 日付 Thu Sep 03
$p ドライブおよびパス C:\Windows\System32
$n ドライブのみ C:\
$_ 改行
$s スペース

個性的なプロンプトを作る

また、ASCII文字だけではなく、フォントがグリフを持っていればこんな感じのプロンプトを作ることもできます。

prompt $p$s❱$s

screenshot-nimbus-capture-2020.09.03-01_22_41.png

cmd.exeの引数として実行

手でタイプするのではなく、cmd.exeの引数に指定して実行させる場合は/kスイッチを使います。/kスイッチを指定すると、コマンドを実行した後は対話モードのまま待機状態になります。

cmd.exe /k prompt $p$s❱$s

Windows Terminalの設定

{
    "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
    "name": "Command Prompt",
    "commandline": "cmd.exe /k prompt $p$s❱$s",
    "hidden": false,
    "colorScheme": "Campbell"
},

もちろん、絵文字も表示できます。promptコマンドに入力するときに文字化けしたりと、ちょっとおすすめではないですが。

prompt 🌻🌼🌹$s

screenshot-nimbus-capture-2020.09.03-02_05_23.png

VS Codeでこそプロンプトをカスタマイズしよう

ところで、皆さんはVS CodeでどこにIntegrated Terminalを表示させていますか?

VS CodeのIntegrated Terminalはサイドパネルにドラッグアンドドロップすることができます。でも、そのままではサイドパネルが狭く、C:\Users\...\...\...\と長いパスが表示されてしまい、見づらくなってしまいます。

そこで、$_でパスとコマンド入力行の間に改行を入れてみましょう。

prompt $p$_❱$s

screenshot-nimbus-capture-2020.09.03-02_11_46.png

VS Codeの設定

"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": "/k prompt $p$_❱$s",

prompt /?

Changes the cmd.exe command prompt.

PROMPT [text]

  text    Specifies a new command prompt.

Prompt can be made up of normal characters and the following special codes:

  $A   & (Ampersand)
  $B   | (pipe)
  $C   ( (Left parenthesis)
  $D   Current date
  $E   Escape code (ASCII code 27)
  $F   ) (Right parenthesis)
  $G   > (greater-than sign)
  $H   Backspace (erases previous character)
  $L   < (less-than sign)
  $N   Current drive
  $P   Current drive and path
  $Q   = (equal sign)
  $S     (space)
  $T   Current time
  $V   Windows version number
  $_   Carriage return and linefeed
  $$   $ (dollar sign)

If Command Extensions are enabled the PROMPT command supports
the following additional formatting characters:

  $+   zero or more plus sign (+) characters depending upon the
       depth of the PUSHD directory stack, one character for each
       level pushed.

  $M   Displays the remote name associated with the current drive
       letter or the empty string if current drive is not a network
       drive.

参考

prompt | Microsoft Docs

5
1
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
5
1