Skip to content

Instantly share code, notes, and snippets.

@creade
Created November 21, 2012 03:31
Show Gist options
  • Save creade/4122834 to your computer and use it in GitHub Desktop.
Save creade/4122834 to your computer and use it in GitHub Desktop.
selfDoc
#!/bin/sh
cat <<EOT >doced
#!/bin/sh
printCut() {
while IFS= read -t 1 piped
do
my_array=("\${my_array[@]}" "\$piped")
done
printed=0
for i in "\${my_array[@]}"
do
if [ \$printed == 0 ]
then
echo \$@ 1>&2
printed=1
fi
echo "\$i" 1>&2
done
for j in "\${my_array[@]}"
do
echo "\$j"
done
}
EOT
cat $@ | grep -Ev '#!/bin/sh' |
sed 's/\(cut [^|]*\)/ \1 | printCut "Using { \1 }"/g'|
sed 's/\(awk [^|]*\)/ \1 | printCut "Using { \1 }"/g'|
sed 's/\(grep [^|]*\)/ \1 | printCut "Using { \1 }"/g'|
sed 's/\(sort [^|]*\)/ \1 | printCut "Using { \1 }"/g'|
sed 's/tee \/dev\/tty/printCut "teeing"/g' |
perl -pi -e "s/(sed.*?(').*?(').*?([^|]*))/ \1 | printCut \"Using { \1 }\" /g"|
perl -pi -e "s/(perl.*?(').*?(').*?([^|]*))/ \1 | printCut \"Using { \1 }\" /g" >> doced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment