#!/bin/sh

# Pattern-matching
protocols='(((https?|ssh|git|ftps?|rsync|file|svn):\/\/)|mailto:|data:)'
validchar='[^] \t\r\n\f)\x27">]+'

# Formatting
before='\x1B[4;32m'
after='\x1B[0m'

sed -r -e "s/${protocols}${validchar}/${before}&${after}/g" $1;

Add shell-script to decorate URL patterns in text
Add shell-script to decorate URL patterns in text

The script hooks directly into sed, so both STDIN or parameters work:

    decorate-urls.sh < ~/Desktop/file.txt
    decorate-urls.sh file.txt

Refs: 5b9fbdb5b23
