Browse Source

bin: add `x` helper to run commands using the top-level ./run.sh of a repo workspace

Signed-off-by: Alejandro Mery <amery@geeks.cl>
master
Alejandro Mery 5 years ago
parent
commit
ee84fa6388
1 changed files with 29 additions and 0 deletions
  1. +29
    -0
      files/bin/x

+ 29
- 0
files/bin/x

@ -0,0 +1,29 @@
#!/bin/sh
set -eu
# find root of the "workspace"
find_repo_workspace_root() {
if [ -d "$1/.repo" ]; then
echo "$1"
elif [ "${1:-/}" != / ]; then
find_repo_workspace_root "${1%/*}"
fi
}
WS="$(find_repo_workspace_root "$PWD")"
if [ -z "$WS" ]; then
# find root of .git repository
WS="$(git rev-parse --show-superproject-working-tree 2> /dev/null || true)"
[ -d "$WS" ] || WS="$(git rev-parse --show-toplevel 2> /dev/null || true)"
fi
if [ -d "$WS" ]; then
if [ -x "$WS/run.sh" ]; then
exec "$WS/run.sh" "$@"
fi
fi
if [ "$#" -gt 0 ]; then
exec "$@"
fi

Loading…
Cancel
Save