Created
September 21, 2012 11:52
-
-
Save juanlu-sanz/3761053 to your computer and use it in GitHub Desktop.
Bash profile with separator, time (from Lifehacker) and git branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This file should be saved in your home directory. | |
function parse_git_dirty { | |
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" | |
} | |
function parse_git_branch { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/" | |
} | |
# Fill with minuses | |
# (this is recalculated every time the prompt is shown in function prompt_command): | |
fill="--- " | |
reset_style='\[\033[00m\]' | |
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color | |
prompt_style=$reset_style | |
command_style=$reset_style'\[\033[1;29m\]' # bold black | |
# Prompt variable: | |
PS1="$status_style"'$fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)'"$command_style " | |
# Reset color for command output | |
# (this one is invoked every time before a command is executed): | |
trap 'echo -ne "\e[0m"' DEBUG | |
function prompt_command { | |
# create a $fill of all screen width minus the time string and a space: | |
let fillsize=${COLUMNS}-9 | |
fill="" | |
while [ "$fillsize" -gt "0" ] | |
do | |
fill="-${fill}" # fill with underscores to work on | |
let fillsize=${fillsize}-1 | |
done | |
# If this is an xterm set the title to user@host:dir | |
case "$TERM" in | |
xterm*|rxvt*) | |
bname=`basename "${PWD/$HOME/~}"` | |
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007" | |
;; | |
*) | |
;; | |
esac | |
} | |
PROMPT_COMMAND=prompt_command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wget -nc -O ~/.bash_ps1 https://raw.github.com/gist/3761053/c6de170fde1ce9b3b16237cecb3e6f6138854050/.bash_ps1 | |
if grep "/.bash_ps1\" ]; then" ~/.bashrc | |
then | |
echo "[WARNING]: It seems your .bashrc file already has this piece of code added (not necessarily a bad thing)" | |
else | |
echo -e "if [ -f \"/.bash_ps1\" ]; then\n . \"$HOME/.bash_ps1\"\n fi" >> ~/.bashrc | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget -mc -O gitsole.sh https://raw.github.com/gist/3761053/da069922c3c5be60bc55553c26c68846d1d059e2/gitsole.sh; chmod +x gitsole.sh; ./gitsole.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment