manjaro / release-plan

Roadmap for our Manjaro install media releases
85 stars 7 forks source link

consider to switch to zsh #47

Open philmmanjaro opened 8 years ago

philmmanjaro commented 8 years ago

On further improving shell experience and colors and stuff we can switch to zsh. It's compatible with bash, but much faster.

It will take some work to deploy a new config for zsh. but... there's oh-my-zsh for that, which ships a bucketload of themes. It will also improve our development work as zsh would for example instantly display git branch status and so on. So it is the very same thing, and even with additional functionality. Arch already uses zsh as default shell on their live-media.

philmmanjaro commented 8 years ago

Here is an oldy but goldy from Teo about this topic.

udeved commented 8 years ago

That wouldn't hurt at all, because upstream zsh package does not deploy any /etc/skel files. So the entire bash config with extension files became obsolete, which is caused by bash upstream providing /etc/skel/ bashrc files

udeved commented 8 years ago

https://github.com/manjaro/manjaro-tools/commit/5e1246d638d9eeb505431aa1d2a18c7ba49b255b

Chrysostomus commented 7 years ago

I think switching to zsh is a good idea. I would suggest that we ship simple zshrc instead of oh-my-zsh. Something with prompt similar to our bash prompt (or simpler), and autocd enabled. Oh-my-zsh is too heavy and complex for most users.

philmmanjaro commented 7 years ago

CAL supports this now with the development version. However the new users module still needs a better UI.

jonathonf commented 7 years ago

ZSH isn't a drop-in BASH replacement; I'd be very cautious about assuming things would "just work".

Most scripts are written to target a portable /bin/sh or, when extra functions are needed, /bin/bash. Noone writes portable scripts targeted at /usr/bin/zsh. Therefore BASH would need to be installed by default alongside ZSH, and in that case I can't see the benefit of setting ZSH as the default as a user can switch their shell as they wish.

If you can list any distros that have a default shell other than BASH (or DASH, but that's Ubuntu so meh) I'll reconsider. :)

Chrysostomus commented 7 years ago

I think arch and gentoo use it on their install media. I could be wrong though.

Not having bash is not an option, because so many basic tools depend on it.

Sure, for scripting purposes zsh is not a drop in replacement (for example anything using arrays should break). But as a login shell it definitely is (properly configured). I don't think anyone is suggesting we replace /bin/sh with it, 'cause that would not make any sense. Switching to dash might yield some performance increase, but with zsh the benefit would be negligible.

But as a login shell it would definitely make sense. It is more user friendly, which would be in spirit of manjaro. And unlike fish, it doesn't break anything.

Chrysostomus commented 7 years ago

I propose we make a configuration package for zsh. zsh-settings, manjaro-zshrc or something. I suggest something similar to what bspwm edition has, but with prompt closer to bash default.

Chrysostomus commented 7 years ago

I made a pull request at packages-community, adding manjaro-zsh-config.

Features:

I made this with the intention of offering it for common manjaro zsh configuration. It should similar enough to bash to be approachable, and well enough commented to be understandable, while improving shell experience for beginners and advanced users alike.

The files are here: https://github.com/Chrysostomus/manjaro-zsh-config

Maybe we could use this as a starting point for finding a configuration that would be agreeable to most of us?

excalibur1234 commented 7 years ago

i like your .zshrc file.

i have just tested it and the only things i would change are:

Chrysostomus commented 7 years ago

Thanks, I'll update it. Imho 100 is enough because no duplicates are saved, but 1000 is fine too and more common.

Chrysostomus commented 7 years ago

