Skip to content

Run try command in the users shell of choice - #197

Merged
mgree merged 66 commits into
binpash:mainfrom
Ioa1:main
Jun 18, 2025
Merged

mgree merged 66 commits into
binpash:mainfrom
Ioa1:main

Conversation

@Ioa1

@Ioa1 Ioa1 commented Jun 9, 2025

Copy link
Copy Markdown
Contributor

Issue #7 says that we always run try in bin/sh. We want to allow the user to choose what shell try runs in or failing that picks a sane default.

Comment thread test/check_shell.sh Resolved
Comment thread test/check_shell.sh Resolved
Comment thread test/check_shell.sh Outdated
cleanup() {
cd /

if [ -d "$try_workspace" ]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop this whole if---we don't need a try_workspace for this test.

Comment thread test/check_shell.sh Outdated
check_case "" "/bin/bash" "/bin/bash" "2"

if [ "$CI" = "true" ]; then
saved_shell=$(grep -e "^$LOGNAME" /etc/passwd | cut -d: -f7)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do something like : ${LOGNAME=$(whoami)} first, since $LOGNAME doesn't seem to be set in CI here.

Comment thread test/check_shell.sh Outdated

if [ "$CI" = "true" ]; then
saved_shell=$(grep -e "^$LOGNAME" /etc/passwd | cut -d: -f7)
sudo apt install -y zsh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sudo apt install -y zsh
sudo apt-get install -y zsh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we omit the installing of zsh part here, since not all runners/test distro will be debian based, and for other test deps we have always been just relying on the environment having it

Ioa1 and others added 24 commits June 9, 2025 18:37
Co-authored-by: Michael Greenberg <michael@greenberg.science>
Co-authored-by: Michael Greenberg <michael@greenberg.science>
Co-authored-by: Michael Greenberg <michael@greenberg.science>
Comment thread docs/try.1.md Outdated

While using *try* you can choose to commit the result to the filesystem or completely ignore it without any side-effect to the main file system.

You can also choose your own shell when running *try*.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try will run your command within your login shell by default; you can override this by setting the TRY_SHELL variable.

@mgree mgree left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fundamentally fine---a few comment nits, and we need to fix the formatting.

Comment thread docs/try.1.md Outdated

While using *try* you can choose to commit the result to the filesystem or completely ignore it without any side-effect to the main file system.

You can also choose your own shell when running *try*. *try* will run your command within your login shell by default; you can override this by setting the TRY_SHELL variable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can also choose your own shell when running *try*. *try* will run your command within your login shell by default; you can override this by setting the TRY_SHELL variable.
You can also choose your own shell when running *try*. *try* will run your command within your login shell by default; you can override this by setting the *TRY_SHELL* variable to the absolute path of a shell to use.

Comment thread try Outdated

################################################################################
# Run a command (in `$@`) in an overlay (in `$SANDBOX_DIR`)
# Returns the shell try is currently running on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't exactly the right description. Maybe:

Suggested change
# Returns the shell try is currently running on
# Tries to detect a setting for TRY_SHELL

Comment thread try Outdated
[ -d "$SANDBOX_DIR" ] || error "could not find sandbox directory $SANDBOX_DIR" 2
# Force absolute path
SANDBOX_DIR="$(cd "$SANDBOX_DIR" && pwd)"
#case TRY_SHELL set

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to keep formatting like other comments in the code. (There are a few others missing spaces after #.)

Suggested change
#case TRY_SHELL set
# case: TRY_SHELL set to an executable

Comment thread try Outdated
## Create a new sandbox if one was not given
SANDBOX_DIR="$(mktemp -d --suffix ".try-$EXECID")"
fi
#check if SHELL is set and is not fish

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is just translating the code to English---we expect someone reading this to understand the basics of the shell code anyway. The intent is more like:

Suggested change
#check if SHELL is set and is not fish
# use SHELL (if it's not fish)

Comment thread try Outdated
error "given sandbox '$SANDBOX_DIR' is invalid" 1
else
login_shell=$(grep "^$(whoami):" /etc/passwd | cut -d: -f7)
#echo "login_shell in try: $login_shell"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't leave in your print debugs!

Suggested change
#echo "login_shell in try: $login_shell"

Comment thread try Resolved
Comment thread try Outdated
try-summary -i "$IGNORE_FILE" "$SANDBOX_DIR" || return 1
TRY_EXIT_STATUS=0
}
if type try-summary >/dev/null 2>&1; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto... all these are showing whitespace-induced diffs. 😢

Comment thread try Outdated
(--) shift
try "$@";;
(*) try "$@";;
summary)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was entirely reformatted... can you put it back the way it was, please?

@mgree
mgree merged commit 8e7a32f into binpash:main Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants