Bash-it / bash-it

A community Bash framework.
MIT License
14.27k stars 2.29k forks source link

Include update-bash section in the docs #1614

Closed davesteinberg closed 1 year ago

davesteinberg commented 4 years ago

After using Bash-it very happily on Linux, I'm now trying it on macOS (10.15.5, with bash 3.2.57), and I'm having all sorts of weird line break/line wrap problems. The problems seem to stem from scm_prompt_info, as they don't appear when I'm using a theme that doesn't use it or when I'm not in a git repo.

The problems I'm seeing include unexpected line breaks in the middle of my prompt, early line wrapping (while I'm typing, before I get to the end of the line), line wrapping that doesn't actually advance to the next line (the cursor just returns to the beginning of the current line), and messing up the xterm title (I'm using the xterm plugin). However, the exact problems seem to vary with the theme, the terminal application (I've tried Terminal and iTerm, and both are affected), the width of the terminal window, the particular directory I'm in, and the previous command.

Here's a screen shot that shows most of these problems:

Bash-it Bug

In the upper terminal, notice:

  1. The line break in the 4th and 5th prompts (it actually comes in the middle of an escape series, but that isn't always the case).
  2. The early line wrap in the second echo command.
  3. The messed up window title (a command isn't running; it's showing a previous one that already completed).

I'm using a custom theme here, but I see the same sorts of problems with built-in themes that use scm_prompt_info.

I'm using just three plugins:

Here's my .bash_profile:

#!/usr/bin/env bash
export BASH_SILENCE_DEPRECATION_WARNING=1

# If not running interactively, don't do anything
case $- in
  *i*) ;;
    *) return;;
esac

# Path to the bash it configuration
export BASH_IT="/Users/dave/.bash_it"
export BASH_IT_CUSTOM="$HOME/.bash_it.custom"

# Lock and Load a custom theme file.
# Leave empty to disable theming.
# location /.bash_it/themes/
export BASH_IT_THEME='one'

# (Advanced): Change this to the name of your remote repo if you
# cloned bash-it with a remote other than origin such as `bash-it`.
# export BASH_IT_REMOTE='bash-it'

# Your place for hosting Git repos. I use this for private repos.
export GIT_HOSTING='git@git.domain.com'

# Don't check mail when opening terminal.
unset MAILCHECK

# Change this to your console based IRC client of choice.
export IRC_CLIENT='irssi'

# Set this to the command you use for todo.txt-cli
export TODO="t"

# Set this to false to turn off version control status checking within the prompt for all themes
export SCM_CHECK=true

# Set Xterm/screen/Tmux title with only a short hostname.
# Uncomment this (or set SHORT_HOSTNAME to something else),
# Will otherwise fall back on $HOSTNAME.
#export SHORT_HOSTNAME=$(hostname -s)

# Set Xterm/screen/Tmux title with only a short username.
# Uncomment this (or set SHORT_USER to something else),
# Will otherwise fall back on $USER.
#export SHORT_USER=${USER:0:8}

# Set Xterm/screen/Tmux title with shortened command and directory.
# Uncomment this to set.
#export SHORT_TERM_LINE=true

# Set vcprompt executable path for scm advance info in prompt (demula theme)
# https://github.com/djl/vcprompt
#export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt

# (Advanced): Uncomment this to make Bash-it reload itself automatically
# after enabling or disabling aliases, plugins, and completions.
# export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=1

# Uncomment this to make Bash-it create alias reload.
# export BASH_IT_RELOAD_LEGACY=1

# Load Bash It
source "$BASH_IT"/bash_it.sh

It is the standard one created by the install script, with a few minor additions:

  1. I've defined BASH_SILENCE_DEPRECATION_WARNING to suppress the Catalina nag message when you use Bash.
  2. I've defined BASH_IT_CUSTOM to point at the directory with my custom theme and aliases.
  3. I've changed BASH_IT_THEME to select my custom theme.

Here's my theme:

#!/usr/bin/env bash
#
# One: A simple theme with bright colors and a one-line prompt.

