-
-
Save jbedo/4107973 to your computer and use it in GitHub Desktop.
Acme script for adding/removing comments (from 9fans)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rc | |
fn f { | |
n=$1 | |
if(! cat $f | cut -c1-$n | 9 grep -v '^[ ]+$' >/dev/null){ | |
x=`{f `{expr $n + 1}} | |
echo '.'$"x | |
} | |
} | |
f=/tmp/com.$pid | |
cat >$f | |
switch($%){ | |
case *.go *.c | |
c='//' | |
case *.tex | |
c='%' | |
case * | |
c='#' | |
} | |
# Remove comment? | |
if(cat $f | 9 grep '^[ ]*'$c' ' >/dev/null){ | |
cat $f | 9 sed 's|'$c' ||' | |
rm $f | |
exit | |
} | |
# Add comment. | |
s=`{f 1} | |
if(~ $#s 0) | |
cat $f | 9 sed 's|^|'$c' |' | |
if not | |
cat $f | 9 sed 's|^('$"s')|\1'$c' |' | |
rm $f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment