acomagu / fish-async-prompt

Make your prompt asynchronous to improve the reactivity.
MIT License
390 stars 22 forks source link

SHLVL incremented #17

Closed arobase-che closed 4 years ago

arobase-che commented 4 years ago

Hi,

The SHLVL environment variable is incremented. I'm used to have my shell level to be 1 when it's my first prompt. Now it's 2.

How to check

$ env | grep SHLVL
SHLVL=2

Is it what we want ?

acomagu commented 4 years ago

Hmm, no reproduce for me.

$ sh -c 'env -i TERM=$TERM HOME=$(mktemp -d) fish'
Welcome to fish, the friendly interactive shell
$ env | grep SHLVL
SHLVL=1
$ curl https://raw.githubusercontent.com/acomagu/fish-async-prompt/master/conf.d/__async_prompt.fish --create-dirs -sLo ~/.config/fish/conf.d/async_prompt.fis
h
$ source ~/.config/fish/conf.d/async_prompt.fish
$ ls
$ env | grep SHLVL
SHLVL=1

Fish appear to just increase the value on startup, for example:

$ env SHLVL=10 fish
Welcome to fish, the friendly interactive shell
$ env | grep SHLVL
SHLVL=11

So maybe your WM(GNOME or KDE, etc) set SHLVL=1?

arobase-che commented 4 years ago

Sorry, I wasn't clear at all ! It didn't increment the variable SHLVL in the shell's environment but in the prompt's environment.

Here a working example :

$ sh -c 'env -i TERM=$TERM HOME=$(mktemp -d) fish' # Nice tip btw, thank you !
Welcome to fish, the friendly interactive shell
$ env | grep SHLVL
SHLVL=1
$ mkdir ~/.config/fish/functions
$ echo 'function fish_prompt
      echo "$SHLVL \$ "
end' > ~/.config/fish/functions/fish_prompt.fish
1 $ curl https://raw.githubusercontent.com/acomagu/fish-async-prompt/master/conf.d/__async_prompt.fish --create-dirs -sLo ~/.config/fish/conf.d/async_prompt.fish
1 $ source ~/.config/fish/conf.d/async_prompt.fish
2 $ env | grep SHLVL
SHLVL=1
2 $ 

The echo 'function fish_prompt ... command will change the prompt to print the SHLVL. When async_prompt.fish is charged, it increments the SHLVL of the prompt, but not the SHLVL environment variable.

Sorry about the confusion, I realize that I wasn't understandable.

acomagu commented 4 years ago

OK, I understand. Thank you for detailed explanation.

The reason is the plugin spawns another Fish process and run your prompt function on it.

I'll fix it in days. I want minimize the differences of prompt's environment between when plugin is installed and when not.

Thank you for reporting!

arobase-che commented 4 years ago

Thank you for detailed explanation.

You are welcome ^^

The reason is the plugin spawns another Fish process and run your prompt function on it.

        end | env SHLVL=(math "$SHLVL-1") fish -c 'function __async_prompt_ses

At the line 88, may be the only solution since $SHLVL is a read only variable.

^^

acomagu commented 4 years ago

Thanks! Are you willing to create PR?

arobase-che commented 4 years ago

If the solution suits you. Here we go ! :D