Skip to content

Instantly share code, notes, and snippets.

@navilan
Last active December 16, 2015 03:44
Show Gist options
  • Save navilan/0671812f042fd2049a84 to your computer and use it in GitHub Desktop.
Save navilan/0671812f042fd2049a84 to your computer and use it in GitHub Desktop.
#!/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
}
#! /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
# 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
#!/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
}
#! /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