2

I'm running Aptana studio 3.3.2. The command echo $SHELL outputs /bin/sh. However there is no value for the PS1 environment variable which I would like to inspect. I cannot there is no .bash_profile or .bashrc file but I would like to inspect PS1 environment variable.

This because in Git, when I do a

git init myproject
cd myproject

I get the following prompt

foo/myproject (master)

I cannot figure out how the shell manages to append the (master) string to the directory name found in PS1. After all the directory name is myproject, not "myproject (master)".

Thanks.

As an update, here is my shell:

Neil@NEIL-PC ~
$ echo $SHELL
/bin/sh

Neil@NEIL-PC ~
$ /bin/sh --version
GNU bash, version 3.1.0(3)-release (i686-pc-msys)
Copyright (C) 2005 Free Software Foundation, Inc.

and here is a printout of my environment variables:

Neil@NEIL-PC ~
$ pwd
/c/Users/Neil

Neil@NEIL-PC ~
$ env
HOMEPATH=\Users\Neil
APPDATA=C:\Users\Neil\AppData\Roaming
PROGRAMW6432=C:\Program Files
TERM=cygwin
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
WINDIR=C:\Windows
COMMONPROGRAMW6432=C:\Program Files\Common Files
PUBLIC=C:\Users\Public
PROGRAMDATA=C:\ProgramData
USERDOMAIN=NEIL-PC
COMMONPROGRAMFILES(X86)=C:\Program Files (x86)\Common Files
OS=Windows_NT
ALLUSERSPROFILE=C:\ProgramData
VBOX_INSTALL_PATH=C:\Program Files\Oracle\VirtualBox\
!::=::\
TEMP=/tmp
COMMONPROGRAMFILES=C:\Program Files (x86)\Common Files
COM.ADOBE.VERSIONCUE.CLIENT.APPNAME=AdobeDrive
USERNAME=Neil
PROCESSOR_LEVEL=6
PATH=/c/Users/Neil/bin:.:/usr/local/bin:/mingw/bin:/bin:/c/Users/NeilZanella/AppData/Local/Aptana Studio 3/jre/bin/client:/c/Users/NeilZanella/AppData/Lo
cal/Aptana Studio 3/jre/bin:/c/Users/NeilZanella/AppData/Local/Aptana Studio 3/jre/lib/i386:/c/glassfish3/jdk7/bin:/c/Program Files (x86)/Vim/vim73:/c/Pr
ogram Files/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86)/NVIDIA Co
rporation/PhysX/Common:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/Program Files (x86)/Sony/VA
IO Startup Setting Tool:/c/Program Files (x86)/Windows Live/Shared:/c/Program Files (x86)/Microsoft ASP.NET/ASP.NET Web Pages/v1.0/:/c/Program Files/Micr
osoft SQL Server/110/Tools/Binn/:/c/HashiCorp/Vagrant/bin:/c/Program Files/Microsoft/Web Platform Installer/:/c/Program Files (x86)/Microsoft SQL Server/
100/Tools/Binn/:/c/Program Files/Microsoft SQL Server/100/Tools/Binn/:/c/Program Files/Microsoft SQL Server/100/DTS/Binn/:/c/Program Files (x86)/Microsof
t SQL Server/100/Tools/Binn/VSShell/Common7/IDE/:/c/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE/PrivateAssemblies/:/c/Program Files (x86)
/Microsoft SQL Server/100/DTS/Binn/:/c/Program Files (x86)/Microsoft SQL Server/110/Tools/Binn/:/c/Program Files/Microsoft SQL Server/110/DTS/Binn/:/c/Pr
ogram Files (x86)/Microsoft SQL Server/110/Tools/Binn/ManagementStudio/:/c/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/PrivateAssemblies
/:/c/Program Files (x86)/Microsoft SQL Server/110/DTS/Binn/:/c/Program Files (x86)/QuickTime/QTSystem/:/c/glassfish3/jdk7/bin:/c/Program Files (x86)/Vim/
vim73:/c/Program Files/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86
)/NVIDIA Corporation/PhysX/Common:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/Program Files (x
86)/Sony/VAIO Startup Setting Tool:/c/Program Files (x86)/Windows Live/Shared:/c/Program Files (x86)/Microsoft ASP.NET/ASP.NET Web Pages/v1.0/:/c/Program
 Files/Microsoft SQL Server/110/Tools/Binn/:/c/HashiCorp/Vagrant/bin:/c/Program Files/Microsoft/Web Platform Installer/:/c/Program Files (x86)/Microsoft
