Commit a218d7e9 authored by iannucci@chromium.org's avatar iannucci@chromium.org

Add bash shell function to make python work like it should.

This uses the virtual /proc filesystem to identify when the user runs
`python` without redirecting stdout/stdin. If this is the case, we run
`python -i` instead. Otherwise, or if there are arguments, we run it
verbatim.

R=dnj@chromium.org
BUG=598956

Review URL: https://codereview.chromium.org/1851113003 .

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299681 0039d316-1c4b-4281-b951-d872f2087c98
parent 3466b0d6
#!/bin/bash
# This alias allows invocations of `python` to work as expected under msys bash.
# In particular, it detects if stdout+stdin are both attached to a pseudo-tty,
# and if so, invokes python in interactive mode. If this is not the case, or
# the user passes any arguments, python will be invoked unmodified.
python() {
if [[ $# > 0 ]]; then
python.exe "$@"
else
readlink /proc/$$/fd/0 | grep pty > /dev/null
TTY0=$?
readlink /proc/$$/fd/1 | grep pty > /dev/null
TTY1=$?
if [ $TTY0 == 0 ] && [ $TTY1 == 0 ]; then
python.exe -i
else
python.exe
fi
fi
}
......@@ -100,6 +100,7 @@ for %%f in (git.bat gitk.bat ssh.bat ssh-keygen.bat git-bash) do (
%FIND_EXE% "%GIT_BIN_DIR%" "%WIN_TOOLS_ROOT_DIR%\%%f" 2>nul 1>nul
if errorlevel 1 goto :GIT_MAKE_BATCH_FILES
)
if not exist %GIT_INST_DIR%\etc\profile.d\python.sh goto :GIT_MAKE_BATCH_FILES
goto :SYNC_GIT_HELP_FILES
:GIT_INSTALL
......@@ -138,6 +139,7 @@ call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/cmd\\\\gitk.ex
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh-keygen.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh-keygen.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/PYTHON_BIN_DIR/python276_bin/g" -e "s/SVN_BIN_DIR/svn_bin/g" < %~dp0git-bash.template.sh > "%WIN_TOOLS_ROOT_DIR%\git-bash"
copy "%~dp0profile.d.python.sh" %GIT_INST_DIR%\etc\profile.d\python.sh > NUL
:: Ensure various git configurations are set correctly at they system level.
call "%WIN_TOOLS_ROOT_DIR%\git.bat" config --system core.autocrlf false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment