Re: zsh problems MacOS High Sierra

2022-05-05 Thread Sriranga Veeraraghavan
Happy to have been of help.

Best,

-ranga

> On May 5, 2022, at 10:11, Jean Bermudez  wrote:
> 
> Thank you very much! This fixed my problem. I have zsh 5.8.1 as the default 
> shell and I can run NeoVim without problems.
> 
> El lun, 2 may 2022 a las 16:33, Sriranga Veeraraghavan 
> (mailto:srira...@berkeley.edu>>) escribió:
> Hi Jean,
> 
> Is /opt/local/bin/zsh in your /etc/shells now?  You can check as follows:
> 
> /usr/bin/grep -i zsh /etc/shells
> 
> If this includes /opt/local/bin/zsh, then you can probably use 
> /opt/local/bin/zsh as a valid login shell.  If so, you can now probably try 
> the following to change your shell:
> 
> /usr/bin/chsh -s /opt/local/bin/zsh
> 
> This should probably change your login shell to /opt/local/bin/zsh.  This was 
> the same command that was in my prior email, except that it omits the ‘$’ 
> character, which, by convention, is the default shell prompt and should not 
> be treated as part of the command.
> 
> I think the rest of your problems may be due to the PATH environment variable 
> not being set properly.  For zsh, I would suggest that you set up your PATH 
> environment variable as follows:
> 
> /bin/echo 'export 
> PATH="/opt/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin"'
>  > ~/.zshenv
> 
> For your reference, the PATH environment variable is a list of all the 
> directories that your shell (zsh or bash) will look in for commands.  The ‘:’ 
> character separates the directories.  The order in which the directories are 
> listed is important.  In the above, /opt/local/bin is ahead of all of the 
> other directories, so that you will get the MacPorts versions of commands 
> rather than the versions that are in other directories (the Apple provided 
> versions are usually in /bin or /usr/bin).  
> 
> HTH,
> 
> -ranga
> 
> > On May 2, 2022, at 12:55, Jean Bermudez  > > wrote:
> > 
> > Hi! Thank you for your answer!
> > 
> > I was trying a few things before your reply. In the #macpports channel on 
> > libera.chat, 
> > they recommended me to run this: echo "/opt/local/bin/zsh" | sudo tee -a 
> > /etc/shells
> > 
> > ...to set my user's login shell to /opt/local/bin/zsh.
> > 
> > After that they was recommended me to run: "chsh -s /opt/local/bin/zsh" to 
> > set zsh as default shell.
> > 
> > I tried that, and everything continued the same way. I commented that when 
> > I use the command "echo $ZSH_VERSION" the answer is 5.8.1 (the installed 
> > version of MacPorts), instead when I use the command "zsh -version" it 
> > answers me 5.3 (the High Sierra version).
> > 
> > Faced with this, in the #macports chat on libera chat I got the following 
> > response:
> > 
> > - $ZSH_VERSION is what your current shell is
> > - zsh --version is whatever is first in your $PATH
> > - which also explains why it works for bash - your $PATH contains 
> > /opt/local/bin before /bin
> > - That also explains why it works for zsh started from bash, because that 
> > usually keeps $PATH the same, so /opt/local/bin is again before /bin
> > - See https://guide.macports.org/#installing.shell.postflight 
> > 
> > - $PATH is btw also the reason why the nvim command doesn't work.
> > - export PATH=/opt/local/bin:$PATH; hash -r; nvim will probably work in all 
> > shells
> > 
> > When I use "export PATH=/opt/local/bin:$PATH; hash -r; nvim" NeoVim starts, 
> > but when I close the terminal and try to open NeoVim with the command 
> > "nvim" I get as response "nvim: command not found".
> > 
> > Additionally trying some things, I used this command "cat > 
> > ~/.bash_profile" which brought me some problems. I had to reset 
> > .bash_profile.
> > 
> > Now when I run "nvim" I cannot access NeoVim from any of the SHELLS. The 
> > only way I can access NeoVim currently is by using "export 
> > PATH=/opt/local/bin:$PATH; hash -r; nvim".
> > 
> > I tried the commands you recommended.
> > - sudo /bin/sh -c '/bin/echo /opt/local/bin/zsh >> /etc/shells'. 
> > In response I get an empty command line with a ">" at the beginning.
> > 
> > - $ /usr/bin/chsh -s /opt/local/bin/zsh
> > - $ /bin/echo 'PATH="$PATH:/opt/local/bin:/opt/local/sbin"' >> ~/.zshenv
> > In response to these last two commands I get: -bash: $: command not found
> > 
> > 
> > El lun, 2 may 2022 a las 15:04, Sriranga Veeraraghavan 
> > (mailto:srira...@berkeley.edu>>) escribió:
> > Hi Jean,
> > 
> > I think that this isn’t working for you because MacPorts generally installs 
> > programs in /opt/local/bin.  
> > 
> > If you have installed zsh using MacPorts and you want to make the MacPort’s 
> > version of zsh your default shell, you’ll probably need to do something 
> > like the following:
> > 
> > $ sudo /bin/sh -c '/bin/echo /opt/local/bin/zsh >> /etc/shells’ 
> > $ /usr/bin/chsh -s /opt/local/bin/zsh
> > 
> > The first line adds /opt/local/bin/zsh to /etc/shells as a permitted login 
> > shell.  The 

