mirror of
https://github.com/notwa/rc
synced 2024-11-05 02:49:02 -08:00
Connor Olding
d35c492850
* use /usr/bin/env for all hashbangs * enable hashall for bash * workaround syntax error in -shrc for bash
48 lines
904 B
Bash
48 lines
904 B
Bash
#!/usr/bin/env sh
|
|
# the first expression is taken from this FAQ:
|
|
# https://perldoc.perl.org/perlfaq6.html#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file%3f
|
|
noccom() {
|
|
[ -s ~/opt/local/bin/noccom ] || cat > ~/opt/local/bin/noccom <<EOF
|
|
#!/usr/bin/env perl
|
|
|
|
\$/ = undef;
|
|
\$_ = <>;
|
|
|
|
s{
|
|
/\\*[^*]*\\*+([^/*][^*]*\\*+)*/
|
|
|
|
|
//([^\\\\]
|
|
|
|
|
[^\\n][\\n]?)*?\\n
|
|
|
|
|
(
|
|
"(?:\\\\.|[^"\\\\])*"
|
|
|
|
|
'(?:\\\\.|[^'\\\\])*'
|
|
|
|
|
.[^/"'\\\\]*
|
|
)
|
|
}{defined \$3 ? \$3 : ""}gxse;
|
|
|
|
s{
|
|
\\\\?\\n\\s*([{}])?\\s*(;*)\\s*(?=\\\\?\\n)
|
|
|
|
|
(
|
|
\\#[^\\n]*\\n
|
|
|
|
|
"(?:\\\\.|[^"\\\\])*"
|
|
|
|
|
'(?:\\\\.|[^'\\\\])*'
|
|
|
|
|
.[^#/"'\\\\\\n]*
|
|
)
|
|
}{defined \$3 ? \$3 : (defined \$1 ? " ".\$1.\$2 : \$2)}gxse;
|
|
|
|
s#(^|\\n)\\s+#\$1#gs;
|
|
|
|
print;
|
|
EOF
|
|
|
|
perl ~/opt/local/bin/noccom "$@"
|
|
}
|
|
noccom "$@"
|