Skip to content

Commit f7914d6

Browse files
authored
fix: docker working directory (#10)
fix that the docker working directory is the current directory.
1 parent 02efd42 commit f7914d6

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

.bin/argsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ argsh::main() {
104104
local tty=""
105105
[[ ! -t 1 ]] || tty="-it"
106106
# shellcheck disable=SC2046
107-
docker run --rm ${tty} $(docker::user) \
107+
docker run --rm ${tty} $(docker::user) -w /workspace \
108108
-e "BATS_LOAD" \
109109
-e "ARGSH_SOURCE" \
110110
-e "GIT_COMMIT_SHA=$(git rev-parse HEAD || :)" \

libraries/docker.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ docker::user() {
2525
local user="${3:-"$(whoami)"}"
2626
local home="${4:-"/workspace"}"
2727
local shell="${5:-"/bin/sh"}"
28+
local curr
29+
curr="$(pwd)"
30+
curr="${curr#"${PATH_BASE:-}"}"
31+
if [[ "${curr}" == "$(pwd)" ]]; then
32+
curr="${home}"
33+
else
34+
curr="${home}${curr}"
35+
fi
2836

2937
echo "${user}:x:${uid}:${gid}::${home}:${shell}" > /tmp/docker_passwd
3038
echo "${user}:x:${gid}:" > /tmp/docker_group
3139
echo "-v /tmp/docker_passwd:/etc/passwd -v /tmp/docker_group:/etc/group"
3240
echo "-u ${uid}:${gid}"
3341

34-
echo "-v ${PATH_BASE:-.}:${home}"
35-
echo "-w ${home}"
42+
echo "-v ${PATH_BASE:-"$(pwd)"}:${home}"
43+
echo "-w ${curr}"
3644
}

libraries/main.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ argsh::shebang() {
2828
return 1
2929
} >&2
3030
local tty=""
31-
[[ ! -t 1 ]] || tty="-it"
31+
! tty -s || tty="-it"
3232
# shellcheck disable=SC2046
3333
docker run --rm ${tty} $(docker::user) \
3434
-e "BATS_LOAD" \
@@ -37,7 +37,7 @@ argsh::shebang() {
3737
-e "GIT_VERSION=$(git describe --tags --dirty || :)" \
3838
ghcr.io/arg-sh/argsh:latest "${@}"
3939
return 0
40-
} >&2
40+
}
4141
bash::version 4 3 0 || {
4242
echo "This script requires bash 4.3.0 or later"
4343
return 1

0 commit comments

Comments
 (0)