Last active
April 23, 2020 21:33
-
-
Save trusktr/10602678 to your computer and use it in GitHub Desktop.
Bash configuration with custom prompt, aliases, and some other goodies.
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
# vim: set ft=sh: | |
# | |
# /etc/bash.bashrc.custom | |
# | |
## BEGIN ENVIRONMENT VARS | |
# Add local ruby gems to our PATH. How to add system-wide gems? | |
export PATH=$PATH:~/.gem/ruby/1.9.1/bin | |
# proper encoding for the linux terminal (ttys) | |
if [ "$TERM" = linux ] ; then | |
export T3WINDOW_OPTS=acs=utf8 | |
fi | |
# global node module location | |
export NODE_PATH=$NODE_PATH:/usr/lib/node_modules:/usr/local/lib/node_modules | |
## END ENVIRONMENT VARS | |
################################################## | |
# Fancy PWD display function | |
################################################## | |
# The home directory (HOME) is replaced with a ~ | |
# The last pwdmaxlen characters of the PWD are displayed | |
# Leading partial directory names are striped off | |
# /home/me/stuff -> ~/stuff if USER=me | |
# /usr/share/big_dir_name -> ../share/big_dir_name if pwdmaxlen=20 | |
################################################## | |
export NEW_PWD="Hello there young jedi apprentice." | |
dynamicPS1() { | |
# How many characters of the $PWD should be kept | |
local pwdmaxlen=35 | |
# Indicate that there has been dir truncation | |
local trunc_symbol="..." | |
local dir=${PWD##*/} | |
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen )) | |
NEW_PWD=${PWD/#$HOME/\~} | |
local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen )) | |
if [ ${pwdoffset} -gt "0" ] | |
then | |
NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen} | |
NEW_PWD=${trunc_symbol}/${NEW_PWD#*/} | |
fi | |
PS1="\n${BRed}┌─[${BGreen}\t${BRed}/${BYellow}\h${BRed}/${BBlue}\u${BRed}${BRed}/${BPurple}${NEW_PWD}${BRed}]${BRed}\n└─╼ ${ColorOff}" | |
} | |
## colors | |
# Reset | |
ColorOff='\[\e[0m\]' # Text Reset | |
BColorOff='\[\e[1;0m\]' # Text Reset | |
# Regular Colors | |
Black='\[\e[0;30m\]' # Black | |
Red='\[\e[0;31m\]' # Red | |
Green='\[\e[0;32m\]' # Green | |
Yellow='\[\e[0;33m\]' # Yellow | |
Blue='\[\e[0;34m\]' # Blue | |
Purple='\[\e[0;35m\]' # Purple | |
Cyan='\[\e[0;36m\]' # Cyan | |
White='\[\e[0;37m\]' # White | |
# Bold | |
BBlack='\[\e[1;30m\]' # Black | |
BRed='\[\e[1;31m\]' # Red | |
BGreen='\[\e[1;32m\]' # Green | |
BYellow='\[\e[1;33m\]' # Yellow | |
BBlue='\[\e[1;34m\]' # Blue | |
BPurple='\[\e[1;35m\]' # Purple | |
BCyan='\[\e[1;36m\]' # Cyan | |
BWhite='\[\e[1;37m\]' # White | |
# Underline | |
UBlack='\[\e[4;30m\]' # Black | |
URed='\[\e[4;31m\]' # Red | |
UGreen='\[\e[4;32m\]' # Green | |
UYellow='\[\e[4;33m\]' # Yellow | |
UBlue='\[\e[4;34m\]' # Blue | |
UPurple='\[\e[4;35m\]' # Purple | |
UCyan='\[\e[4;36m\]' # Cyan | |
UWhite='\[\e[4;37m\]' # White | |
# Background | |
On_Black='\[\e[40m\]' # Black | |
On_Red='\[\e[41m\]' # Red | |
On_Green='\[\e[42m\]' # Green | |
On_Yellow='\[\e[43m\]' # Yellow | |
On_Blue='\[\e[44m\]' # Blue | |
On_Purple='\[\e[45m\]' # Purple | |
On_Cyan='\[\e[46m\]' # Cyan | |
On_White='\[\e[47m\]' # White | |
# High Intensity | |
IBlack='\[\e[0;90m\]' # Black | |
IRed='\[\e[0;91m\]' # Red | |
IGreen='\[\e[0;92m\]' # Green | |
IYellow='\[\e[0;93m\]' # Yellow | |
IBlue='\[\e[0;94m\]' # Blue | |
IPurple='\[\e[0;95m\]' # Purple | |
ICyan='\[\e[0;96m\]' # Cyan | |
IWhite='\[\e[0;97m\]' # White | |
# Bold High Intensity | |
BIBlack='\[\e[1;90m\]' # Black | |
BIRed='\[\e[1;91m\]' # Red | |
BIGreen='\[\e[1;92m\]' # Green | |
BIYellow='\[\e[1;93m\]' # Yellow | |
BIBlue='\[\e[1;94m\]' # Blue | |
BIPurple='\[\e[1;95m\]' # Purple | |
BICyan='\[\e[1;96m\]' # Cyan | |
BIWhite='\[\e[1;97m\]' # White | |
# High Intensity backgrounds | |
On_IBlack='\[\e[0;100m\]' # Black | |
On_IRed='\[\e[0;101m\]' # Red | |
On_IGreen='\[\e[0;102m\]' # Green | |
On_IYellow='\[\e[0;103m\]' # Yellow | |
On_IBlue='\[\e[0;104m\]' # Blue | |
On_IPurple='\[\e[10;95m\]' # Purple | |
On_ICyan='\[\e[0;106m\]' # Cyan | |
On_IWhite='\[\e[0;107m\]' # White | |
## history settings. | |
export HISTFILE=~/.bash_history | |
export HISTFILESIZE=10000 | |
export HISTSIZE=10000 | |
export HISTCONTROL=erasedups | |
#export HISTTIMEFORMAT="[$(tput setaf 6)%F %T$(tput sgr0)]: " | |
#export HISTIGNORE=hcln | |
#shopt -s histappend | |
## automatic commands executed before each prompt. | |
export PROMPT_COMMAND="history -a; dynamicPS1; $PROMPT_COMMAND" | |
## execute a command before every command, including the ones in PROMPT_COMMAND | |
#trap 'echo "foobar"' DEBUG | |
## execute a command when the shell exits | |
trap 'echo "Goodbye!"' EXIT | |
## GENERAL SHELL OPTIONS | |
shopt -s checkwinsize # fix line wrap on window resize | |
shopt -s autocd # Auto "cd" when entering just a pathname | |
stty -ixon # disable freezing of the terminal when pressing ctrl+s | |
## Default editor | |
export EDITOR=vim | |
## grep color | |
export GREP_OPTIONS='--color=auto' | |
## ls color. Color rules can be stored in a file and loaded with dircolors. NOTE: This needs to be changed on different systems. | |
export `dircolors | sed 's/^.//' | sed 's/..$//'` # sets up the LS_COLORS environment variable for ls with default colors. | |
## BEGIN aliases and alias functions | |
## colors for man pages | |
man() { | |
env \ | |
LESS_TERMCAP_mb=$(printf "\e[1;31m") \ | |
LESS_TERMCAP_md=$(printf "\e[1;31m") \ | |
LESS_TERMCAP_me=$(printf "\e[0m") \ | |
LESS_TERMCAP_se=$(printf "\e[0m") \ | |
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \ | |
LESS_TERMCAP_ue=$(printf "\e[0m") \ | |
LESS_TERMCAP_us=$(printf "\e[1;32m") \ | |
man "$@" | |
} | |
alias rm='rm -I' # -I: prompt before removing | |
alias mv='mv -i' # -i: prompt before overwrite | |
alias ~='cd ~' | |
alias .="pwd" | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
alias ls="ls -F --group-directories-first --color=auto" # this doesn't work for some reason. EDIT: This didn't work because I was overwriting it in ~truktr/.bashrc | |
alias l=ls | |
alias ll="ls -l" | |
alias la="ls -A" | |
alias lla="ls -lA" | |
alias lal="ls -lA" | |
alias h='history' | |
alias href='echo -n "Refreshing history... "; hcln; history -c; history -r; echo "done."' #refresh the history. See hcln below. | |
alias clear="clear; archey" | |
alias mce="mc -e" # mcedit | |
alias sudo="sudo " #makes sudo recognize aliases. | |
alias untar="tar -xzvf" | |
alias mkdir="mkdir -p" | |
alias screenoff="xset dpms force off" | |
#alias less=vimpager #TODO only if vimpager is detected | |
alias j=jobs | |
alias vi=vim | |
#alias cat=lolcat #TODO only if lolcat is detected | |
alias weechat="weechat-curses" | |
## END aliases | |
## execute these at the beginning of the session: | |
dynamicPS1 # custom prompt style (see the definition above). | |
hcln # clean the history (see /usr/bin/hcln). | |
### Chrome OS | |
##If the home folder is mounted with noexec, remount with exec. | |
#mount | grep home/chronos/user | cut -d\( -f2 | grep noexec > /dev/null | |
#if [ $? -eq 0 ]; then | |
#sudo mount -i -o remount,exec /home/chronos/user | |
#echo " --" Mounted ChromeOS home folder with exec. | |
#else | |
#echo " --" ChromeOS home folder already remounted with exec. | |
#fi | |
##If the root folder is mounted read-only, remount read-write. | |
#mount | grep " / " | cut -d\( -f2 | grep "\bro\b" > /dev/null | |
#if [ $? -eq 0 ]; then | |
#sudo mount -i -o remount,rw / | |
#echo " --" Mounted ChromeOS root folder read-write. | |
#else | |
#echo " --" ChromeOS root folder already remounted with read-write. | |
#fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment