0

I am looking for a way to apply colors to highlight URLs (http://....) and IP @ in the output of a terminal command.

Example would be with a wget command for example where I would like to be able to output URLs in a particular color so that it is easier to read.

Best would be to be able to do the same for IP@ and other important info to standout.

I have been struggling with this for a while and not able to find a solution.

I use iTerm 2 on MAC with oh-my-zsh

2
  • According to [this blog] (gabri.me/blog/custom-colors-in-your-zsh-prompt), if you run spectrum_ls in your terminal, do you get the colors? – Alfabravo Sep 10 '15 at 5:45
  • I think this is only modifying the prompt color. I am looking for a way to highlight URL and IP @ in any command output. – Laurent Sep 11 '15 at 6:16
0

On the answer to this question, someone actually forked zsh-syntax-hightighting and created a flexible functionality to colorize according to patterns and lot of stuff on zsh.

You might check this answer as well. Don't know if this makes yours a duplicate but oh well. Despite it being old, you can try supercat as it works with regexp so you can match URL and colorize them.

0

In Preferences -> Profiles -> Advanced you can set up Triggers; that is, if a certain regular expression is encountered, it might take actions such as highlight the text.

Beware: unfortunately it significantly slows down iTerm.

I'm not sure when this feature appeared, it might be only present in the latest betas.

3
  • Nice. I found the Triggers but putting the following Regex is not working: ^(http|https):// – Laurent Sep 25 '15 at 2:18
  • Does the URL appear at the beginning of a line, as required by the ^ character in your regexp? – egmont Sep 25 '15 at 13:22
  • I am obviously pretty weak on RegEx. I wanted the highlight to happen for any http:// or https:// regardless of where the http:// appears. How should my RegEx look like? I tried to remove ^ which works but only highlight the http:// part when I would like this + the URL to be highlight example.com (this shoudl be highlighted anywhere in the output) – Laurent Sep 28 '15 at 12:26
0

Apply colors to terminal output...

For anyone looking for a simple way (in my opinion) to color the terminal text in 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} "

so with the variable setup described above, they can all be local to a bash script for example and you just need to prepend ${COLOR} and append ${NC} to whatever text in your echo statement, or printf, and so on in you bash, csh script or .c or .f program

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.