tricky

highlight output

[!TIP] references:

$ curl -sg https://api.domain.com | ack --passthru 'keyword'

less

$ curl -sg https://api.domain.com | less -i -p 'keyword'

$ command | grep --color=always 'pattern\|$'
$ command | grep --color=always -E 'pattern|$'
$ command | egrep --color=always 'pattern|$'
  • example

    $ curl -sg 'https://api.domain.com | jq -r . | grep --color=always '.*keyword.*\|$'
    
    # or
    $ curl -sg 'https://api.domain.com | jq -r . | grep --color=always -E '| .*keyword.*'

[!TIP] Highlight was designed to offer a flexible but easy to use syntax highlighter for several output formats. Instead of hardcoding syntax or colouring information, all relevant data is stored in configuration scripts. These scripts may be altered or enhanced with plug-in scripts.

$ highlight -i git.groovy -o git.groovy.html --syntax groovy --inline-css --include-style --line-numbers

[!TIP] ccat is the colorizing cat. It works similar to cat but displays content with syntax highlighting.

$ ccat /path/to/file.groovy

# output html format
$ ccat file.py --bg=dark --html

# get colors
$ ccat --palette

render visualization of hexadecimal colors

[!NOTE|label:references:]

# colorcat
# - cats a file, but if any line contains N hex colors, it appends the colors
#   (rendered as ansi escape sequences) to the end of the line.
# - input can be stdin, a file, or a hex color in plain text
function colorcat() {
  if [[ "$#" -eq 1 && ! -f "$1" ]]; then
    echo "$1"
  else
    cat "$@"
  fi | while read -r line; do
    local colors=""
    for word in $line; do
      if [[ "$word" =~ ^[^A-Fa-f0-9]*#?([A-Fa-f0-9]{6})[^A-Fa-f0-9]*$ ]]; then
        hex=${BASH_REMATCH[1]}
        local r=$((16#${hex:0:2}))
        local g=$((16#${hex:2:2}))
        local b=$((16#${hex:4:2}))
        local truecolor="\033[48;2;${r};${g};${b}m"
        local reset="\033[0m"
        colors="${colors}${truecolor}  ${reset} "
      fi
    done
      echo -e "$line $colors"
  done
}

others

remove highlight

[!TIP] references:

$ <cmd> | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g"

# or
$ alias decolorize='sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[mGKHfJ]//g"'
# deprecated
# $ alias decolorize='sed -r "s/\\x1B\\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"'
$ command | decolorize
  • tips

    $ git br -a | cat -A
    * ^[[1;32mmarslo^[[m$
      ^[[31mremotes/origin/marslo^[[m$
      ^[[31mremotes/origin/gh-pages^[[m$
      ^[[31mremotes/origin/gitbook^[[m$
      ^[[31mremotes/origin/master^[[m$
      ^[[33mgh-pages^[[m$
      ^[[33mmaster^[[m$
      ^[[31mremotes/origin/sample^[[m$
    
    $ git br -a | decolorize | cat -A
    * marslo$
      remotes/origin/marslo$
      remotes/origin/gh-pages$
      remotes/origin/gitbook$
      remotes/origin/master$
      gh-pages$
      master$
      remotes/origin/sample$

[!NOTE|label:references:]

$ echo ${BASH_ALIASES[ls]}
ls --color=always

  • get bash login log ( for rc script debug )

    $ bash -l -v
  • run with only one startup file ( for sharing accounts )

    $ bash -i --rcfile="$HOME/.marslo/.imarslo"
$ grep -oP '"url":"\K[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q)

authentication

references:

CHARACTERSPERCENT-ENCODED

]

%5B

[

%5D

?

%3F

/

%2F

<

%3C

~

%7E

#

%23

```

%6D

!

%21

@

%40

$

%24

%

%25

^

%5E

&

%26

*

%2A

(

%28

)

%29

+

%2B

=

%3D

}

%7D

`

%7C

:

%3A

"

%22

;

%3B

'

%27

,

%2C

>

%3E

{

%7B

space

%20

downlaods bookmark

[!TIP] references:

Last updated