jhillyerd / plugin-git

Git aliases plugin for the Fish shell (similar to oh-my-zsh git)
MIT License
607 stars 85 forks source link

Problem with non-interactive shell where `$path` is not defined #102

Closed hexclover closed 10 months ago

hexclover commented 10 months ago

Hello, thank you for the fantastic plugin! I have a NixOS system with

  1. fish as the default shell
  2. this plugin enabled through https://github.com/nix-community/home-manager/

and I am look into the issue of being unable to SSH to any host through ProxyJump. It turns out if I (somehow) skip executing this line of init.fish, the problem magically disappears:

https://github.com/jhillyerd/plugin-git/blob/641b8722948bde5863cc3a049c2fde394158122d/init.fish#L2

It seems that since I don't have the $path variable defined in my environment, this line is expanded simply as source. According to fish's document, the behavior of source is

If no file is specified and stdin is not the terminal, or if the file name - is used, stdin will be read.

So in an interactive shell, the command fails and returns immediately; since home-manager generates code for loading the __git.init function, L3 in init.fish can be executed and the plugin itself works without problem. But in the fish process SSH spawns to execute the proxy command (fish -c 'exec ssh ...'), the source command will wait for input indefinitely, before continuing to exec.

I would like to know about the usage of this $path variable to come up with a proper fix of the problem. I guess it comes from some plugin framework but I failed to find relevant information. Or we can just modify init.fish to skip initialization if we are not in an interactive shell.

jhillyerd commented 10 months ago

Yes, $path is specific to oh-my-fish: https://github.com/oh-my-fish/oh-my-fish/blob/d427501b2c3003599bc09502e9d9535b5317c677/docs/en-US/Packages.md?plain=1#L70

I know nix fairly well, but I don't use home manager, so I don't have an easy way to experiment.

We could wrap the entire contents of init.fish in an if statement that checks for the presence of $path/functions/__git.init.fish

hexclover commented 10 months ago

Maybe we should just wrap the source line? Because home-manager still wants init.fish to initialize the plugin, it just adds the functions directory to fish_function_path before sourcing init.fish so source $path/... becomes unnecessary.

PaulGrandperrin commented 10 months ago

I just want to add that it also breaks scp.