Hacker News new | ask | show | jobs
by pyre 4782 days ago

  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
2 comments

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.