Re: zsh problems MacOS High Sierra

2022-05-03 Thread Dave Horsfall
On Mon, 2 May 2022, Ryan Schmidt wrote:

> When the MacPorts installer detects that your shell is zsh, it places 
> such a line in ~/.zprofile. I don't know if there is a significant 
> difference between putting it in ~/.zprofile vs putting it in ~/.zshenv.

I've been using ZSH on various boxen for ages, and I still don't 
understand it :-)

-- Dave


Re: zsh problems MacOS High Sierra

2022-05-03 Thread raf
On Mon, May 02, 2022 at 11:22:35AM -0400, Jean Bermudez  
wrote:

> Hi there!
> 
> I installed "NeoVim" and "zsh" via MacPorts on MacOs High Sierra.
> 
> I have a problem. High Sierra comes with "zsh" version 5.3 installed by
> default. I noticed this after I installed zsh version 5.8.1 via MacPorts.
> 
> How did I figure it out?
> - I changed the default shell (bash) to "zsh" via the command "chsh -s
> /bin/zsh".
> - I tried to start NeoVim with the command "nvim".
> - And the system responded "zsh: command not found: nvim".
> - After trying several things, I entered the command "zsh -version" and the
> version that was active was 5.3 (High Sierra).
> - I went back to the "bash" shell and simply entered the command "zsh" to
> use the zsh shell, and when I checked the version (zsh -version) the
> version was 5.8.1 (MacPorts). I entered the command "nvim" and it worked.
> 
> I got desperate looking for a solution and entered several times the
> command you provide on your site to set MacPorts': sudo sh -c 'echo
> ${prefix}/bin/zsh >>/etc/shells'.
> 
> Now when I check the list of Shells with "cat /etc/shells". I get
> "/bin/zsh" four times.
> 
> I want to delete all zsh and install only the MacPorts "zsh" cleanly; and
> then set that shell to default.
> 
> How do I do this?

I'd recommend leaving /bin/zsh where it is, adding
/opt/local/bin/zsh to /etc/shells and setting your
shell to that with chsh. Then, make sure that
/opt/local/bin is before /bin in your $PATH.

If that doesn't do it, because no matter what you try,
the PATH doesn't get set to what you want, the problem
might be caused by the use of /usr/libexec/path_helper
in /etc/zprofile.

I think it's Apple's way of trying to be helpful by
assuming that you don't know what you want your own
$PATH to be. By default, that file looks something
like:

  if [ -x /usr/libexec/path_helper ]; then
  eval `/usr/libexec/path_helper -s`
  fi

Get it to echo $PATH before and after path_helper to
see if you want what it's doing. If not, change it to
stop path_helper from running.

