Created
December 7, 2018 12:20
-
-
Save benpitman/98bb83145e3668da264951f357930a88 to your computer and use it in GitHub Desktop.
My personalised bashrc
This file contains hidden or 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
alias rm='rm -i' | |
alias cp='cp -i' | |
alias mv='mv -i' | |
if [ -f /etc/bashrc ]; then | |
. /etc/bashrc | |
fi | |
prompt_command() { | |
local RETNUM=$? | |
if [[ $- =~ x ]]; then | |
local debug='set -x' | |
set +x | |
fi | |
local RESET GREY RED GREEN YELLOW BLUE PURPLE CYAN WHITE | |
local ret_col self parent pathname pathdirs hiddendirs pathfiles hiddenfiles linkfiles address prefix | |
RESET='\e[0m' | |
GREY='\e[1;30m' | |
RED='\e[1;31m' | |
GREEN='\e[1;32m' | |
YELLOW='\e[0;33m' | |
BLUE='\e[1;34m' | |
PURPLE='\e[1;35m' | |
CYAN='\e[0;36m' | |
WHITE='\e[0;37m' | |
(( $RETNUM )) && ret_col="${RED}" || ret_col="${GREEN}" | |
self=$( basename "$PWD" ) | |
if [[ "$self" == '/' ]]; then | |
unset self | |
else | |
parent=$( basename $( dirname "$PWD" ) ) | |
[[ "$parent" == '/' ]] && unset parent | |
fi | |
pathname="$parent/$self" | |
[[ ~ == "/$pathname" ]] && pathname='~' | |
content=$(ls -FA1 2>/dev/null) | |
pathdirs=$( grep '/$' <<< "$content" | wc -l ) | |
hiddendirs=$( grep '^\..*/$' <<< "$content" | wc -l ) | |
pathfiles=$( grep '[^@/]$' <<< "$content" | wc -l ) | |
hiddenfiles=$( grep '^\.[^@/]*$' <<< "$content" | wc -l ) | |
linkfiles=$( grep '@$' <<< "$content" | wc -l ) | |
[[ "$USER" == "root" ]] && prefix='#' || prefix='$' | |
address=$(git branch 2>/dev/null | grep -Po '^\* \K.*') | |
if [ -z "$address" ]; then | |
address=$( ip a | grep 'state UP' -A2 | grep -Po 'inet \K.*?(?=\/)' ) | |
fi | |
printf "${ret_col}%-4d${PURPLE}%s${GREY}@${BLUE}%s ${CYAN}[%s] ${WHITE}%s\n" "$RETNUM" "$address" $( date '+%I:%M:%S' ) "${pathdirs}D(${hiddendirs}H) ${pathfiles}F(${hiddenfiles}H ${linkfiles}L)" "$pathname" | |
PS1="\[${YELLOW}\]\!\[${WHITE}\]:${prefix} \[${RESET}\]" | |
$debug | |
} | |
PROMPT_COMMAND=prompt_command | |
export EDITOR='nano' | |
export VISUAL='nano' | |
alias lll='ls -alF' | |
alias rc='nano ~/.bashrc && exec bash' | |
stty -ixon | |
source /usr/local/bin/travel.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment