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

Allow wrapping and variable interpolation in help in the devshell menu #298

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

Conversation

deemp
Copy link
Contributor

@deemp deemp commented Jan 14, 2024

Based on #290

Interpolation

There's a .env file not added to git.

ADDRESS="http://localhost:3000"

A devshell user would like to open the address in a browser.

She can write this expression.

devShells.default = devshell.mkShell {
  bash.extra = ''
    set -a
    source .env
  '';
  devshell.menu.interpolate = true;
  commands = [
    { 
       package = "hello"; help = "open $ADDRESS";
    } 
  ];
};

And get this devshell menu.

🔨 Welcome to devshell

[[general commands]]

  hello - open http://localhost:3000
  menu  - prints this menu

[devshell]$

Wrapping

The default devshell looks like this:

🔨 Welcome to devshell

[[general commands]]

  menu                    - prints this menu

[packages]

  diffutils-3.10          - Commands for showing the differences between
                            files (diff, cmp, etc.)
  goreleaser-1.23.0       - Deliver Go binaries as fast and easily as
                            possible

[scripts]

  nix fmt                 - format Nix files
  nix run .#bench         - Run benchmark
  nix run .#docs          - Run mdBook server at "http://localhost:3000"

[utilites]

  golangci-lint-1.55.2    - golang linter
  hub-unstable-2022-12-01 - GitHub utility

[devshell]$

@@ -178,7 +178,7 @@ in
help = "prints this menu";
name = "menu";
command = ''
cat <<'DEVSHELL_MENU'
cat <<${(x: if config.devshell.menu.interpolate then x else "'${x}'") "DEVSHELL_MENU"}
Copy link
Member

Choose a reason for hiding this comment

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

I'd instead change it for everyone or make it configurable on the command level. With flake-parts, commands can get composed from different places, and then it's hard to know how the help is going to be interpolated from the different leafs.

Let's also make the "name" more strict, so it cannot include characters like $

@deemp deemp changed the title Allow variable interpolation in devshell menu Allow wrapping and variable interpolation in help in the devshell menu Jan 18, 2024
@deemp
Copy link
Contributor Author

deemp commented Jan 18, 2024

Hmm, what can be the error on macOS?

UPD: it was due to longer than devshell.menu.width lines on macOS

@deemp deemp force-pushed the add-interpolate-menu branch 2 times, most recently from 6fbe1a9 to d020c6d Compare January 18, 2024 08:29
@deemp deemp mentioned this pull request Jan 18, 2024
@deemp
Copy link
Contributor Author

deemp commented Jan 29, 2024

@zimbatm, @blaggacao, please, review

@blaggacao
Copy link
Contributor

Although this is not a moderated repository. Recent Moderation Team actions has scared me away from the Nix Community.

I'm sorry, won't be available for review. This has nothing to do with you and your effort which is really commendable. Keep the spirit up!

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