Is it possible to define a configuration file for zsh scripts?
I am running macOS 10.15 and the default shell is zsh.
I have defined, i.e., alias abc="echo yes"
in ~/.zshrc, ~/.zsh_profile, ~/.profile, and ~/.zsh_login, every configuration file I can think of. However, a shell script t.sh calling abc
will complain command not found: abc
:
⇒ cat t.sh
abc
⇒ zsh t.sh
t.sh:1: command not found: abc
⇒ sh t.sh
t.sh: line 1: abc: command not found
I understand that adding a line source ~/.zshrc
or source ~/.zsh_login
on the top of t.sh will work, but I wonder is it possible to set a configuration file that runs by default for any zsh script executed on my machine (by me)?
I'm asking this because I want to set an alias that works when I envoke a command inside vim via :!
, e.g. :!abc
, as well as the ]
command in the program nnn. Also please let me know if this is irrelevant to what I asked above. I'm confused of the login shell and non-login shell, or other types of shell. FYI, in vim, :!echo $0
will return /bin/zsh
and :!whoami
will return ***(my name)
, so it seems like it's a login shell.
echo $0
returns/bin/zsh
, without a-
in front. But, since .zshrc is sourced by a non-login shell, why is it not working? Or, is .zshrc only for interactive shell? What about non-interactive non-login shell?