rails / devcontainer

MIT License
63 stars 19 forks source link

Install OhMyZsh and set Zsh as default shell #37

Closed AliOsm closed 4 months ago

AliOsm commented 4 months ago

The Rails/Ruby image installs Zsh, but it is not configuring it as default. This change sets it as default, and also installs OhMyZsh. DevContainer users can set Zsh as default shell using a post creation script, but it requires multiple lines of bash script as implemented here. So, setting it the as default shell is easier. Also, as far as I know, DevContainer users can't override image feature settings, so if there is a place to do this change is inside the image build.

AliOsm commented 4 months ago

Hello again @andrewn617 , could you please take a look at this?

AliOsm commented 4 months ago

Hello @akhilgkrishnan , first of all Zsh and OhMyZsh are providing multiple features better than the default shell, like jumping to the command in the history by writing its first few characters and pressing arrow up.

For the configuration part, as I mentioned in my PR details, because rails/ruby feature is setting up common-utils feature, I have 2 options only as an end user:

So, the solution in my opinion is either making Zsh a default shell and benefit from OhMyZsh, or remove common-utils from rails/ruby feature, and allow the end user to configure it as he wants.

andrewn617 commented 4 months ago

Hi @AliOsm

Thank your for opening this PR. As @akhilgkrishnan mentioned, we aren't going to support custom shells in this image. As for removing common utils from the image, we are relying on it for more than just shells so we can't do that either.

You can set zsh to the default shell with one line in your Dockerfile:

RUN sudo chsh -s /bin/zsh vscode

(Make sure you are using image version 1.1.1 otherwise rbenv will not be initialized properly for zsh. If you are using a ruby version only tag like ruby:3.3.3 you may need to prune that image in order to pull the latest version).

Now, as for why adding common-untils to your Dev Container and including configureZshAsDefaultShell doesn't work, that seems wrong. When I add that feature to a Dev Container using the ruby image, I notice that /home/vscode/.zshrc seems to be overwritten with the default zshrc file losing the rbenv initialization. But it looks like there is code in that feature to avoid that happening - so I am not sure what is happening. But the feature should definitely not be overwriting the user's .zshrc so I think it is worth a report on that repo.

AliOsm commented 4 months ago

For details on why common-utils overwrites .zshrc check https://github.com/devcontainers/features/issues/1035.