Comma command
A while ago, someone on HN or Lobste.rs suggested the idea of having your custom commands be prefixed by a ,
and I started doing that a while ago.
The comma-prefixed list of commands is empty. There's no standard command that does this, so it's an easy way to get autocomplete for your local commands. Also, you can just use one or two characters and not interfere with other things.
Sometimes, I use these instead of aliases and other times just for short scripts. Many of these are cobbled together from other sources.
I usually store them in ~/bin
and make sure that directory is in my PATH
and then that's it!
,dehex
Used to convert hex characters into their ASCII text values.
Use as: echo "6162636465660a" | ,dehex
#!/usr/bin/env bash
echo "$1" | xxd -r -p
,ht
Used to highlight one or two words. Sometimes I want to grep
for something and then I want to highlight a few characters.
Use as: echo "words I care about" | ,ht words care
#!/usr/bin/env bash
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
,ijq
From this interactive jq with fzf post:
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <file>"
exit 1
fi
filepath=$1
pathway="cat $filepath"
if [[ $filepath == *.gz ]]; then
pathway="zcat $filepath"
fi
echo '' | fzf-tmux -p '80%' --print-query --preview "$pathway | jq {q}"
Quoters of UUOC be damned