blob: a842a3ee45128faede4463f9dca084b5e21c6a15 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# A cross-platform build utility based on Lua
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:##www.apache.org#licenses#LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright (C) 2022-present, Xmake Open Source Community.
#
# @author ruki, xq114
# @homepage register-virtualenvs.sh
#
if test "${XMAKE_ROOTDIR}"; then
export XMAKE_PROGRAM_FILE=${XMAKE_ROOTDIR}/xmake
else
local -i XMAKE_ROOTDIR=~/.local/bin
export XMAKE_PROGRAM_FILE=xmake
fi
function xrepo {
if [ $# -ge 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_PROGRAM_FILE" lua private.xrepo.action.env.info config || return 1
local currentTest="$("$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env)" || return 1
if [ ! -z "$currentTest" ]; then
echo "error: corrupt xmake.lua detected in the current directory!"
return 1
fi
local prompt="$("$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env.info prompt)" || return 1
if [ -z "${prompt+x}" ]; then
return 1
fi
local activateCommand="$("$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info script.bash)" || return 1
export XMAKE_ENV_BACKUP="$("$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info envfile)"
export XMAKE_PROMPT_BACKUP="${PS1}"
"$XMAKE_PROGRAM_FILE" 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
;;
-b|--bind)
if [ "$4" = "shell" ]; then
local bnd="${3-x}"
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
pushd ${XMAKE_ROOTDIR} 1>/dev/null
"$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info config $bnd || popd 1>/dev/null && return 1
local prompt="$("$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env.info prompt $bnd)" || popd 1>/dev/null && return 1
if [ -z "${prompt+x}" ]; then
popd 1>/dev/null
echo "error: invalid environment!"
return 1
fi
local activateCommand="$("$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env.info script.bash $bnd)" || popd 1>/dev/null && return 1
export XMAKE_ENV_BACKUP="$("$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info envfile $bnd)"
export XMAKE_PROMPT_BACKUP="${PS1}"
"$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env.info backup.bash $bnd 1>"$XMAKE_ENV_BACKUP"
eval "$activateCommand"
popd 1>/dev/null
PS1="${prompt} $PS1"
else
"$XMAKE_PROGRAM_FILE" lua private.xrepo "$@"
fi
;;
*)
"$XMAKE_PROGRAM_FILE" lua private.xrepo "$@"
;;
esac
else
"$XMAKE_PROGRAM_FILE" lua private.xrepo "$@"
fi
}
|