Git Aptana StudioのCygwin端末でシェルプロンプトを変更するには?

Git Aptana StudioのCygwin端末でシェルプロンプトを変更するには?

私はAptana studio 3.3.2を実行しています。コマンドエコー$SHELL出力/bin/sh。ただし、PS1確認したい環境変数に値がありません。.bash_profileファイルがなければできませんが、環境変数を.bashrc確認したいです。PS1

これはGitで実行するとき

git init myproject
cd myproject

次のプロンプトが表示されます。

foo/myproject (master)

シェルが(デフォルト)文字列をどのように管理しているかわかりませんPS1。結局のところ、ディレクトリ名は " myproject (master)"ではなくmyprojectです。

ありがとうございます。

アップデートとして、これは私のシェルです。

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についてはよくわかりませんが、シェルプロンプトに影響を与える可能性があるいくつかのメカニズムがあります。私はあなたが言及したようにBashを使用していると仮定し.bash_profileます.bashrc

最も簡単なメカニズムは、PS1変数(POSIXシェルなどのシェルを含むほとんどのシェルでサポートされています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はカスタム起動ファイルを提供できます。

ヒントセクションでは、ヒントの詳細を確認できます。バッシュのマニュアルページ

修正する

PS1指定された値には、$(__git_ps1)コマンドの出力に拡張される置換(標準のBashコマンドの代替構文に従いますが、定義するのではなく使用時の拡張)があります__git_ps1。次の様子がわかります。

type -a __git_ps1

関数またはエイリアスの場合、その定義が印刷されます。実行可能ファイルの場合は、そのパスが表示されます。

おすすめ記事