端末出力に色を適用してURLやその他のアイテムを強調表示する

端末出力に色を適用してURLやその他のアイテムを強調表示する

URLを強調表示するために色を適用する方法を探しています(http://....) と IP@ は端末コマンド出力に含まれます。

たとえば、wgetコマンドを使用する場合は、URLを特定の色で出力して読みやすくしたいと思います。

IP@やその他の重要な情報についても同じことを強調することができれば幸いです。

私はしばらくこの問題で苦労していますが、解決策を見つけることができません。

MAC では iTerm 2 と oh-my-zsh を使用します。

ベストアンサー1

端末出力に色を適用...

(私の考えでは)Linuxで端末のテキストの色を指定する簡単な方法を探している人

# yeah  i know... it's csh... if you need bash the syntax is simply red='<colorcode>'

# i have not experimented with other colors, these have always been enough for me.

setenv RED         '\033[0;31m'
setenv BOLDRED     '\033[1;31m'
setenv GREEN       '\033[0;32m'
setenv BOLDGREEN   '\033[1;32m'
setenv ORANGE      '\033[0;33m'
setenv YELLOW      '\033[1;33m'
setenv BLUE        '\033[0;34m'
setenv BOLDBLUE    '\033[1;34m'
setenv PURPLE      '\033[0;35m'
setenv BOLDPURPLE  '\033[1;35m'
setenv CYAN        '\033[0;36m'
setenv BOLDCYAN    '\033[1;36m'
setenv WHITE       '\033[0,37m'
setenv BOLDWHITE   '\033[1,37m'

# turn color off,  i.e. nocolor
setenv NC          '\033[0m'

# example

echo "${RED}This text is in red.${NC}  This text is now back to whatever the previous color was."

# change my csh/tcsh prompt, and only the prompt, to cyan color that is `[username@host cwd] : ` with all text afterward the default shell color.

set prompt="${CYAN}[%n@%m %~] : ${NC} "

したがって、上記の変数設定を使用すると、すべてbashスクリプトのローカル変数になります。たとえば、${COLOR}をecho文やprintfなどのテキストの前に追加し、${NC}をbash、cshスクリプト、または.cまたは.fプログラム

おすすめ記事