aboutsummaryrefslogtreecommitdiff
path: root/.config/vis/plugins/vis-lspc/tools/find-upwards
blob: 85dc7222bd8ff8c22eb1a33f0da3336a1e21c081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh

set -eu

if [ ! "${1:-}" ]; then
    exit 1
fi

BASEDIR="$(dirname "$1")"

while read -r glob; do
    cd "$BASEDIR"

    while [ "$PWD" != "/" ]; do
        set -- "$glob"

        if [ -e "$1" ]; then
            echo "$PWD"
            exit 0
        fi

        cd ..
    done
done

exit 1