Mine looks like:

  if [ $(id -un) != raf ]; then
  if [ -x /usr/libexec/path_helper ]; then
  eval `/usr/libexec/path_helper -s`
  fi
  fi

Having said all that, be warned that it might be
dangerous to set your default shell to a macports
shell, because when upgrading from one major macos
version to another, you might not have a functioning
macports system (since you need to remove and reinstall
macports). I'm not sure that that's a problem, but it
sounds like it probably is. So you might want to chsh
your shell back to /bin/zsh before a major upgrade, and
chsh it back to /opt/local/bin/zsh afterwards. But I've
never had to do that, so maybe it's not a problem.

cheers,
raf



Re: zsh problems MacOS High Sierra

2022-05-03 Thread Joshua Root

Ryan Schmidt wrote:


On May 2, 2022, at 23:49, Sriranga Veeraraghavan wrote:

>/I am not a zsh user, but according to zsh's documentation, 
~/.zprofile is run only when zsh is used as a login shell, whereas 
~/.zshenv is read for nearly every instance of zsh (including scripts): />//>/https://zsh.sourceforge.io/Guide/zshguide02.html#l9 />//>/Because of this, it is possible that if /opt/local/bin, etc., are 
only added to PATH in ~/.zprofile, then in some instances zsh would 
use the Apple standard programs in /bin, /sbin, /usr/bin, etc., while 
in other instances zsh would use, for example, the MacPorts versions 
in /opt/local/bin, etc. This might lead to inconsistencies or hard to 
detect bugs in shell scripts, etc. /

MacPorts has been modifying ~/.zprofile when the shell is zsh ever since zsh 
support was added to MacPorts 2.5 years ago. If it is a problem, nobody has 
reported it so far.

https://github.com/macports/macports-base/commit/f9a3b2d5bcc27a1a279184c496a095f31b5d85a2

All shells on macOS are login shells.


Not all shells are login shells, but non-login shells are commonly child 
processes of a login shell that already executed the startup files. So 
non-login shells will usually inherit any variables exported in 
zprofile. Also, any shell can (and often does) run another shell. That 
means that all code in zshenv and zshrc needs to behave correctly when 
executed multiple times. Unconditionally appending to PATH will result 
in the value being added multiple times, once per "layer" of shell. So 
that's one reason why we don't use zshenv.


The other is that Apple's /etc/zprofile overwrites PATH, so any changes 
made to it before that file is read don't stick.


- Josh



Re: zsh problems MacOS High Sierra

2022-05-02 Thread Ryan Schmidt
On May 2, 2022, at 23:49, Sriranga Veeraraghavan wrote:

> On May 2, 2022, at 20:46, Ryan Schmidt wrote:
> 
>> When the MacPorts installer detects that your shell is zsh, it places such a 
>> line in ~/.zprofile. I don't know if there is a significant difference 
>> between putting it in ~/.zprofile vs putting it in ~/.zshenv.
> 
> I am not a zsh user, but according to zsh's documentation, ~/.zprofile is run 
> only when zsh is used as a login shell, whereas ~/.zshenv is read for nearly 
> every instance of zsh (including scripts):
> 
> https://zsh.sourceforge.io/Guide/zshguide02.html#l9
> 
> Because of this, it is possible that if /opt/local/bin, etc., are only added 
> to PATH in ~/.zprofile, then in some instances zsh would use the Apple 
> standard programs in /bin, /sbin, /usr/bin, etc., while in other instances 
> zsh would use, for example, the MacPorts versions in /opt/local/bin, etc.  
> This might lead to inconsistencies or hard to detect bugs in shell scripts, 
> etc. 

MacPorts has been modifying ~/.zprofile when the shell is zsh ever since zsh 
support was added to MacPorts 2.5 years ago. If it is a problem, nobody has 
reported it so far.

https://github.com/macports/macports-base/commit/f9a3b2d5bcc27a1a279184c496a095f31b5d85a2

All shells on macOS are login shells.



