11

Let's say you opened a Git Bash console and used it for a time but you forgot if you opened it as Administrator or not.

Is there a way to check this in the current console, without closing and opening it again?

Samurai Jack
  • 2,633
  • 6
  • 33
  • 54
  • Why would you open Git Bash as an administrator in the first place? – 1615903 Apr 27 '17 at 09:56
  • 7
    Run `env | grep SESSIONNAME`. If it's run as Administrator, the command returns nothing. If not, it returns `SESSIONNAME=Console`. But this is just what I have observed from tests. I am not sure if this is the difference caused by running as or not as administrator. I have no idea what SESSIONNAME means. – ElpieKay Apr 27 '17 at 14:23
  • @ElpieKay you may be right – Samurai Jack Apr 27 '17 at 14:29

4 Answers4

11

Adapted from the thread on how to check for admin rights, run the following:

if [[ $(sfc 2>&1 | tr -d '\0') =~ SCANNOW ]]; then echo Administrator; else echo $USERNAME; fi

If you are running git-bash as Administrator, it will print Administrator, otherwise it will print your username.

KyleMit
  • 35,223
  • 60
  • 418
  • 600
daveloyall
  • 1,915
  • 20
  • 23
0

My PS1 environmental variable looks like this:

\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$

So off the back of the answer from @daveloyall. I've put this into my .bash_profile

if [[ $(sfc 2>&1 | tr -d '\0') =~ SCANNOW ]]; then
    export TITLEPREFIX='ADMIN' 
fi

This then prefixes the window title with ADMIN if you've opened git-bash as administrator.

-3

You can try a linux command, like that:

whoami

This will return your system username

or windows command:

ECHO %USERNAME%
Zepp
  • 38
  • 4
  • 4
    But it returns the same result whether you are running git bash as Administrator or not... – pgras Jan 30 '18 at 12:05
-4

Yes, You can check the current username by using this command:

git config user.name

This will return the username and you can know if it is the Administrator.