GNU/Linux >> Linux の 問題 >  >> Linux

bash プロンプトにアイコンを追加する方法

実際、はい、できます。

最近のバージョンの Bash では、少なくとも 4 (私は 4.2 と 4.3 でそれを行うことができました)、16 進数で絵文字をレンダリングできます。

echo -e を使用

検索した絵文字を貼り付け、hexdump を実行して、それが何で構成されているかを確認します:

plasmarob ~ $ echo -n ""| hexdump

0000000 f0 9f 87 ba f0 9f 87 b8                        
0000008

そして、その一番上の行を取り、各 hex ペアを \x でエスケープします:

plasmarob ~ $ echo -e 'See? \xf0\x9f\x87\xba\xf0\x9f\x87\xb8'
See? 

私は実際に私のものを次のように変更しました:

プラズマロブ ~ ⚡

そうです、このようなものを考え出し、それを .bashrc に追加してみてください または .bash_profile .

編集:この投稿のフラグが「US」文字としてレンダリングされるようになったため、SO またはブラウザーのレンダリングに関する何かが変更された可能性があります。 YMMV ですが、記載されているバージョンの bash でも動作すると思います。


最近では、絵文字対応のフォントがあれば絵文字を追加できます。質問が最初に投稿されたとき、これは簡単に実行できるオプションではなかったと思います

数年前にこのブログ記事を書きました。

アメリカの国旗については知りませんが、export PS1="\360\237\232\251 > " プロンプトでフラグを取得します。

また、エコーまたはシェルプロンプトのエスケープを少し簡単に出力できるようにするシェルツールも作成しました。エモといいます


申し訳ありません。端末はグラフィックスを行いません。

できることの完全な説明 PROMPTING を参照してください bash(1) man ページのセクション:

<ブロック引用>

プロンプト

対話的に実行する場合、bash は、コマンドを読み取る準備ができたときにプライマリ プロンプト PS1 を表示し、コマンドを完了するためにさらに入力が必要なときにセカンダリ プロンプト PS2 を表示します。 Bash では、バックスラッシュでエスケープされた多数の特殊文字を挿入することで、これらのプロンプト文字列をカスタマイズできます。これらの文字は次のようにデコードされます:

\a     an ASCII bell character (07)
\d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format}
       the  format  is  passed to strftime(3) and the result is inserted into the
       prompt string; an empty format results in a locale-specific time
       representation. The braces are required
\e     an ASCII escape character (033)
\h     the hostname up to the first ‘.’
\H     the hostname
\j     the number of jobs currently managed by the shell
\l     the basename of the shell’s terminal device name
\n     newline
\r     carriage return
\s     the name of the shell, the basename of $0 (the portion following the final
       slash)
\t     the current time in 24-hour HH:MM:SS format
\T     the current time in 12-hour HH:MM:SS format
\@     the current time in 12-hour am/pm format
\A     the current time in 24-hour HH:MM format
\u     the username of the current user
\v     the version of bash (e.g., 2.00)
\V     the release of bash, version + patch level (e.g., 2.00.0)
\w     the current working directory, with $HOME abbreviated with a tilde (uses the
       value of the PROMPT_DIRTRIM variable)
\W     the basename of the current working directory, with $HOME abbreviated with a
       tilde
\!     the history number of this command
\#     the command number of this command
\$     if the effective UID is 0, a #, otherwise a $
\nnn   the character corresponding to the octal number nnn
\\     a backslash
\[     begin a sequence of non-printing characters, which could be used to embed a
       terminal control sequence into the prompt
\]     end a sequence of non-printing characters

通常、コマンド番号と履歴番号は異なります。コマンドの履歴番号は履歴リスト内の位置であり、履歴ファイルから復元されたコマンドが含まれる場合があります (以下の履歴を参照)。コマンド番号はシーケンス内の位置です。現在のシェル セッション中に実行されたコマンドの数。文字列がデコードされた後、prompvars シェル オプションの値に応じて、パラメーター展開、コマンド置換、算術展開、および引用符の削除によって展開されます (以下の SHELL BUILTIN COMMANDS の shopt コマンドの説明を参照してください)。

\e\[ そして \] エスケープ シーケンスには特に注意が必要です。これらを使用すると、ANSI エスケープ コードを挿入して、前景色、背景色の変更、カーソルの移動、画面の一部の消去、およびその他の派手なトリックを実行するよう端末に命令できます。

たとえば、プロンプトの色がどのように変化するかです。 \[\e[0;31m\] 前景色を赤に設定し、 \[\e[0;0m\] デフォルトにリセットします。


Linux
  1. LinuxでBashプロンプトを短縮する方法は?

  2. basenameコマンドの使用方法は?

  3. Bashの「評価」コマンド?

  1. 前の bash コマンドの引数を思い出すにはどうすればよいですか?

  2. Linuxのsh(bashではない)のコマンドプロンプトで現在のパスを表示するには?

  3. bashコマンド文字列の逐語的な文字を確認するにはどうすればよいですか?

  1. Bash履歴に保存されるコマンドの数を変更する方法

  2. Ubuntu でコア数を調べる方法

  3. エラーが発生したときに Bash で行番号を見つけるにはどうすればよいですか?