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 support for fish and tcsh shells #1347

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

add support for fish and tcsh shells #1347

wants to merge 4 commits into from

Conversation

limeytexan
Copy link
Contributor

@limeytexan limeytexan commented Apr 20, 2024

Proposed Changes

This PR adds support for the fish and tcsh shells based on the refactoring of flox activate performed in #1299.

Also removed posixIfThen and posixSetEnv C++ macros no longer required since merging PR#1299.

Release Notes

  • Added support for fish and tcsh shells.

@limeytexan limeytexan force-pushed the fish-and-tcsh branch 2 times, most recently from d05824d to fa5fd87 Compare April 23, 2024 10:48
@limeytexan limeytexan force-pushed the issue-1187 branch 2 times, most recently from 3c3e633 to f9caf58 Compare April 23, 2024 11:51
@limeytexan limeytexan force-pushed the fish-and-tcsh branch 3 times, most recently from 1071e76 to 65e11a2 Compare April 23, 2024 16:48
@limeytexan limeytexan force-pushed the issue-1187 branch 4 times, most recently from 779a4b9 to 67a0e41 Compare April 30, 2024 17:18
Base automatically changed from issue-1187 to main April 30, 2024 17:20
@limeytexan limeytexan force-pushed the fish-and-tcsh branch 3 times, most recently from 3118022 to d4d4a0b Compare May 22, 2024 17:43
@limeytexan limeytexan marked this pull request as ready for review May 22, 2024 17:55
@mkenigs mkenigs requested a review from dcarley May 22, 2024 18:55
@limeytexan limeytexan force-pushed the fish-and-tcsh branch 2 times, most recently from 7c03ba1 to 44b7b6d Compare May 23, 2024 12:34
The perils of creating our own quoting function is that we're destined
to repeat lessons of the past, but of course the advantage is that we have
more precise control of the outcome. This patch adds logic to similarly
escape the backtick (`) character. (I rather suspect our next step will
be to escape the single quote ('), followed by conditional logic to avoid
escaping when within them.)
Following PR#1299 it was fairly straightforward to add support for the
fish and tcsh shells. This patch adds this support along with tests that
mirror those that already exist for bash and zsh.

Also removed `posixIfThen` and `posixSetEnv` C++ macros no longer required
since merging PR#1299.
Copy link
Contributor

@mkenigs mkenigs left a comment

Choose a reason for hiding this comment

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

I only made it through the Rust - I'll pick up with the pkgdb changes next week (that's where all the real logic is 😆 )

cli/flox/src/commands/init/mod.rs Outdated Show resolved Hide resolved
cli/flox/src/commands/init/mod.rs Outdated Show resolved Hide resolved
cli/tests/activate.bats Show resolved Hide resolved
indoc! {r#"
echo "Activating poetry virtual environment" >&2
source "$(poetry env info --path)/bin/activate.csh""#}
.to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

question blocking: how prominent do we want tcsh to be in docs and init hooks? I'm not really sure how much it's used, so I'm not sure if most people will see it as boilerplate or actually helpful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know at least two firms in which it's still used extensively, but regardless we should maintain a low bar for the addition of shell support (and it should be easier and better factored to involve modifications to fewer than 30 files in future!).

As for the prominence of its mention in the template, that's somewhat of an implementation detail; direnv supports 9 shells, and I agree at some point that we'll want to change the manifest template to be less verbose once there are that many to be listed.

But is there a reason you made the comment here in the python.rs file? This is one place where we definitely need to explicitly emit code for each of the supported shells - I can see your question pertaining to the template manifest.toml but not here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Even in init hooks, we could just add hooks for the most popular shells - with 3 examples (bash, zsh, and fish) I don't think it would be too difficult for a tcsh user to figure out what to add in a tcsh hook.

@ghudgins @jennymahmoudi any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

agree, just fish is good

@zmitchell
Copy link
Contributor

I'm about half-way done with my review, I'll probably try to finish on Monday

Thanks @mkenigs for the eagle eye. Clearly did that in a batch of bulk changes and just missed it ... curious why that wasn't caught in tests but happy to move on ...

Co-authored-by: Matthew Kenigsberg <matthew@floxdev.com>
set prompt = "$_flox $FLOX_SAVE_TCSH_PROMPT"
endif

unset _flox
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion blocking: when "${FLOX_PROMPT_ENVIRONMENTS:-}" == "", the prompt shouldn't be changed at all

# these files ourselves prior to setting up the environment.
foreach f ( /etc/csh.login /etc/csh.cshrc ~/.cshrc ~/.tcshrc )
if ( -f $f ) then
source $f
Copy link
Contributor

Choose a reason for hiding this comment

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

question blocking: could we hit the same infinite looping bug as with .bashrc?


# Bring in the Nix and Flox environment customizations.
if ( $?FLOX_TCSH_INIT_SCRIPT ) then
source "$FLOX_TCSH_INIT_SCRIPT"
Copy link
Contributor

Choose a reason for hiding this comment

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

question blocking: looks like above you source e.g. $HOME/.cshrc, but then doesn't FLOX_TCSH_INIT_SCRIPT source ~/.cshrc again? Not sure if I'm reading that right

Copy link
Contributor

Choose a reason for hiding this comment

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

That's what it looks like to me

cli/flox/src/commands/init/mod.rs Outdated Show resolved Hide resolved
@@ -365,6 +365,12 @@ impl Activate {
.arg("--rcfile")
.arg(activation_path.join("activate").join("bash"));
},
Shell::Fish(_) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: it's probably worth suggesting to the user that they rebuild the environment to gain support for the new shells. If this is a remote environment that belongs to someone else then it's out of their hands, but otherwise they may not understand why we say we support fish, etc and then get this error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I expect there will be approximately zero people wanting to use fish with environments rendered before version 1.0.5, but I see your point. What if we update the error message to read "fish not supported with environments rendered before version 1.0.5; please update environment and try again" - does that work for you?


# Bring in the Nix and Flox environment customizations.
if ( $?FLOX_TCSH_INIT_SCRIPT ) then
source "$FLOX_TCSH_INIT_SCRIPT"
Copy link
Contributor

Choose a reason for hiding this comment

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

That's what it looks like to me

pkgdb/src/buildenv/assets/activate.d/set-prompt.fish Outdated Show resolved Hide resolved
s/flox_save_fish_prompt/flox_saved_fish_prompt/g
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.

None yet

4 participants