Hmm... I think I found a way to improve word recognition (as in don't consider full file paths single words for the purposes of movement and word deleting). I think I'll add that

excalibur1234 commented 7 years ago

the first line looking for /etc/profile.d/cnf.sh only works, if pkgfile is installed: https://wiki.archlinux.org/index.php/Pkgfile https://wiki.archlinux.org/index.php/Zsh#The_.22command_not_found.22_hook at least this is what i have read about it. but i have not tested that. i am also not sure, whether pkgfile can work in manjaro or not

please make it work (e.g. by making pkgfile a dependency) or remove that line.

Chrysostomus commented 7 years ago

It is there to be ready when we get support for .files. https://github.com/manjaro/release-plan/issues/98 No point in adding pkgfile before it works, but once it does, we can just add the dependency. But this preparation for it is harmless.

excalibur1234 commented 7 years ago
Chrysostomus commented 7 years ago

Currently the $ becomes # when shell has elevated privileges. I can modify it to change color too.

Maybe we could conditionally display git status in right prompt when in git repo? I have used some git status prompts, what information should be displayed?

jonathonf commented 7 years ago

Just a note of caution - be careful not to reinvent the wheel. There are things like powerline that will do an awful lot of what you're talking about without a great deal of extra configuration.

All you'd probably need is to change the default blue prompt to a Manjaro green.

Chrysostomus commented 7 years ago

Yes, I'm not going to write anything from scratch, for reinvented wheels are expensive and often full of angles.

I think powerline is a bit much for average user, I would leave that to user discretion.

This right prompt would be unintrusive, as it is displayed only when in git repos: https://techanic.net/2012/12/30/my_git_prompt_for_zsh.html

excalibur1234 commented 7 years ago

"what information should be displayed?" the branch name or commit hash ( if in detached head state) you are working on and maybe, the git status (whether all changes are committed or not). these are the things i have noticed the most using the git themes in oh-my-zsh.

i have always looked at powerline as an overkill, especially for non-vim users.

volklord commented 7 years ago

My two cents :
Making zsh default shell doesn't/won't "replace" bash, in fact scripts can still be run with bash (#!/bin/bash) in scripts or bash -c "command" in command line.
One of the most benefits of zsh is auto completion and from my experience without grml-zsh-config package installed you get half the power of zsh IMO.

Chrysostomus commented 7 years ago

Would you then suggest that we enable menu completion like grml does?

excalibur1234 commented 7 years ago

i have just uploaded my customized version of your .zshrc file: https://github.com/excalibur1234/manjaro-zsh-config/blob/master/.zshrc

i have also adopted the git prompt from your link above and included the display of exit code from last command (look at lines 267-415)

Chrysostomus commented 7 years ago

Looks interesting, I like the cd aliases and the fact that it lists contents when entering a new directory.

I don't think we should alias pacui and yaourt if we aim this to be common for all editions, because not all editions have it. For a similar reason I refrained from adding a keybinding to bmenu...

I'll adopt most of your modifications, I think.

jonathonf commented 7 years ago

Please don't override built-in commands. That's going to get annoying very quickly. cd means "change directory", nothing else. ;)

Also, having aliases for non-standard packages will create confusion for anyone who runs them, e.g.:

alias y='yaourt'
alias p='pacui'

play() {
  if [[ $# == 0 ]]; then
    mpv --no-video --shuffle --playlist <(find "$PWD" -type f -follow)
    ...

What does this one do?

alias sudo='sudo '
Chrysostomus commented 7 years ago

Yeah, that part did not get merged. It's fine for personal use but not as common default.

jonathonf commented 7 years ago

I was going to edit but you got back too quickly. :P I should have also said, adding an alias e.g. cdl which does e.g. cd "$@"; ls; would be fine.

excalibur1234 commented 7 years ago

as you have seen, this is my personal .zshrc file. this means that there are personal things in it, which are not recommended for general use.

this includes most aliases. the "play" function looks for music files in your current directory (or the directory you have specified and plays it in a playlist with mpv. if a web address is given, it tries to play the music there. this function is not meant for general use, because it depends on mpv!

also the "cd && ll" function is really useful in bash, but not really necessary in zsh. i recommend to remove it from there (or at least uncomment it by default.

thanks for reminding me about the "sudo" alias. i just removed it, too.

Chrysostomus commented 7 years ago

I have no idea what that sudo thing does, I think I got it from somewhere. Pacui and yaourt aliases were not merged.

Merged features currently:

jonathonf commented 7 years ago

as you have seen, this is my personal .zshrc file. this means that there are personal things in it, which are not recommended for general use.

That's fine - just you linked to it in this thread so I thought it was related.

excalibur1234 commented 7 years ago

i have taken a look at grml-zsh-config as suggested above. but the problem is that grml-zshrc is REALLY customized. you need a while to become familiar with it - and its syntax cannot simpy copied to an ordinary .zshrc file.

either way, i think we already have a lot of features in our .zshrc file already.

Chrysostomus commented 7 years ago

I actually started by trying to modify grml-zsh-config, but soon gave up because of its complexity.

I think that if we keep adding much more features, the shell startup time is going to suffer.

excalibur1234 commented 7 years ago

i agree. our zsh should be more comfortable than default bash while not being noticeably slower - even on slow computers.

if there are are no obvious features missing, i recommend to push manjaro-zsh-config into the unstable branch and make an announcement (including a description how to change shell to zsh). then, people can start to test it and give feedback. we can also ask the rest of the team for feedback.

volklord commented 7 years ago

@Chrysostomus I don't think it "needs" to be modified, it works(TM) out of the box and offers a basic git prompt. That's what the archlinux install media has, zsh + grml-zsh-config and it is more than enough for installing and system administration.

Chrysostomus commented 7 years ago

@archderwelt Thanks for feedback! Manjaro-architect now offers choice of grml-zsh-config and manjaro-zsh-config after installing a manjaro edition.

I would prefer that we would prefer our own configuration because

I started manjaro-zsh-config, because grml-zsh-config just doesn't feel very manjaro to me, but more like arch/debian. That being said, grml is still a valid and respectable choice.

volklord commented 7 years ago

@Chrysostomus True, the distros have different ideals and concerning the point of branding/customizing ["user friendly" <=> "do it your self/keep it simple and stupid"]. Also true grm-zsh-config has 'nothing' manjaro specific, but nothing arch specific as well, the blue color is just by chance. Am using zsh/grml combo on my manjaro (stable) machine and it rocks :-) . I will have to try the manjaro version, so far I can't say any thing yet about it.

a bit more mysterious about where it keeps its files

pacman -Ql grml-zsh-config should "print" the files.

Chrysostomus commented 7 years ago

Thanks, I do know how to find it, I was using colorful language to illustrate their difference in complexity. manjaro-zsh-config is just the zshrc with scripts that are visibly sourced.

By arch specific I meant that it is congruent with the arch way to ship upstream packages. It is actual goal with arch linux, while manjaro is indifferent to the matter. Some packages are upstream, some are manjaro branded.

Chrysostomus commented 7 years ago

Could you further tell what is it that is like about grml-zsh-config? You obviously have been using it longer than I.

Things I liked:

I have mixed feelings about it using a menu for tab completion. It looks really cool, but in practice I prefer normal tab completion.

volklord commented 7 years ago

While I am a typical "standard" user, I can't dig in technical things and all I can say for the moment is :
I have used zsh without grm-zsh-config and the user experience is quite different, e.g if a file/dir name is uppercase and you type it lowercase, it feels like bash, but with grml-zsh it doesn't matter. You type first letter(s) lowercase, hit tab and name gets corrected. A big plus for me, saves pressing shift.
Apart from the enhanced auto completion, it sets also sane defaults and plenty of helpful stuff in /etc/zsh/zshrc (line 1138 for example), these features might be overkill but a starting point for customizing and adjusting to fit the manjaro ideals.
It feels like the two completes each other, this is why I suggested it.

Chrysostomus commented 7 years ago

Thanks for input. Manjaro-zsh-config has case insensitive completion enabled too. I'll look into grml further to see if I can find something interesting.

excalibur1234 commented 7 years ago

i still think that .zshrc should also be copied into the /root/ directory. this way, the command prompt becomes red after typing "su" and giving your password. without .zshrc in /root/ directory, you simply see a default shell.

is there any reason for not doing this?

Chrysostomus commented 7 years ago

I haven't gotten around to do it yet.

Chrysostomus commented 7 years ago

Done now in 0.2 update. Also added undo (shift+tab), switched prompt to maia and made some other tweaks.

jonathonf commented 7 years ago

I'd be wary of having giving root a heavily-customised profile (for any shell). For example, if it sources a configuration file it is doing so as root. Some of the options may also not be appropriate - for example, option nohup sounds like it could be pretty awful if you're not aware of what it does, and option autocorrect is not something that should be enabled for root. If you mess up your system because you mistype, that's one thing. If "autocorrect" gets it wrong, that's unforgivable (plus what you actually typed won't show up in history).

I'd err on the side of keeping root's shell as a plain as possible. Anyone messing round as root can always introduce their own configuration - and if you're operating in a root shell this much you're doing it wrong.

udeved commented 7 years ago

I see root account config for apps, besides some colours in terminal, very critical. I am no fan, to provide eg thunar root settings. Users should be reminded they are using root power, ugly theme is easiest reminder.

oberon-manjaro commented 7 years ago

I think actually what it does is provide config to make root shell look different from normal user shell. Or am I wrong, @Chrysostomus ?

udeved commented 7 years ago

I am generally no fan of over customization. If a user wants to have an alias to terminate a process, he should add it. This kind of stuff should not be default, we also do some not so good stuff with bashrc.

Chrysostomus commented 7 years ago

Good points about root user. I'll make adjustments.

Chrysostomus commented 7 years ago

I now made a separate, more plain zshrc for root. I doesn't source anything, does not have nohub set and no autocorrect. The only alias I kept for root is alias cp="cp -i". It still has good tab completion, ctrl+arrows movement, colored man pages and autocd. The prompt is now exact bash prompt replica.

For normal user I also kept alias x='startx ~/.xinitrc', because it is so useful for editions that don't use displaymanager.

I don't think autocorrect option is that dangerous, because it only commits changes after "did you mean?" - dialog. But as @jonathonf said, better to err on the side of caution.

philmmanjaro commented 6 years ago

@Chrysostomus: What is the current status on this one?

Chrysostomus commented 6 years ago

Works, has been used in some community editions for a long time now. The issues with qt terminals have been solved. If others agree, I feel that it is ready to be included