SQL Server/100/Tools/Binn/:/c/Program Files/Microsoft SQL Server/100/Tools/Binn/:/c/Program Files/Microsoft SQL Server/100/DTS/Binn/:/c/Program Files (x8
6)/Microsoft SQL Server/100/Tools/Binn/VSShell/Common7/IDE/:/c/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE/PrivateAssemblies/:/c/Program
Files (x86)/Microsoft SQL Server/100/DTS/Binn/:/c/Program Files (x86)/Microsoft SQL Server/110/Tools/Binn/:/c/Program Files/Microsoft SQL Server/110/DTS/
Binn/:/c/Program Files (x86)/Microsoft SQL Server/110/Tools/Binn/ManagementStudio/:/c/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/Privat
eAssemblies/:/c/Program Files (x86)/Microsoft SQL Server/110/DTS/Binn/:/c/Program Files (x86)/QuickTime/QTSystem/:/c/Users/Neil/Desktop/adt-bundle-window
s-x86_64-20130219/sdk/tools:/c/Users/Neil/Desktop/adt-bundle-windows-x86_64-20130219/sdk/platform-tools:/c/Users/NeilZanella/AppData/Local/Aptana Studio
3:.
PSMODULEPATH=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\
FP_NO_HOST_CHECK=NO
INPUTRC=/etc/inputrc
PWD=/c/Users/Neil
SYSTEMDRIVE=C:
PROCESSOR_ARCHITEW6432=AMD64
JAVA_HOME=C:\glassfish3\jdk7
VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
USERPROFILE=C:\Users\Neil
LANG=IT
APTANA_VERSION=3.3.2.1358388697
CM2015DIR=C:\Program Files (x86)\Common Files\Autodesk Shared\Materials\
LOGONSERVER=\\NEIL-PC
PROCESSOR_ARCHITECTURE=x86
LOCALAPPDATA=C:\Users\Neil\AppData\Local
!C:=C:\xampp\htdocs\wordpress392
HOME=/c/Users/Neil
SHLVL=1
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PLINK_PROTOCOL=ssh
HOMEDRIVE=C:
WINDOWS_TRACING_FLAGS=3
WINDOWS_TRACING_LOGFILE=C:\BVTBin\Tests\installpackage\csilogfile.log
MSYSTEM=MINGW32
PROMPT=$P$G
COMSPEC=C:\Windows\system32\cmd.exe
LESS=-FRSX
LOGNAME=Neil
TMP=/tmp
SYSTEMROOT=C:\Windows
PROCESSOR_REVISION=2a07
CONFIGSETROOT=C:\Windows\ConfigSetRoot
MAKE_MODE=unix
PROGRAMFILES=C:\Program Files (x86)
VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
NUMBER_OF_PROCESSORS=4
COM.ADOBE.VERSIONCUE.CLIENT.APPVERSION=1.0.0
COM.ADOBE.VERSIONCUE.CLIENT.APPLOCALE=it_IT
PROGRAMFILES(X86)=C:\Program Files (x86)
SESSIONNAME=Console
GNUPGHOME=/c/Users/Neil/.gnupg
HISTFILE=/c/Users/Neil/.bash_history
COMPUTERNAME=NEIL-PC
OLDPWD=/c/xampp/htdocs/wordpress392
_=/bin/env

