Hacker News new | ask | show | jobs
by oinksoft 4782 days ago
I think the zsh-vs-bash debate is centered on minimalist vs. full-featured. For instance, the git completion example is very ugly in zsh to me. I know what git commands do, and I'd much prefer for the completion to take 1-2 lines total than one line per possible command, as in the zsh example. The prompt examples are similar -- my PS1 is

  local green="$(tput setaf 2)"
  local reset="$(tput sgr0)"
  export PS1="\[$green\]>>\[$reset\] "
And a multiline prompt, let alone one with right-justified elements, is pretty gruesome to me.

The first slides about availability on Macintoshes don't resonate, because I'm going to have MacPorts on any dev box and use that to install the latest. It's more likely I ssh to a server that has Bash 4 and no Zsh than anything else, so it also makes sense to know bash and have a good .bashrc ready to scp up there if I'm going to be doing a lot of work on the server.

zsh spellcheck is very annoying, thankfully it can be disabled. This is my preferred spellcheck solution ;^) https://github.com/mtoyoda/sl

All that being said, zsh is a really cool piece of software. It's one of those things I've always wanted to really stretch to its limits, but I've never been able to hang with it for more than a few months, which I doubt is enough time to really become accustomed to the workflows zsh allows (like the /u/b/... expansion example in the slides).

3 comments

Bash isn't really "minimalist" compared to the likes of dash or mksh. [rob-pike]Completion is a compromise, the Unix Way is to make your commands short and simple enough that you can memorize them all![/rob-pike]

  local green="$(tput setaf 2)"
  local reset="$(tput sgr0)"
  export PS1="\[$green\]>>\[$reset\] "
Could be this in zsh:

  export PS1="%{%F{green}%}>>%{%f%} "
- %{%} replace \[\] - %F{color} sets the foreground colour - %f resets the foreground colour

I would go with something like:

  export PS1="%{%(?.%F{green}.%F{red})%}>>%{%f%} "
It will be green if the last command exiting successfully, otherwise it will be red.

There's also better history support (from my zsh config):

  # History
  # ~~~~~~~

  HISTSIZE=1000
  SAVEHIST=1000
  HISTFILE=$HOME/.zsh_history

  setopt SHARE_HISTORY        # Share history across sessions
  setopt HIST_IGNORE_SPACE    # commands starting w/ a space don't go into history

  # SHARE_HISTORY seems to imply both of these, at least that's how the manpage
  #   reads, so let's comment them out for now.
  #
  # setopt INC_APPEND_HISTORY   # Incrementally append history to file
  # setopt EXTENDED_HISTORY     # Save the timestamp and duration of commands to history file
Actually, except the `SHARE_HISTORY` option (which can be emulated), everything else is available in Bash.
Sorry, I just copy-pasted the whole thing. I know that most of the other options are available, though I didn't know that the HIST_IGNORE_SPACE was available in bash.
In bash you'd use HISTCONTROL=ignorespace
According to the manpage, ignorespace doesn't treat multi-line commands very nicely.
You would have to disable the cmdhist option for that to matter:

  shopt -u cmdhist
Or I guess be working with a bash old enough to not support cmdhist.
Actually, I just tried the foreground/background stuff (similar to yours, but my own code, slightly different) and it works fine in bash 4.
I'm unclear what you mean by foreground/background stuff. I'm looking at the manpage for bash 4.2, and I don't see any short-hand for the color escape codes in prompts.
The spellcheck isn't even on by default.