Skip to content

Instantly share code, notes, and snippets.

@exupero
Last active February 29, 2016 12:57
Show Gist options
  • Save exupero/73dcd2e15085203563c0 to your computer and use it in GitHub Desktop.
Save exupero/73dcd2e15085203563c0 to your computer and use it in GitHub Desktop.
instruct

instruct

A shell script to give step-by-step instructions. Pipe text into it. It'll be processed as follows:

  • Each line is echoed back to you one at a time.
  • Hit the Enter key to see the next instruction.
  • Lines surrounded by triple backticks are copied to the system clipboard, and the next line of text has the icon next to it.
  • Blank lines are ignored.
  • To insert a blank line, use a triple dash (---).

OS X only, due to pbcopy, but easily adapted to other Unix systems.

Lines are shown one at a time. Press Enter to see the next line.
Blank lines are ignored.
---
Use --- to show a blank line.
```
Some text
```
Something is now on the clipboard.
#!/bin/bash
pause() {
{
stty -echo
read
stty echo
} < /dev/tty
}
isCode() {
echo "$1" | grep -q '```'
test "$?" -eq "0"
}
isBreak() {
echo "$1" | grep -q '^\-\-\-$'
test "$?" -eq "0"
}
isNonBlank() {
echo "$1" | grep -qv '^$'
test "$?" -eq "0"
}
hasPaste=0
while read line; do
isCode "$line" && {
while read line; do
isCode "$line" && break
echo "$line"
done | pbcopy
hasPaste=1
continue
}
isBreak "$line" && {
echo ""
continue
}
isNonBlank "$line" && {
if [ $hasPaste -eq 1 ]; then
echo "↪ $line"
else
echo " $line"
fi
hasPaste=0
pause
continue
}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment