我正在运行 Aptana studio 3.3.2。命令 echo$SHELL
输出/bin/sh
。但是PS1
,我想检查的环境变量没有值。我不能没有.bash_profile
文件.bashrc
,但我想检查PS1
环境变量。
这是因为在 Git 中,当我执行
git init myproject
cd myproject
我收到以下提示
foo/myproject (master)
我无法弄清楚 shell 如何设法将(主)字符串附加到PS1
.毕竟目录名称是myproject,而不是“ myproject (master)
”。
谢谢。
作为更新,这是我的外壳:
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.
这是我的环境变量的打印输出:
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 ~
$
感兴趣的变量似乎是:
提示=$P$G
PS1='[\033]0;$MSYSTEM:\w\007\033[32m]\u@\h [\033[33m\w$(__git_ps1)\033[0m] $ ' PS2='> ' PS4 ='+'
有人能解释一下这些变量如何相互作用吗?什么是 $G 和 $(__git_ps1) ?
谢谢。
答案1
我对 Aptana Studio 不太了解,但有多种机制可以影响 shell 提示符。我假设您正在使用 Bash,正如您提到的.bash_profile
和.bashrc
。
最简单的机制是设置PS1
变量(大多数 shell 都支持,甚至像 POSIX shell 这样的 shell dash
),它不一定是环境变量。您可以在其中放入各种转义序列来打印信息作为提示的一部分。要检查PS1
,只需运行以下命令:
echo $PS1
但是,我不知道有任何序列本身可以用来打印当前的 Git 分支 ( master
)。
还有一个PROMPT_COMMAND
变量指定在显示提示之前要运行的函数;该函数可用于生成任意提示。这是您所描述的行为的示例实现:
foobar() {
local branch
branch=$(git branch 2>/dev/null | grep '^*') || branch='?'
branch=${branch##* }
# \w: current working directory
PS1="\\w ($branch) "
}
PROMPT_COMMAND=foobar
Bash 在启动时会读取许多文件:
/etc/profile
~/.bash_profile
~/.bashrc
~/.profile
- 使用指定的任何文件
--rcfile
其中任何一个都可能负责设置提示。 Aptana Studio 可能提供自定义启动文件。
您可以在“提示”部分找到有关提示的更多信息。Bash 手册页。
更新
在PS1
您提供的值中,$(__git_ps1)
有一个替换(按照标准 Bash 命令替换语法,但在使用时而不是在定义时扩展),它将扩展为命令的输出__git_ps1
。你可以这样了解它是什么样的:
type -a __git_ps1
如果它是函数或别名,则会打印其定义。如果它是可执行文件,则会显示其路径。