[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Pimp your shell - Debian developer tips?



On 6/3/20 7:30 PM, Gunnar Wolf wrote:
Like Paul said in his reply, I also have a "bash monstrosity" as a
Bash prompt.

For many years, I have taken a different approach; use the default and add only a few minor changes. Each stable update, I use /etc/skel/.bashrc and edit/add in my little bits.

Other than uncommenting a few existing color & alias configs in the default file, I configure history to allow .bash_history grep from any open shell session, and keep a lot more:

# save every command, as opposed to only at the end of the session
export PROMPT_COMMAND='history -a'

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=20000
HISTFILESIZE=40000

# Useful to know where we stand while using different version control systems
parse_git_branch() {
     # Yes, temporary, dirty, yada yada yada. Works for me™.
     # --exclude-standard does not exist on git <= 1.5
     git_opts='--exclude-standard'
     branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
     if [ ! -z "$branch" ]
     then
	clean=`git status --porcelain`
	if [ ! -z "$clean" ]
	then
	    branch="${branch}*"
	    new=`git ls-files -o $git_opts|wc -l`
	    del=`git ls-files -d $git_opts|wc -l`
	    mod=$(( `git ls-files -m $git_opts|wc -l` - $del ))
	    if [ $mod != 0 ]; then branch="${branch}${mod}M"; fi
	    if [ $new != 0 ]; then branch="${branch}${new}N"; fi
	    if [ $del != 0 ]; then branch="${branch}${del}D"; fi

	fi
     fi
     echo $branch
}

Gunnar's git branch foo is what really lead me to post my default .bashrc change strategy. I also depend on knowing branch name and repo status state and use this PS1 config:

# adapted from http://people.planetpostgresql.org/dfetter/index.php?/archives/53-Git-+-bash-win.html # https://web.archive.org/web/20161013111148/http://www.bramschoenmakers.nl/en/node/624
if [ -f /usr/bin/git ]; then
  export GIT_PS1_SHOWDIRTYSTATE=1
  PSGIT='\[\033[01;31m\]$(__git_ps1 "(%s)")\[\033[00m\]'
  PS1="$PSGIT$PS1"
fi

--
Kind regards,
Michael


Reply to: