Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions distrobox-enter
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ headless=0
# There's no need for them to pass the --root flag option in such cases.
[ "$(id -ru)" -eq 0 ] && rootful=1 || rootful=0
skip_workdir=0
empty_env=0
add_env=""
verbose=0
clean_path=0
version="1.8.1.2.1"
Expand Down Expand Up @@ -188,6 +190,9 @@ Options:
--clean-path: reset PATH inside container to FHS standard
--no-tty/-T: do not instantiate a tty
--no-workdir/-nw: always start the container from container's home directory
--empty-env: don't copy host environment variables (default is to copy whenever reasonable)
--add-env: comma-separated list of additional host environment variables to copy
(overrides --empty-env)
--additional-flags/-a: additional flags to pass to the container manager command
--help/-h: show this message
--root/-r: launch podman/docker/lilipod with root privileges. Note that if you need root this is the preferred
Expand Down Expand Up @@ -231,6 +236,17 @@ while :; do
shift
skip_workdir=1
;;
--empty-env)
shift
empty_env=1
;;
--add-env)
if [ -n "$2" ]; then
add_env="$2"
shift
shift
fi
;;
-n | --name)
if [ -n "$2" ]; then
container_name="$2"
Expand Down Expand Up @@ -429,14 +445,21 @@ generate_enter_command()

# Loop through all the environment vars
# and export them to the container.
set +o xtrace
# disable logging for this snippet, or it will be too talkative.
for i in $(printenv | grep '=' | grep -Ev ' |"|`|\$' |
grep -Ev '^(CONTAINER_ID|FPATH|HOST|HOSTNAME|HOME|PATH|PROFILEREAD|SHELL|XDG_SEAT|XDG_VTNR|XDG_.*_DIRS|^_)'); do
# We filter the environment so that we do not have strange variables,
# multiline or containing spaces.
# We also NEED to ignore the HOME variable, as this is set at create time
# and needs to stay that way to use custom home dirs.
if [ "${empty_env}" -eq 0 ]; then
set +o xtrace
# disable logging for this snippet, or it will be too talkative.
for i in $(printenv | grep '=' | grep -Ev ' |"|`|\$' |
grep -Ev '^(CONTAINER_ID|FPATH|HOST|HOSTNAME|HOME|PATH|PROFILEREAD|SHELL|XDG_SEAT|XDG_VTNR|XDG_.*_DIRS|^_)'); do
# We filter the environment so that we do not have strange variables,
# multiline or containing spaces.
# We also NEED to ignore the HOME variable, as this is set at create time
# and needs to stay that way to use custom home dirs.
result_command="${result_command}
--env=${i}"
done
fi
# Export all environment variables passed via --additional-envvars
for i in $(echo "$additional_envvars" | sed 's/,/ /g'); do
result_command="${result_command}
--env=${i}"
done
Expand Down
4 changes: 4 additions & 0 deletions docs/usage/distrobox-enter.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ If using it inside a script, an application, or a service, you can specify the

--name/-n: name for the distrobox default: my-distrobox
--/-e: end arguments execute the rest as command to execute at login default: default ${USER}'s shell
--clean-path: reset PATH inside container to FHS standard
--no-tty/-T: do not instantiate a tty
--no-workdir/-nw: always start the container from container's home directory
--empty-env: don't copy host environment variables (default is to copy whenever reasonable)
--additional-envvars: comma-separated list of additional host environment variables to copy
(overrides --empty-env)
--additional-flags/-a: additional flags to pass to the container manager command
--help/-h: show this message
--root/-r: launch podman/docker/lilipod with root privileges. Note that if you need root this is the preferred
Expand Down