Re: zsh problems MacOS High Sierra

2022-05-02 Thread Sriranga Veeraraghavan


> On May 2, 2022, at 20:46, Ryan Schmidt  wrote:
> 
> ...
> 
> When the MacPorts installer detects that your shell is zsh, it places such a 
> line in ~/.zprofile. I don't know if there is a significant difference 
> between putting it in ~/.zprofile vs putting it in ~/.zshenv.
> 

I am not a zsh user, but according to zsh's documentation, ~/.zprofile is run 
only when zsh is used as a login shell, whereas ~/.zshenv is read for nearly 
every instance of zsh (including scripts):

https://zsh.sourceforge.io/Guide/zshguide02.html#l9

Because of this, it is possible that if /opt/local/bin, etc., are only added to 
PATH in ~/.zprofile, then in some instances zsh would use the Apple standard 
programs in /bin, /sbin, /usr/bin, etc., while in other instances zsh would 
use, for example, the MacPorts versions in /opt/local/bin, etc.  This might 
lead to inconsistencies or hard to detect bugs in shell scripts, etc. 

Best,

-ranga




Re: zsh problems MacOS High Sierra

2022-05-02 Thread Ryan Schmidt
On May 2, 2022, at 14:04, Sriranga Veeraraghavan wrote:

> Regarding nvim, the reason that zsh can’t find it is probably that the 
> directory /opt/local/bin is not included zsh's PATH environment variable.

Right. The MacPorts installer sets up the PATH for your current shell. If you 
change shells later, you have to set up the PATH yourself or rerun the 
installer to do it automatically.


> I am not a zsh user, but I believe that you can probably fix this as follows:
> 
> $ /bin/echo 'PATH="$PATH:/opt/local/bin:/opt/local/sbin"' >> ~/.zshenv

When the MacPorts installer detects that your shell is zsh, it places such a 
line in ~/.zprofile. I don't know if there is a significant difference between 
putting it in ~/.zprofile vs putting it in ~/.zshenv.



Re: zsh problems MacOS High Sierra

2022-05-02 Thread Sriranga Veeraraghavan
Hi Jean,

Is /opt/local/bin/zsh in your /etc/shells now?  You can check as follows:

/usr/bin/grep -i zsh /etc/shells

If this includes /opt/local/bin/zsh, then you can probably use 
/opt/local/bin/zsh as a valid login shell.  If so, you can now probably try the 
following to change your shell:

/usr/bin/chsh -s /opt/local/bin/zsh

This should probably change your login shell to /opt/local/bin/zsh.  This was 
the same command that was in my prior email, except that it omits the ‘$’ 
character, which, by convention, is the default shell prompt and should not be 
treated as part of the command.

I think the rest of your problems may be due to the PATH environment variable 
not being set properly.  For zsh, I would suggest that you set up your PATH 
environment variable as follows:

/bin/echo 'export 
PATH="/opt/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin"'
 > ~/.zshenv

For your reference, the PATH environment variable is a list of all the 
directories that your shell (zsh or bash) will look in for commands.  The ‘:’ 
character separates the directories.  The order in which the directories are 
listed is important.  In the above, /opt/local/bin is ahead of all of the other 
directories, so that you will get the MacPorts versions of commands rather than 
the versions that are in other directories (the Apple provided versions are 
usually in /bin or /usr/bin).  

HTH,

-ranga

