Skip to content

Instantly share code, notes, and snippets.

@Nebula83
Last active November 28, 2019 07:17
Show Gist options
  • Save Nebula83/33bd1489a53ce4ebbf7b9f0d3b191a88 to your computer and use it in GitHub Desktop.
Save Nebula83/33bd1489a53ce4ebbf7b9f0d3b191a88 to your computer and use it in GitHub Desktop.
BASH shell script
# System-wide .bashrc file for interactive bash(1) shells.
# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# Check if we are in an Xsession in which case we skip all of this
[ "$PROGNAME" = "Xsession" ] && return
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, overwrite the one in /etc/profile)
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
setup_subtitle() {
SUBTITLE=""
SPACER=""
### GIT
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [[ ! -z $GIT_BRANCH ]]
then
SUBTITLE="\033[1;33mgit\033[0m:\033[1;33m$GIT_BRANCH\033[0m-"
# Check if WC clean
if [[ -z $(git status --porcelain) ]]
then
SUBTITLE+="\033[1;32m✓"
else
SUBTITLE+="\033[1;31m❌"
fi
# Check for stash empty
if [[ ! -z $(git stash list) ]]
then
SUBTITLE+="\033[1;31mS\033[0m"
fi
SPACER=" "
fi
## SVN
SVN_STATUS=$((svn status --depth=empty > /dev/null)2>&1)
if [[ -z $SVN_STATUS ]]
then
SVN_BRANCH=$(svn info 2> /dev/null | grep -E "^URL" | awk -F '/' '{print $NF}')
if [[ -z $SVN_BRANCH ]]
then
SVN_BRANCH='?'
fi
SUBTITLE+=$SPACER
SUBTITLE+="\033[1;33msvn\033[0m:\033[1;33m$SVN_BRANCH\033[0m-"
# Check if WC clean
if [[ -z $(svn status --ignore-externals | grep ^X -v) ]]
then
SUBTITLE+="\033[1;32m✓"
else
SUBTITLE+="\033[1;31m❌"
fi
fi
if [[ -z $SUBTITLE ]]
then
SUBTITLE=$TERM$WINDOW
fi
printf "$SUBTITLE"
}
# if this terminal supports colors, set ultra-fancy prompt
if [ -t 1 ]
then
has_color=$(tput colors)
if [ $has_color != 0 ]
then
BLUE="\[\033[1;34m\]"
NO_COLOR="\[\033[0m\]"
WHITE="\[\033[0m\]"
RED="\[\033[1;31m\]"
BLUE="\[\033[1;34m\]"
LIGHT_BLUE="\[\033[1;34m\]"
YELLOW="\[\033[1;33m\]"
NO_COLOUR="\[\033[0m\]"
case $TERM in
xterm*|rxvt*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR=""
;;
esac
HEAD="$TITLEBAR\n$BLUE[$NO_COLOR"
HEAD=${HEAD}""
CURPATH=""
PS1="$TITLEBAR\n$BLUE[$NO_COLOR"
PS1=${PS1}"\$(date +%H:%M)-\$(date \"+%a %d %b %y\")$BLUE]"
PS1=${PS1}"<$NO_COLOR\$(setup_subtitle)$BLUE>"
PS1=${PS1}"-($NO_COLOR \w $BLUE)\n"
# Differentiate for root prompt
if [ $UID == 0 ]
then
PS1=${PS1}"$RED\u$BLUE@$NO_COLOR\h$RED# $NO_COLOR"
else
PS1=${PS1}"$NO_COLOR\u$BLUE@$NO_COLOR\h$BLUE> $NO_COLOR"
fi
fi
fi
# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
# ;;
#*)
# ;;
#esac
# enable bash completion in interactive shells
#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi
# Setup some aliases
alias l1='ls -1'
alias ll='ls -lh'
alias la='ll -A'
alias cd..='cd ..'
alias ..='cd ..'
# Setup some colored aliases
if [ -t 1 ]
then
has_color=$(tput colors)
if [ $has_color != 0 ]
then
alias ls='ls --color=auto'
fi
fi
export PATH=$PATH:~/scripts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment