diff options
| author | xq114 <[email protected]> | 2021-08-24 19:57:35 +0800 |
|---|---|---|
| committer | xq114 <[email protected]> | 2021-08-24 19:57:35 +0800 |
| commit | a21ec09a71f0e4c60957b37eb61e33f1a4ae6e86 (patch) | |
| tree | ed1bcc557207e8b9bafc3622aad07e26c5e16ab9 /scripts | |
| parent | a1e286a66cf7e9df8ec1cad9316386d7f2a75b33 (diff) | |
improve virtualenv on linux
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/get.sh | 8 | ||||
| -rwxr-xr-x | scripts/register-completions.sh | 2 | ||||
| -rw-r--r-- | scripts/register-virtualenvs.sh | 48 |
3 files changed, 57 insertions, 1 deletions
diff --git a/scripts/get.sh b/scripts/get.sh index 8363b4499..21814e45e 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -227,13 +227,19 @@ 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 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-completions.sh b/scripts/register-completions.sh index e274605b2..c93cfb15e 100755 --- a/scripts/register-completions.sh +++ b/scripts/register-completions.sh @@ -1,6 +1,8 @@ # parameter completions for *nix shell +export PATH=${XMAKE_ROOTDIR}:$PATH + if [[ "$SHELL" = */zsh ]]; then # zsh parameter completion for xmake _xmake_zsh_complete() diff --git a/scripts/register-virtualenvs.sh b/scripts/register-virtualenvs.sh new file mode 100644 index 000000000..13a661435 --- /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 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 +} |