> On May 2, 2022, at 12:55, Jean Bermudez  wrote:
> 
> Hi! Thank you for your answer!
> 
> I was trying a few things before your reply. In the #macpports channel on 
> libera.chat, 
> they recommended me to run this: echo "/opt/local/bin/zsh" | sudo tee -a 
> /etc/shells
> 
> ...to set my user's login shell to /opt/local/bin/zsh.
> 
> After that they was recommended me to run: "chsh -s /opt/local/bin/zsh" to 
> set zsh as default shell.
> 
> I tried that, and everything continued the same way. I commented that when I 
> use the command "echo $ZSH_VERSION" the answer is 5.8.1 (the installed 
> version of MacPorts), instead when I use the command "zsh -version" it 
> answers me 5.3 (the High Sierra version).
> 
> Faced with this, in the #macports chat on libera chat I got the following 
> response:
> 
> - $ZSH_VERSION is what your current shell is
> - zsh --version is whatever is first in your $PATH
> - which also explains why it works for bash - your $PATH contains 
> /opt/local/bin before /bin
> - That also explains why it works for zsh started from bash, because that 
> usually keeps $PATH the same, so /opt/local/bin is again before /bin
> - See https://guide.macports.org/#installing.shell.postflight
> - $PATH is btw also the reason why the nvim command doesn't work.
> - export PATH=/opt/local/bin:$PATH; hash -r; nvim will probably work in all 
> shells
> 
> When I use "export PATH=/opt/local/bin:$PATH; hash -r; nvim" NeoVim starts, 
> but when I close the terminal and try to open NeoVim with the command "nvim" 
> I get as response "nvim: command not found".
> 
> Additionally trying some things, I used this command "cat > ~/.bash_profile" 
> which brought me some problems. I had to reset .bash_profile.
> 
> Now when I run "nvim" I cannot access NeoVim from any of the SHELLS. The only 
> way I can access NeoVim currently is by using "export 
> PATH=/opt/local/bin:$PATH; hash -r; nvim".
> 
> I tried the commands you recommended.
> - sudo /bin/sh -c '/bin/echo /opt/local/bin/zsh >> /etc/shells'. 
> In response I get an empty command line with a ">" at the beginning.
> 
> - $ /usr/bin/chsh -s /opt/local/bin/zsh
> - $ /bin/echo 'PATH="$PATH:/opt/local/bin:/opt/local/sbin"' >> ~/.zshenv
> In response to these last two commands I get: -bash: $: command not found
> 
> 
> El lun, 2 may 2022 a las 15:04, Sriranga Veeraraghavan 
> () escribió:
> Hi Jean,
> 
> I think that this isn’t working for you because MacPorts generally installs 
> programs in /opt/local/bin.  
> 
> If you have installed zsh using MacPorts and you want to make the MacPort’s 
> version of zsh your default shell, you’ll probably need to do something like 
> the following:
> 
> $ sudo /bin/sh -c '/bin/echo /opt/local/bin/zsh >> /etc/shells’ 
> $ /usr/bin/chsh -s /opt/local/bin/zsh
> 
> The first line adds /opt/local/bin/zsh to /etc/shells as a permitted login 
> shell.  The command you were using only designated the Apple provided zsh, 
> /bin/zsh, as a permitted login shell.  
> 
> The second line changes the default shell to /opt/local/bin/zsh.  The command 
> you were using probably didn’t accomplish this for you because ${prefix} is a 
> variable used to specify the MacPorts directory, which probably wasn’t 
> defined.  I believe the MacPorts instructions use ${prefix} rather than 
> /opt/local because it is technically possible to install MacPorts in a 
> location other than /opt/local.
> 
> Regarding nvim, the reason that zsh can’t find it is probably that the 
> directory /opt/local/bin is not included zsh's PATH environment 

Re: zsh problems MacOS High Sierra

2022-05-02 Thread Sriranga Veeraraghavan
Hi Jean,

I think that this isn’t working for you because MacPorts generally installs 
programs in /opt/local/bin.  

If you have installed zsh using MacPorts and you want to make the MacPort’s 
version of zsh your default shell, you’ll probably need to do something like 
the following:

$ sudo /bin/sh -c '/bin/echo /opt/local/bin/zsh >> /etc/shells’ 
$ /usr/bin/chsh -s /opt/local/bin/zsh

The first line adds /opt/local/bin/zsh to /etc/shells as a permitted login 
shell.  The command you were using only designated the Apple provided zsh, 
/bin/zsh, as a permitted login shell.  