# LS_COLORS for GNU, LSCOLORS for BSD (converted with https://gist.github.com/thomd/7667642)
export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'
export LSCOLORS="ExGxFxdaCxDaDahbadacec"

# SCM prompt theme
SCM_THEME_PROMPT_PREFIX="${normal} (${bold_cyan}"
SCM_THEME_PROMPT_SUFFIX="${normal})"
SCM_THEME_PROMPT_CLEAN=" ✓"
SCM_THEME_PROMPT_DIRTY=" ${bold_red}✗"

# Prompt function
function prompt() {
  if [[ $(whoami) = root ]]; then user_color=$bold_red; else user_color=$bold_green; fi
  PS1="${normal}[${user_color}\u${bold_green}@\h${normal}:${bold_blue}\W${normal}]$(scm_prompt_info)${normal}$ "
}

safe_append_prompt_command prompt

Bash-it is at ~/.bash_it, but that is a symlink into my Dotbot-based dotfiles repo, where I've added Bash-it as a submodule.

Strangely, what I did find solves the problem is simply commenting out the last line of my .bash_profile and then manually sourcing bash_it.sh from within the interactive shell. That's what the lower terminal in the screen shot shows. Notice how I'm not able to reproduce any of the problems in it.

I have no idea what could be different about letting .bash_profile source bash_it.sh vs. manually doing it immediately afterward. So, I'm very stumped. I'm happy to try things out to get to the bottom of this, if any one has any ideas.

nwinkler commented 4 years ago

Thanks for the detailed description! As a first step, I recommend that you update Bash to v5.0, this can be done through Homebrew. The shipped Bash v3 is ancient...

I'm also running Catalina, but with the powerline-multiline theme, in Terminal.app. A couple of comments:

I tried the echo commands with my current setup, and I don't have these issues:

  master → origin  ~/.bash_it                                                                                                       08:56:06  ⚡ 86%  nils.winkler 
❯ echo 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
  master → origin  ~/.bash_it                                                                                                       08:56:35  ⚡ 86%  nils.winkler 
❯ echo 123456789012345678901234567890
123456789012345678901234567890
  master → origin  ~/.bash_it                                                                                                       08:56:46  ⚡ 86%  nils.winkler 
❯ 

This is what I have in my ~/.bash_profile for the theme settings:

export BASH_IT_THEME='powerline-multiline'
export POWERLINE_LEFT_PROMPT='scm python_venv ruby cwd'
export BATTERY_AC_CHAR="⚡ "
export POWERLINE_PADDING=1
export POWERLINE_COMPACT=0

Maybe give this a try to see if the Powerline theme has the same issues for you?

davesteinberg commented 4 years ago

@nwinkler Thanks for the excellent debugging instructions. As it turns out, I didn't have to go past your first suggestion. Switching to Bash 5 from Homebrew immediately solved the problems I was seeing.

I knew that macOS ships an ancient version of Bash, but I'd only thought of that as an inconvenience for my own scripting. I had no idea that using it would break Bash It or, to be honest, that upgrading would be so easy (I'm already using Homebrew).

Knowing this would have saved me a ton of time, and I wouldn't have wasted yours with this bug, either.

What would you think about declaring a Bash requirement (4.something?) and putting this information in the README's Installation section? Something like this?

Bash Dependency

Bash It requires Bash 4.?? or later to run correctly. Any reasonably current Linux distribution should have shipped with a compatible version of Bash. However, macOS users must upgrade from the included, obsolete Bash version 3. We recommend using Homebrew to do this:

$ brew install bash
$ sudo sh -c 'echo /usr/local/bin/bash >> /etc/shells'
$ chsh  -s /usr/local/bin/bash

Also, now I don't think setting BASH_SILENCE_DEPRECATION_WARNING is a good idea, since you only get the nag when you're using the ancient, macOS-included Bash, which we've just established you should not do. I've removed it from my own .bash_profile.

nwinkler commented 4 years ago

I like the idea of having a note in the README. We might want to add that some functionality might work with Bash 3, but there's no guarantee that everything will work.

NoahGorny commented 1 year ago

Closed in #2146 well done @dylanjtuttle :)