Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option -m to preserve all environment variables #7

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions src/shell.in
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@ usr1_handler () { keep=true; }
force=false # when true, bypasses the call to get_shells
keep=false # when true, does not remove working directory when exiting
quiet=false # when true, informational messages are not outputted
preserveenv=false # when true, environemnt variables are untouched

skel=${SHELL_SKEL:-} # skeleton directory

while getopts 'd:fkqs:SvV' opt; do
while getopts 'd:fkmqs:SvV' opt; do
case $opt in
d) tmpwd=$OPTARG
unset skel ;;
f) force=true ;;
k) keep=true ;;
m) preserveenv=true ;;
q) quiet=true ;;
s) skel=$OPTARG
unset tmpwd ;;
Expand Down Expand Up @@ -229,10 +231,16 @@ fi

! "$quiet" && pinfof 'Starting %s in %s\n' "$realshell" "$tmpwd"

cd -- "$tmpwd" &&
env -i HOME="$tmpwd" \
if "$preserveenv" ; then
cd -- "$tmpwd" &&
"$realshell" "$@"
else
cd -- "$tmpwd" &&
env -i HOME="$tmpwd" \
PATH="$( getconf PATH )" \
PS1='$ ' \
SHELL="$realshell" \
TERM="$TERM" \
"$realshell" "$@"
fi