The second line changes the default shell to /opt/local/bin/zsh.  The command 
you were using probably didn’t accomplish this for you because ${prefix} is a 
variable used to specify the MacPorts directory, which probably wasn’t defined. 
 I believe the MacPorts instructions use ${prefix} rather than /opt/local 
because it is technically possible to install MacPorts in a location other than 
/opt/local.

Regarding nvim, the reason that zsh can’t find it is probably that the 
directory /opt/local/bin is not included zsh's PATH environment variable.  I am 
not a zsh user, but I believe that you can probably fix this as follows:

$ /bin/echo 'PATH="$PATH:/opt/local/bin:/opt/local/sbin"' >> ~/.zshenv

With respect to the extra entries in /etc/shell, my guess is that, if the above 
steps gets things working for you, can just leave that file alone and it will 
not affect anything on your system.  If you want, you can edit that file and 
remove the extra entries. 

Please note, if you are using Terminal.app it still may not use the MacPort’s 
version of zsh as the default shell because I believe that Terminal.app has a 
separate preference that can be used to define the shell for new Terminal 
windows/tabs.  

I don’t have High Sierra installed on any of Macs, but I believe that if you 
open the Preferences windows in Terminal.app and then click on the General tab 
/ button, you will see a setting that reads something like “Shells open with:”. 
 This preference setting should allow you to configure which shell is used by 
Terminal.app.  You many need to change the setting to ‘/opt/local/bin/zsh’ to 
use the MacPorts version of zsh.

HTH,

-ranga

> On May 2, 2022, at 08:22, Jean Bermudez  wrote:
> 
> Hi there! 
> 
> I installed "NeoVim" and "zsh" via MacPorts on MacOs High Sierra.
> 
> I have a problem. High Sierra comes with "zsh" version 5.3 installed by 
> default. I noticed this after I installed zsh version 5.8.1 via MacPorts.
> 
> How did I figure it out?
> - I changed the default shell (bash) to "zsh" via the command "chsh -s 
> /bin/zsh".
> - I tried to start NeoVim with the command "nvim".
> - And the system responded "zsh: command not found: nvim".
> - After trying several things, I entered the command "zsh -version" and the 
> version that was active was 5.3 (High Sierra).
> - I went back to the "bash" shell and simply entered the command "zsh" to use 
> the zsh shell, and when I checked the version (zsh -version) the version was 
> 5.8.1 (MacPorts). I entered the command "nvim" and it worked.
> 
> I got desperate looking for a solution and entered several times the command 
> you provide on your site to set MacPorts': sudo sh -c 'echo ${prefix}/bin/zsh 
> >>/etc/shells'.
> 
> Now when I check the list of Shells with "cat /etc/shells". I get "/bin/zsh" 
> four times.
> 
> I want to delete all zsh and install only the MacPorts "zsh" cleanly; and 
> then set that shell to default.
> 
> How do I do this?



zsh problems MacOS High Sierra

2022-05-02 Thread Jean Bermudez
Hi there!

I installed "NeoVim" and "zsh" via MacPorts on MacOs High Sierra.

I have a problem. High Sierra comes with "zsh" version 5.3 installed by
default. I noticed this after I installed zsh version 5.8.1 via MacPorts.

How did I figure it out?
- I changed the default shell (bash) to "zsh" via the command "chsh -s
/bin/zsh".
- I tried to start NeoVim with the command "nvim".
- And the system responded "zsh: command not found: nvim".
- After trying several things, I entered the command "zsh -version" and the
version that was active was 5.3 (High Sierra).
- I went back to the "bash" shell and simply entered the command "zsh" to
use the zsh shell, and when I checked the version (zsh -version) the
version was 5.8.1 (MacPorts). I entered the command "nvim" and it worked.

I got desperate looking for a solution and entered several times the
command you provide on your site to set MacPorts': sudo sh -c 'echo
${prefix}/bin/zsh >>/etc/shells'.

Now when I check the list of Shells with "cat /etc/shells". I get
"/bin/zsh" four times.

I want to delete all zsh and install only the MacPorts "zsh" cleanly; and
then set that shell to default.

How do I do this?