Neil@NEIL-PC ~
$ set
!::='::\'
!C:='C:\xampp\htdocs\wordpress392'
ALLUSERSPROFILE='C:\ProgramData'
APPDATA='C:\Users\Neil\AppData\Roaming'
APTANA_VERSION=3.3.2.1358388697
BASH=/usr/bin/sh
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="1" [2]="0" [3]="3" [4]="release" [5]="i686-pc-msys")
BASH_VERSION='3.1.0(3)-release'
CM2015DIR='C:\Program Files (x86)\Common Files\Autodesk Shared\Materials\'
COLUMNS=153
COM.ADOBE.VERSIONCUE.CLIENT.APPLOCALE=it_IT
COM.ADOBE.VERSIONCUE.CLIENT.APPNAME=AdobeDrive
COM.ADOBE.VERSIONCUE.CLIENT.APPVERSION=1.0.0
COMMONPROGRAMFILES='C:\Program Files (x86)\Common Files'
COMMONPROGRAMFILES(X86)='C:\Program Files (x86)\Common Files'
COMMONPROGRAMW6432='C:\Program Files\Common Files'
COMPUTERNAME=NEIL-PC
COMP_WORDBREAKS='
"'\''@><=;|&(:'
COMSPEC='C:\Windows\system32\cmd.exe'
CONFIGSETROOT='C:\Windows\ConfigSetRoot'
DIRSTACK=()
EUID=500
FP_NO_HOST_CHECK=NO
GNUPGHOME=/c/Users/Neil/.gnupg
GROUPS=()
HISTFILE=/c/Users/Neil/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/c/Users/Neil
HOMEDRIVE=C:
HOMEPATH='\Users\Neil'
HOSTNAME=NEIL-PC
HOSTTYPE=i686
IFS='
'
INPUTRC=/etc/inputrc
JAVA_HOME='C:\glassfish3\jdk7'
LANG=IT
LESS=-FRSX
LINES=44
LOCALAPPDATA='C:\Users\Neil\AppData\Local'
LOGNAME=Neil
LOGONSERVER='\\NEIL-PC'
MACHTYPE=i686-pc-msys
MAILCHECK=60
MAKE_MODE=unix
MSYSTEM=MINGW32
NUMBER_OF_PROCESSORS=4
OLDPWD=/c/xampp/htdocs/wordpress392
OPTERR=1
OPTIND=1
OS=Windows_NT
OSTYPE=msys
PATH='/c/Users/Neil/bin:.:/usr/local/bin:/mingw/bin:/bin:/c/Users/NeilZanella/AppData/Local/Aptana Studio 3/jre/bin/client:/c/Users/NeilZanella/AppData/L
ocal/Aptana Studio 3/jre/bin:/c/Users/NeilZanella/AppData/Local/Aptana Studio 3/jre/lib/i386:/c/glassfish3/jdk7/bin:/c/Program Files (x86)/Vim/vim73:/c/P
rogram Files/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86)/NVIDIA C
orporation/PhysX/Common:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/Program Files (x86)/Sony/V
AIO Startup Setting Tool:/c/Program Files (x86)/Windows Live/Shared:/c/Program Files (x86)/Microsoft ASP.NET/ASP.NET Web Pages/v1.0/:/c/Program Files/Mic
rosoft SQL Server/110/Tools/Binn/:/c/HashiCorp/Vagrant/bin:/c/Program Files/Microsoft/Web Platform Installer/:/c/Program Files (x86)/Microsoft SQL Server
/100/Tools/Binn/:/c/Program Files/Microsoft SQL Server/100/Tools/Binn/:/c/Program Files/Microsoft SQL Server/100/DTS/Binn/:/c/Program Files (x86)/Microso
ft SQL Server/100/Tools/Binn/VSShell/Common7/IDE/:/c/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE/PrivateAssemblies/:/c/Program Files (x86
)/Microsoft SQL Server/100/DTS/Binn/:/c/Program Files (x86)/Microsoft SQL Server/110/Tools/Binn/:/c/Program Files/Microsoft SQL Server/110/DTS/Binn/:/c/P
rogram Files (x86)/Microsoft SQL Server/110/Tools/Binn/ManagementStudio/:/c/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/PrivateAssemblie
s/:/c/Program Files (x86)/Microsoft SQL Server/110/DTS/Binn/:/c/Program Files (x86)/QuickTime/QTSystem/:/c/glassfish3/jdk7/bin:/c/Program Files (x86)/Vim
/vim73:/c/Program Files/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x8
6)/NVIDIA Corporation/PhysX/Common:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/Program Files (
x86)/Sony/VAIO Startup Setting Tool:/c/Program Files (x86)/Windows Live/Shared:/c/Program Files (x86)/Microsoft ASP.NET/ASP.NET Web Pages/v1.0/:/c/Progra
m Files/Microsoft SQL Server/110/Tools/Binn/:/c/HashiCorp/Vagrant/bin:/c/Program Files/Microsoft/Web Platform Installer/:/c/Program Files (x86)/Microsoft
 SQL Server/100/Tools/Binn/:/c/Program Files/Microsoft SQL Server/100/Tools/Binn/:/c/Program Files/Microsoft SQL Server/100/DTS/Binn/:/c/Program Files (x
86)/Microsoft SQL Server/100/Tools/Binn/VSShell/Common7/IDE/:/c/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE/PrivateAssemblies/:/c/Program
 Files (x86)/Microsoft SQL Server/100/DTS/Binn/:/c/Program Files (x86)/Microsoft SQL Server/110/Tools/Binn/:/c/Program Files/Microsoft SQL Server/110/DTS
