Change default shell from bash to zsh by default?

1 Like

There’s one issue with the migration to zsh for existing users. New builds won’t have this issue. After the packages update, default shell is switched from bash to zsh, the ZDOTDIR environment variable won’t be set yet. When opening a terminal before rebooting, the following surprise (violates principle of least surprise), complicated and confusing message (for most users)

This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses ---

Users would certainly ask something like: Why does this happen? What should I configure?

Option A) Would creating an empty file /home/user/.zshrc be an acceptable solution?

if ! test -f  /home/user/.zshrc ; then
    sudo -u user touch /home/user/.zshrc || true
fi

Option B) Change default shell from bash to zsh only for new builds of Whonix but keep existing users on zsh for now? Then we could give users time to update, next time they update, they’ll already have ZDOTDIR environment variable and /etc/zsh/dist folder. Only users who don’t update for a for a long time would run into above issue.

Option A and B could in theory also be combined but not sure that’s good.

yes, but it won’t be read… because ZDOTDIR won’t be ~/ anymore, it is /etc/zsh/dist.

touch ~/.zshrc
Just touch the file without modification.

possibly forgot touch.

ZROOTDIR=/etc/zsh → Set by build
ZDOTDIR=/etc/zsh/dist → Set by us.

About option B, no opinion.

Yes, this would only hide the question and show the zsh standard configuration (without colors, command completion, exit codes and whatnot). It’s not a perfect solution. Just avoiding the worst usability issue.

Indeed. Edited my above post.

I don’t understand. But also mistake in my previous post. Should have written “ZDOTDIR”. Will edit. I didn’t want to suggest editing ZROOTDIR.
(Maybe that’s required. If yes, please mention. But form my side was just a typo for now.)

all good now. no issues.

1 Like

All of this is now in the developers repository.


Two issues…

  1. inconsistent ZDOTDIR environment variable
  • bug: With lightdm display manager (on my Debian host operating system + distro morphed into Kicksecure): ZDOTDIR environment variable missing
  • ok: Whonix Xfce for VirtualBox which is using gdm display manager: ZDOTDIR environment variable ok
  • ok: virtual consoles

Seems like DefaultEnvironment= isn’t as consistent / reliable as desired.

  1. changing default shell is failing in Whonix Xfce for VirtualBox

debian/dist-base-files.postinst command chsh --shell /bin/zsh user is failing due to permission denied (seen during apt dist-upgrade). (The chsh command doesn’t require sudo because Debian maintainer scripts run as root anyhow.)

:frowning:

I don’t know any reliable way of setting system wide variables before the shell is sourced.
Last resort would be to patch the /etc/zsh scripts provided by debian, which I understand is also undesired.

If for example the variable was set in the zsh system files, then it would not need to be set externally, only will be used by zsh sourcing.

1 Like

Issues:

  • POS1 key not working
  • END key not working

fixing

1 Like

You can use POS1 or ENDE or Ctrl+A and Ctrl+E for the same functionality.

See the bindkeys section for a lot of things that can be done with the control keys.

1 Like

Excellent! Merged. Thank you!

Currently I had the very same question:

The answer there worked for me. First I typed in the zsh shell:

bindkey '^ ' forward-word

This was handy to test this so I didn’t have to edit the zsh config right away just to try that solution. Once entered, I could use

ctrl + space

Now, before we add bindkey '^ ' forward-word to the zsh config by default… Are there some common / popular / convention zsh shortcuts? Then perhaps we should use the same instead of inventing ones which are only used by Kicksecure / Whonix?

Once that’s done, the most common hotkeys should be documented unless it’s already documented somewhere good enough upstream.

Readline library is what shells uses. Every shell has their own implementation, Zsh used Bash readline in the beginning then startd doing their own version.

Bash reads /etc/inputrc and ~/.inputrc, Zsh does not.

As for typing style, Vi-style line editor is POSIX while Emacs is not.

Zsh does not have default keybindings, it comes clean and you design your keybindings, but it is better to follow preexisting standards:

https://man.archlinux.org/man/readline.3#DEFAULT_KEY_BINDINGS
https://manpages.debian.org/bullseye/readline-common/readline.3readline.en.html

A good table I found is in the Arch Wiki.

The debian man page also has the table, but it is just a little bit more difficult to read without colors and column separation.
Order of precedence I will be using:

  • if Vi and Emacs keymap is empty, I will try to choose a non-used key
  • if one of the styles is empty, I will use the other style key.
  • if both are filled, I will prefer Vi because it is POSIX and not GNU only.
1 Like

Another thing is that some controls, even not specified on the zsh file, are acting their default behavior.

Example is ^I, which is the same as tab. I will add those also because then I don’t overwrite the default behavior they already have with different mappings.

Edit: some can’t be mentioned

zsh-syntax-highlighting: unhandled ZLE widget 'complete'
zsh-syntax-highlighting: (This is sometimes caused by doing `bindkey <keys> complete` without creating the 'complete' widget with `zle -N` or `zle -C`.)
``
1 Like

Now, before we add bindkey '^ ' forward-word to the zsh config by default

Didn’t find anything conflicting with ^ .

Are there some common / popular / convention zsh shortcuts? Then perhaps we should use the same instead of inventing ones which are only used by Kicksecure / Whonix?

Doing that following the readline man page (Arch or Debian, same thing)

Once that’s done, the most common hotkeys should be documented unless it’s already documented somewhere good enough upstream.

Just link to man page.

One default behavior I know that I changed is ^J to accept-search instead of the default accept-line.

^M is already accept-line, which equals to the Enter key.

Having ^J as accept-search is better for tab completion, you can select the option and type ^J to accept the search and continue typing.

1 Like
1 Like

Forward word and backward word is not Ctrl+arrows, where arrows are right and left arrows.

1 Like

I think this is the right way to go. macOS did this some time ago, but not for this reason.

Maybe with different colors/themes (I kinda like compartmentalization) in Whonix GW vs Whonix WS too, once again to prevent mistakes from happens, because they do, right?

Have a good one! // yodawins

1 Like

Currently the prompt is workstation|gateway user PWD, where workstation or gateway depends on the vm you are on. I see a problem with this is that it makes the prompt too large, but ws|gw would not be a suitable alternative because they only differ by one letter. Maybe setting the terminal background differently for the GW or WS would help, but that would be on XFCE, not on ZSH.

1 Like