diff options
| author | ruki <[email protected]> | 2021-08-25 06:34:15 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-25 06:34:15 +0800 |
| commit | a483cecba3feb404388099ccc8bdb32e6382102c (patch) | |
| tree | 4def16435b92dd065fd54bf74ea8de66989e7863 /scripts | |
| parent | dbd66858b8b68a784c415557e8958650e3d638c1 (diff) | |
| parent | 65cd1d83d3f61415607b8976e7b5c215b67e42a8 (diff) | |
Merge pull request #1604 from xq114/dev
improve virtualenv on linux
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/get.sh | 9 | ||||
| -rw-r--r-- | scripts/register-virtualenvs.sh | 48 | ||||
| -rwxr-xr-x | scripts/xrepo.bat | 6 |
3 files changed, 59 insertions, 4 deletions
diff --git a/scripts/get.sh b/scripts/get.sh index 8363b4499..f64ff8041 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -227,13 +227,20 @@ write_profile() install_profile() { if [ ! -d ~/.xmake ]; then mkdir ~/.xmake; fi - echo "export PATH=$prefix/bin:\$PATH" > ~/.xmake/profile + echo "export XMAKE_ROOTDIR=\"$prefix/bin\"" > ~/.xmake/profile + echo 'export PATH="$XMAKE_ROOTDIR:$PATH"' >> ~/.xmake/profile if [ -f "$projectdir/scripts/register-completions.sh" ]; then cat "$projectdir/scripts/register-completions.sh" >> ~/.xmake/profile else remote_get_content "$gitrepo_raw/scripts/register-completions.sh" >> ~/.xmake/profile fi + if [ -f "$projectdir/scripts/register-virtualenvs.sh" ]; then + cat "$projectdir/scripts/register-virtualenvs.sh" >> ~/.xmake/profile + else + remote_get_content "$gitrepo_raw/scripts/register-virtualenvs.sh" >> ~/.xmake/profile + fi + if [[ "$SHELL" = */zsh ]]; then write_profile ~/.zshrc elif [[ "$SHELL" = */ksh ]]; then diff --git a/scripts/register-virtualenvs.sh b/scripts/register-virtualenvs.sh new file mode 100644 index 000000000..700d8dd99 --- /dev/null +++ b/scripts/register-virtualenvs.sh @@ -0,0 +1,48 @@ + +# virtual environments for *nix shell + +if test "${XMAKE_ROOTDIR}"; then + export XMAKE_EXE=${XMAKE_ROOTDIR}/xmake +else + export XMAKE_EXE=xmake +fi + +function xrepo { + if [ $# -eq 2 ] && [ "$1" = "env" ]; then + local cmd="${2-x}" + case "$cmd" in + shell) + if test "${XMAKE_PROMPT_BACKUP}"; then + PS1="${XMAKE_PROMPT_BACKUP}" + source "${XMAKE_ENV_BACKUP}" || return 1 + unset XMAKE_PROMPT_BACKUP + unset XMAKE_ENV_BACKUP + fi + "$XMAKE_EXE" lua private.xrepo.action.env.info config || return 1 + local prompt="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info prompt)" || return 1 + if [ -z "${prompt+x}" ]; then + return 1 + fi + local activateCommand="$("$XMAKE_EXE" lua private.xrepo.action.env.info script.bash)" || return 1 + export XMAKE_ENV_BACKUP="$("$XMAKE_EXE" lua private.xrepo.action.env.info envfile)" + export XMAKE_PROMPT_BACKUP="${PS1}" + "$XMAKE_EXE" lua private.xrepo.action.env.info backup.bash 1>"$XMAKE_ENV_BACKUP" + eval "$activateCommand" + PS1="${prompt} $PS1" + ;; + quit) + if test "${XMAKE_PROMPT_BACKUP}"; then + PS1="${XMAKE_PROMPT_BACKUP}" + source "${XMAKE_ENV_BACKUP}" || return 1 + unset XMAKE_PROMPT_BACKUP + unset XMAKE_ENV_BACKUP + fi + ;; + *) + "$XMAKE_EXE" lua private.xrepo $@ + ;; + esac + else + "$XMAKE_EXE" lua private.xrepo $@ + fi +} diff --git a/scripts/xrepo.bat b/scripts/xrepo.bat index c8714a11c..77acf7d24 100755 --- a/scripts/xrepo.bat +++ b/scripts/xrepo.bat @@ -22,7 +22,7 @@ if !errorlevel! neq 0 ( exit /B !errorlevel! ) - @%XMAKE_EXE% lua private.xrepo.action.env.info prompt 1>nul + @%XMAKE_EXE% lua --quiet private.xrepo.action.env.info prompt 1>nul if !errorlevel! neq 0 ( echo error: xmake.lua not found^^! exit /B !errorlevel! @@ -39,13 +39,13 @@ if !errorlevel! neq 0 ( exit /B !errorlevel! ) - @%XMAKE_EXE% lua private.xrepo.action.env.info prompt 1>nul + @%XMAKE_EXE% lua --quiet private.xrepo.action.env.info prompt 1>nul if !errorlevel! neq 0 ( echo error: xmake.lua not found^^! exit /B !errorlevel! ) endlocal - for /f %%i in ('@%XMAKE_EXE% lua private.xrepo.action.env.info prompt') do @( + for /f %%i in ('@%XMAKE_EXE% lua --quiet private.xrepo.action.env.info prompt') do @( @set "PROMPT=%%i %PROMPT%" ) @set XMAKE_PROMPT_BACKUP=%PROMPT% |
