Category Archives: Shell Related

On Ubuntu 13+ and higher, /etc/bash_completion.d/git is now git-prompt

In this previous post I wrote about how to get some git branch information into your shell. That was written back when Ubuntu 12 LTS was the standard.

I recently upgraded a box to Ubuntu 16 LTS, and this information went away. 🙁

I discovered via trial and error, that the call that’s needed in .bashrc is now:

## To show you what branch you are in as you move around git repos
##
if [ -f /etc/bash_completion.d/git-prompt ]; then
. /etc/bash_completion.d/git-prompt
PS1='\[\u@\h \e[33m\]\w\[\e[0m\] $(__git_ps1 " (%s)")\n\$ '
fi


/etc/bash_completion.d/git is now: /etc/bash_completion.d/git-prompt

My favorite way to run screen

First, make sure you have screen installed:

[bash]
$ sudo apt-get install screen
[/bash]

Then, create a .screenrc file with the following in it:
[bash]
screen -t root sudo su –
screen -t bash2
screen -t bash3

select 0
startup_message off

caption always "%{= kw}%-w%{= bw}%n %t%{-}%+w %-= @%H – %c – (%l)"
#
# Call via: screen -R -e^Hh -d
#
# to change the strings, look at:
# http://www.gnu.org/software/screen/manual/screen.html#String-Escapes
#
# to test your changes, you can either copy the above line, the do
# CTRL-H : and then paste in the line above
#
# or, CTRL-H :source ~/.screenrc
[/bash]

Lastly, start up screen:
[bash]
screen -R -e^Hh -d
[/bash]

This let’s you switch screens by pressing CTRL-H and then SPACEBAR. (I found that I use CTRL-A far too much to let that be the standard screen key binding)

Git – automagically add modified files and rm deleted files

Sometimes a script will upgrade/add/modify/delete a large swath of files (possibly due to an upgrade-type script). If you are lazy, then you’ll want a script to help you commit those files. Here’s what I’ve come up with:

To perform a git add to all modified files:
[bash]
for file in `git status | grep modified | cut -d ":" -f 2`; do git add $file; done
[/bash]

To perform a git rm to all modified files:
[bash]
for file in `git status | grep deleted | cut -d ":" -f 2`; do git rm $file; done
[/bash]