←back to thread

756 points speckx | 1 comments | | HN request time: 0.261s | source
1. arjie ◴[] No.45676608[source]
A few I use are:

    #!/usr/bin/env bash
    # ~/bin/,dehex

    echo "$1" | xxd -r -p

and

    #!/usr/bin/env bash
    # ~/bin/,ht

    highlight() {
      # Foreground:
      # 30:black, 31:red, 32:green, 33:yellow, 34:blue, 35:magenta, 36:cyan

      # Background:
      # 40:black, 41:red, 42:green, 43:yellow, 44:blue, 45:magenta, 46:cyan
      escape=$(printf '\033')
      sed "s,$2,${escape}[$1m&${escape}[0m,g"
    }

    if [[ $# == 1 ]]; then
      highlight 31 $1
    elif [[ $# == 2 ]]; then
      highlight 31 $1 | highlight 32 $2
    elif [[ $# == 3 ]]; then
      highlight 31 $1 | highlight 32 $2 | highlight 35 $3
    elif [[ $# == 4 ]]; then
      highlight 31 $1 | highlight 32 $2 | highlight 35 $3 | highlight 36 $4
    fi
I also use the comma-command pattern where I prefix my personal scripts with a `,` which allows me to cycle between them fast etc.

One thing I have found that's worth it is periodically running an aggregation on one's history and purging old ones that I don't use.