I needed to get my OPENAPI key for use in gsheets, it’s in my env, here’s how to do it in a 1 liner
env | grep OPENAI_API | cut -d '=' -f 2 | pbcopy
# EDIT, this is a great pipeline for teaching, but my reader George points out env variables are variables, so we can simplify this to:
echo $OPEN_API_KEY | pbcopy
env gets all environment variables
LANGUAGE=en_US
I3SOCK=/run/user/1000/i3/ipc-socket.3145
MANDATORY_PATH=/usr/share/gconf/i3.mandatory.path
OPENAI_API_KEY=MY_KEY
DESKTOP_SESSION=i3
XTERM_SHELL=/bin/bash
EDITOR=vim
GTK_MODULES=gail:atk-bridge
XDG_SEAT=seat0
XDG_SESSION_DESKTOP=i3
grep selects OPEN_API
OPENAI_API_KEY=MY_KEY
Cut splits by = and selects the 2nd (1 index)
MY_KEY
and pbcopy puts it into my clipboard where I paste it from in chrome.
Happy hacking
instead of parsing the env output. how about having the shell do it for you.
echo $OPENAI_API | pbcopy
Nice! I always use:
```
tr '=' '\t' | awk '{print $2}'
```
I'll try to use `cut` more 😀