Last active
December 16, 2015 03:44
-
-
Save navilan/0671812f042fd2049a84 to your computer and use it in GitHub Desktop.
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 awk -f | |
function rel2abs(req, dir, root) | |
{ | |
"readlink --canonicalize " root|getline res | |
"sh -c \"cd " dir " && readlink --canonicalize " req "\""|getline resolved | |
gsub(res, "", resolved) | |
gsub(/^\//,"", resolved) | |
return resolved | |
} | |
{ | |
qs="('|\")" | |
if (match($0, "require\\s+" qs "(\\..*)" qs, m) != 0) | |
{ | |
sub (/require (.*)/, "require '" rel2abs(m[2], DIR, ROOT) "'") | |
} | |
print $0 | |
} |
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 sh | |
ROOT=$(readlink --canonicalize ${1}) | |
TOFIX=$(readlink --canonicalize ${2}) | |
DIR=$(dirname $TOFIX) | |
awk -i inplace -v DIR="$DIR" -v ROOT="$ROOT" -f $(dirname $0)/req2abs.awk $TOFIX |
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
# To run the scripts (example): | |
ag --coffee "require" | xargs -n 1 req2abs.sh assets/source | |
ag --sass "url" | xargs -n 1 url2abs.sh assets/source |
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 awk -f | |
function rel2abs(req, dir, root) | |
{ | |
"readlink --canonicalize " root|getline res | |
"sh -c \"cd " dir " && readlink --canonicalize " req "\""|getline resolved | |
gsub(res, "", resolved) | |
gsub(/^\//,"", resolved) | |
return resolved | |
} | |
{ | |
if (match($0, "url\\s*\\((\\.[^)]*)\\)", m) != 0) | |
{ | |
sub (/url\s*([^)]*))/, "url(" rel2abs(m[1], DIR, ROOT) ")") | |
} | |
print $0 | |
} |
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 sh | |
ROOT=$(readlink --canonicalize ${1}) | |
TOFIX=$(readlink --canonicalize ${2}) | |
DIR=$(dirname $TOFIX) | |
awk -i inplace -v DIR="$DIR" -v ROOT="$ROOT" -f $(dirname $0)/url2abs.awk $TOFIX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment