Skip to content

Instantly share code, notes, and snippets.

Last active June 7, 2020 11:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Shows the `awesomecsv` list by using `ok-bash` in the terminal (and navigate to these links too)
#!/usr/bin/env bash
# Unofficial Bash Strict Mode
set -euo pipefail
# import ok
if [[ -r "$_OK__PATH_TO_ME/" ]]; then
. "$_OK__PATH_TO_ME/" prompt '=> ' prompt_default
function to_ok_format {
python -c "import codecs, csv, sys
def ansi_format(start, text, end): return '\x1B[{}m{}\x1B[{}m'.format(start, text, end)
def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
# doesn't do Unicode; encode temporarily as UTF-8:
csv_reader = csv.reader( [line.encode('utf-8') for line in unicode_csv_data],
dialect=dialect, **kwargs)
for row in csv_reader:
# decode UTF-8 back to Unicode, cell by cell:
yield [unicode(cell, 'utf-8') for cell in row]
sys.stdin = codecs.getreader('utf_8')(sys.stdin)
sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
sys.stderr = codecs.getwriter('utf_8')(sys.stderr)
csv_reader = unicode_csv_reader(sys.stdin)
last_header = ''
for row in csv_reader:
if last_header != row[0]:
last_header = row[0]
print '# %s' % row[0]
# opens URL from command line; see for other OS's:
print 'open %s # %s: %s' % (row[2], ansi_format('4', row[1], '24'), row[3])
# Fetch CSV, remove heading (1st line), prepend awesome URL's to the list, rewrite it to .ok-format, and stream it to OK
FIRST_LINES=$',AwesomeCSV,,🕶️ A curated list of awesome tools for dealing with awesome CSV (here are links below stored)
,a-w-e-s-o-m-e,,😎 Curated list of awesome lists
curl -s -f | sed '1d' | cat <(printf "$FIRST_LINES") - | to_ok_format | ok -f - "$@"
#naive implementation (doesn't work well with quoted strings including comma's)
#curl -s | sed -e 1d | awk -F ',' '{if(last_cat!=$1) { print "# " $1; last_cat=$1;} print "open " $3 " # " $2;}' | ok -f - "$@"
# Requires:
# Gist:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment