-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcolors-to-github.sh
37 lines (30 loc) · 927 Bytes
/
colors-to-github.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# convert ansi-colored terminal output to github markdown
# to colorize text on github, we use <span color="red">red</span> etc
# depends on: aha, xclip
# license: CC0-1.0
# sample use: colors-to-github.sh diff a.txt b.txt
cmd="$1"
shift
base="$(basename "$cmd")"
# add arguments to force color output
# TODO add more commands here
extra_args=''
if [[ ' diff ls cargo ' =~ " $base " ]]; then
extra_args='--color=always'
elif [[ ' jp2a ' =~ " $base " ]]; then
extra_args='--colors'
elif [[ ' gulp ' =~ " $base " ]]; then
extra_args='--color'
elif [[ ' npm ' =~ " $base " ]]; then
extra_args='--color always'
fi
(
echo '<pre>'
"$cmd" $extra_args "$@" 2>&1 | aha --no-header
echo '</pre>'
) \
| sed -E 's/<span style="[^"]*color:([^;"]+);"/<span color="\1"/g' \
| sed -E 's/ style="[^"]*"//g' \
| xclip -i -sel clipboard
echo 'output is in clipboard. hit control + V in your editor'