/Binn/:/c/Program Files (x86)/Microsoft SQL Server/110/Tools/Binn/ManagementStudio/:/c/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/Priva
teAssemblies/:/c/Program Files (x86)/Microsoft SQL Server/110/DTS/Binn/:/c/Program Files (x86)/QuickTime/QTSystem/:/c/Users/Neil/Desktop/adt-bundle-windo
ws-x86_64-20130219/sdk/tools:/c/Users/Neil/Desktop/adt-bundle-windows-x86_64-20130219/sdk/platform-tools:/c/Users/NeilZanella/AppData/Local/Aptana Studio
 3:.'
PATHEXT='.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC'
PIPESTATUS=([0]="0")
PLINK_PROTOCOL=ssh
POSIXLY_CORRECT=y
PPID=1
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
PROCESSOR_IDENTIFIER='Intel64 Family 6 Model 42 Stepping 7, GenuineIntel'
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=2a07
PROGRAMDATA='C:\ProgramData'
PROGRAMFILES='C:\Program Files (x86)'
PROGRAMFILES(X86)='C:\Program Files (x86)'
PROGRAMW6432='C:\Program Files'
PROMPT='$P$G'
PS1='\[\033]0;$MSYSTEM:\w\007
\033[32m\]\u@\h \[\033[33m\w$(__git_ps1)\033[0m\]
$ '
PS2='> '
PS4='+ '
PSMODULEPATH='C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\'
PUBLIC='C:\Users\Public'
PWD=/c/Users/Neil
SESSIONNAME=Console
SHELL=/bin/sh
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor:posix
SHLVL=1
SYSTEMDRIVE=C:
SYSTEMROOT='C:\Windows'
TEMP=/tmp
TERM=cygwin
TMP=/tmp
UID=500
USERDOMAIN=NEIL-PC
USERNAME=Neil
USERPROFILE='C:\Users\Neil'
VBOX_INSTALL_PATH='C:\Program Files\Oracle\VirtualBox\'
VS110COMNTOOLS='C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\'
VS120COMNTOOLS='C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\'
WINDIR='C:\Windows'
WINDOWS_TRACING_FLAGS=3
WINDOWS_TRACING_LOGFILE='C:\BVTBin\Tests\installpackage\csilogfile.log'
_=env
__git_all_commands=
__git_diff_common_options='--stat --numstat --shortstat --summary
                        --patch-with-stat --name-only --name-status --color
                        --no-color --color-words --no-renames --check
                        --full-index --binary --abbrev --diff-filter=
                        --find-copies-harder
                        --text --ignore-space-at-eol --ignore-space-change
                        --ignore-all-space --exit-code --quiet --ext-diff
                        --no-ext-diff
                        --no-prefix --src-prefix= --dst-prefix=
                        --inter-hunk-context=
                        --patience
                        --raw
                        --dirstat --dirstat= --dirstat-by-file
                        --dirstat-by-file= --cumulative
'
__git_fetch_options='
        --quiet --verbose --append --upload-pack --force --keep --depth=
        --tags --no-tags --all --prune --dry-run
'
__git_log_common_options='
        --not --all
        --branches --tags --remotes
        --first-parent --merges --no-merges
        --max-count=
        --max-age= --since= --after=
        --min-age= --until= --before=
'
__git_log_date_formats='relative iso8601 rfc2822 short local default raw'
__git_log_gitk_options='
        --dense --sparse --full-history
        --simplify-merges --simplify-by-decoration
        --left-right
'
__git_log_pretty_formats='oneline short medium full fuller email raw format:'
__git_log_shortlog_options='
        --author= --committer= --grep=
        --all-match
'
__git_merge_options='
        --no-commit --no-stat --log --no-log --squash --strategy
        --commit --stat --no-squash --ff --no-ff --ff-only
'
__git_merge_strategies=
__git_mergetools_common='diffuse ecmerge emerge kdiff3 meld opendiff
                        tkdiff vimdiff gvimdiff xxdiff araxis p4merge
'
__git_porcelain_commands=
__git_send_email_confirm_options='always never auto cc compose'
__git_send_email_suppresscc_options='author self cc bodycc sob cccmd body all'
__git_whitespacelist='nowarn warn error error-all fix'
i='/etc/profile.d/*.sh'

Neil@NEIL-PC ~
$

The variables of interest seem to be:

PROMPT=$P$G

PS1='[\033]0;$MSYSTEM:\w\007 \033[32m]\u@\h [\033[33m\w$(__git_ps1)\033[0m] $ ' PS2='> ' PS4='+ '

Can someone explain how these variables interact? What is $G and $(__git_ps1) ?

Thanks.

3

I don't know anything about Aptana Studio specifically, but there are various mechanisms that can influence the shell prompt. I assume you're using Bash as you mentioned .bash_profile and .bashrc.

The simplest mechanism is to set the PS1 variable (supported by most shells, even straight POSIX ones like dash), which doesn't necessarily need to be an environment variable. There are various escape sequences you can put in it to print information as part of the prompt. To inspect PS1, simply run the following:

echo $PS1

However, I don't know of any sequences that, by themselves, can be used to print the current Git branch (master).

There is also a PROMPT_COMMAND variable that specifies a function to run before the prompt is displayed; this function can be used to generate an arbitrary prompt. Here's an example implementation of the behavior you describe:

foobar() {
    local branch
    branch=$(git branch 2>/dev/null | grep '^*') || branch='?'
    branch=${branch##* }
    # \w: current working directory
    PS1="\\w ($branch) "
}
PROMPT_COMMAND=foobar

There are a number of files that Bash will read at startup:

  • /etc/profile
  • ~/.bash_profile
  • ~/.bashrc
  • ~/.profile
  • any file specified using --rcfile

Any of these might be responsible for setting the prompt. Aptana Studio probably provides a custom startup file.

You can find out more about prompting in the "Prompting" section of the Bash man page.

Update

In the PS1 value that you provided, $(__git_ps1) is a substitution (per standard Bash command substitution syntax, but expanded when used rather than when defined) that will be expanded to the output of the __git_ps1 command. You can find out what that is like so:

type -a __git_ps1

If it's a function or alias, its definition will be printed. If it's an executable, its path will be shown.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.