Skip to content

Instantly share code, notes, and snippets.

@hryamzik
Created March 29, 2016 13:24
Show Gist options
  • Save hryamzik/e216a0493e6e5e64b1ef to your computer and use it in GitHub Desktop.
Save hryamzik/e216a0493e6e5e64b1ef to your computer and use it in GitHub Desktop.
#!/bin/bash
read line
role=$(echo "$line"|/usr/local/bin/sed -E 's/^\s*-\s*\{?\s*(role:\s)?([a-zA-Z0-9_+-\/]+)($|,.*)/\2/')
testpath="$TM_DIRECTORY"
function testPath {
if test -d "$1/$role"
then
echo "$1/$role"
elif test -d "$1/roles/$role"
then
echo "$1/roles/$role"
fi
}
function openRole {
echo "$1"
if test -f "$1/tasks/main.yml"
then
mate "$1/tasks/main.yml"
else
mate "$1"
fi
}
rolepath="$(testPath "$testpath" )"
test -z "$rolepath" || openRole "$(/usr/local/opt/coreutils/libexec/gnubin/realpath "$rolepath")"
echo $role
echo "$TM_DIRECTORY"|grep -o '/'|while read _ && test -z "$rolepath"
do
testpath="$testpath/../"
rolepath="$(testPath "$testpath" )"
test -z "$rolepath" || openRole "$(/usr/local/opt/coreutils/libexec/gnubin/realpath "$rolepath")"
done
@hryamzik
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment