Skip to content

Fix Fish shell hook to load secrets immediately on source#20

Merged
crhuber merged 3 commits intomainfrom
copilot/fix-fish-shell-hook-issue-again
Oct 31, 2025
Merged

Fix Fish shell hook to load secrets immediately on source#20
crhuber merged 3 commits intomainfrom
copilot/fix-fish-shell-hook-issue-again

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Fish shell's --on-variable PWD event only fires on directory changes, not when the hook script is initially sourced. Users with .crumb.yaml in their current directory see no environment variables loaded until they change directories or trigger a new prompt.

Changes

  • pkg/commands/hook.go: Add immediate _crumb_hook invocation after function definitions
  • hook_test.go: Verify hook output includes immediate invocation call

Example

Before:

function _crumb_hook --on-variable PWD
  if test -f .crumb.yaml
    crumb export --shell fish | source;
  end
end
# Hook defined but not executed - secrets won't load until PWD changes

After:

function _crumb_hook --on-variable PWD
  if test -f .crumb.yaml
    crumb export --shell fish | source;
  end
end

# Call hook immediately to load secrets in current directory
_crumb_hook

This matches the behavior users expect from bash/zsh hooks which use eval in PROMPT_COMMAND/precmd_functions.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Fish Shell Hook Not Working</issue_title>
<issue_description>Given a .crumb file in ~/Desktop

cat .crumb.yaml
version: "1.0"
environments:
default:
path: "/platform/dev/"
remap: {}
env: {}

the path and secret do exist

crumb ls /platform/dev/
/platform/dev/TOKEN

crumb get /platform/dev/TOKEN


if i cd into ~/Desktop. no secret exists

echo $TOKEN

however if i run crumb export --shell fish | source;
echo $TOKEN
123456789

so the crumb export command is working but it doesnt work in fish shell when changing into a directory with .crumb.yaml in it

fish config looks like so

if status is-interactive
# fzf
fzf --fish | source
# crumb
crumb hook --shell fish | source
end</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Add _crumb_hook invocation at the end of Fish hook script
- This ensures secrets load immediately when hook is sourced
- Without this, secrets only load after PWD changes or on next prompt
- Update tests to verify the immediate invocation

Co-authored-by: crhuber <5857391+crhuber@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix fish shell hook not working with crumb Fix Fish shell hook to load secrets immediately on source Oct 30, 2025
Copilot AI requested a review from crhuber October 30, 2025 16:58
@crhuber crhuber marked this pull request as ready for review October 31, 2025 17:07
@crhuber crhuber merged commit d76056d into main Oct 31, 2025
2 checks passed
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.

Fish Shell Hook Not Working

2 participants