eradman / entr

Run arbitrary commands when files change

Home Page:http://eradman.com/entrproject/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Current working directory is set to /usr/sbin when using fish?

adamroyjones opened this issue · comments

I've been running into a strange problem with entr that I'm struggling to understand. This wasn't an issue before, but I'm not sure what changed.

I sometimes set up compile loops like

fd "\.go\$" | entr -c -s "go run main.go"

but I've been finding that, if I set my user shell to /usr/bin/fish, then this doesn't work. The issue is that the working directory for the command after the pipe seems to be set to /usr/sbin:

fd "\.go\$" | entr -s "echo (pwd)"
# /usr/sbin

However, if I set SHELL=/usr/bin/bash, all's well:

fd "\.go\$" | SHELL=/usr/bin/bash entr -s "echo $(pwd)"
# The expected working directory.

Do you know what the problem might be? I don't (yet) know enough C to be of much use in picking things apart.

I was not able to reproduce this problem when setting SHELL to /usr/bin/fish on OpenBSD 7.1 or Rocky Linux 8

@adamroyjones what operating system are you using?

It's affected me with Ubuntu 22.04 and Arch Linux on at least two different computers. I tried to reproduce it in a Docker container just now and I failed miserably—everything's fine in that cleaner context.

I'm sorry: I should have tried to reproduce it in such a way first.

I'll include the (non)reproduction scripts below and close the issue. I'll add a comment later if I figure out what happened, just in case anyone else is struck by this. Again, I'm sorry for the bother.


FROM debian:bullseye
RUN apt update && apt install --yes entr fd-find fish golang
RUN useradd --uid 1000 --shell /usr/bin/fish --create-home reproducer
# Outside of the container. The directory should contain the above Dockerfile and at least one Go file.
docker build --tag entr-reproduction .
docker container run -it --mount type=bind,source="$(pwd)",target=/home/reproducer entr-reproduction bash
# Inside of the container. The final command should print /home/reproducer, not /usr/sbin.
su reproducer
cd
fdfind "\.go\$" | entr -s "echo (pwd)"

Christ, this is embarrassing: fish has a feature such that, if you type the name of a path (relative or not) and hit return, the shell's current directory is changed to that path. My configuration had something that looked roughly like:

set --export fish_user_paths \
    foo \
    bar
    /usr/sbin

The problem resulted from the absent trailing slash.

Wow--that "feature" is a subtle trap!
Thank you for posting the diagnoses.