Skip to content

Conversation

@hirotaka
Copy link

@hirotaka hirotaka commented Oct 7, 2025

Summary

Fixes a fish shell variable scope bug where the cd command was not being executed after selecting a directory.

Problem

In fish shell, variables declared with set -l inside switch case blocks are scoped to that block only. This caused the cmd variable to be undefined outside the switch statement, resulting in the cd command not being executed.

Solution

  • Declare cmd variable before the switch statement with set -l cmd ""
  • Use set (without -l) inside case blocks to update the outer scope variable

Testing

All existing tests pass after this fix (22 tests, 68 assertions).

In Fish shell, variables declared with `set -l` inside switch case blocks
are scoped to that block only. This caused the `cmd` variable to be
undefined outside the switch statement, resulting in the cd command
not being executed.

Fixed by:
- Declaring `cmd` variable before the switch statement
- Using `set` instead of `set -l` inside case blocks to update the
  outer scope variable

All tests pass after this fix.
@hirotaka hirotaka changed the title Fix Fish shell variable scope in init command Fix fish shell variable scope in init command Oct 7, 2025
@hirotaka hirotaka mentioned this pull request Oct 15, 2025
@franck
Copy link

franck commented Nov 13, 2025

Thanks. This changes fix try with fish.

@gamb
Copy link

gamb commented Nov 16, 2025

For any home manager users you can adopt this patch with an override:

  programs.try = {
    enable = true;
    package = inputs.try.packages.${system}.default.overrideAttrs (old: {
      patches = (old.patches or [ ]) ++ [
        (pkgs.fetchpatch {
          url = "https://patch-diff.githubusercontent.com/raw/tobi/try/pull/39.diff";
          sha256 = "sha256-wZdZskcfBD3Z5xlyozO70O3v87Dx8hKb8+kX8eCE9Zw=";
        })
      ];
    });
  };

Confirmed it works for me

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