FallenAngel
FallenAngel

Reputation: 67

Git top level dir Name

I am trying to retrieve the top level dir name but the $GIT var is returning empty? this is for git integration in the terminal.

function root_func() {
    GIT="git rev-parse --is-inside-work-tree"
    if [[ $GIT =~ "True" ]]; then
    git rev-parse --show-toplevel | awk 'BEGIN{FS="/"}{print $(NF-0)}'
    fi  }

Upvotes: 1

Views: 80

Answers (1)

mipadi
mipadi

Reputation: 411012

GIT="git rev-parse --is-inside-work-tree"

That's just setting GIT to a string. I think you actually want

GIT=$(git rev-parse --is-inside-work-tree)

You can also do this pretty easily as a one-liner:

git rev-parse --is-inside-work-tree >/dev/null 2>&1 && basename $(git rev-parse --show-toplevel)

Upvotes: 3

Related Questions