Comma command: Difference between revisions

From Rest of What I Know
Created page with "A while ago, someone on HN or Lobste.rs suggested the idea of having your custom commands be prefixed by a <code>,</code> 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 a..."
 
Fix source
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
A while ago, someone on HN or Lobste.rs suggested the idea of having your custom commands be prefixed by a <code>,</code> and I started doing that a while ago.
A while ago, [https://rhodesmill.org/brandon/2009/commands-with-comma/ I read about this idea of having your custom commands be prefixed by a <code>,</code>] 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.
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.
Line 48: Line 48:
fi
fi
</syntaxhighlight>
</syntaxhighlight>
== <code>,ijq</code> ==
From [https://dev.to/pbnj/fzf-jq-interactive-jq-15no this interactive jq with fzf post]:
<syntaxhighlight lang=bash>
#!/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}"
</syntaxhighlight>
Quoters of UUOC be damned
[[Category:Programming]] [[Category:Tips]]

Latest revision as of 03:29, 24 June 2024

A while ago, I read about this 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[edit]

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[edit]

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[edit]

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