Skip to content

Instantly share code, notes, and snippets.

@Gen2ly
Created March 22, 2014 14:01
Show Gist options
  • Save Gen2ly/9707581 to your computer and use it in GitHub Desktop.
Save Gen2ly/9707581 to your computer and use it in GitHub Desktop.
# Bash-configuration for user
# Check for an interactive session
[ -z "$PS1" ] && return
## Settings ##
set_prompt_style () { # Custom prompt
local bldpur='\e[1;35m' # Purple
local bldblu='\e[1;34m' # Blue
local bldblk='\e[1;30m' # Black - Bold
local bldred='\e[1;31m' # Red
local txtrst='\e[0m' # Text Reset
#local bashuser="\[$bldpur\]\u@\[$txtrst\]" # username
local bashhost="\[$bldpur\]\h\[$txtrst\]" # hostname
local bashdir="\[$bldblu\]\w\[$txtrst\]" # directory
local bashprompt="\[$bldblk\]:\n\[$txtrst\]" # prompt symbol
if [ `whoami` == "root" ] ; then
# local bashuser="\[$bldred\]\u@\[$txtrst\]"
local bashhost="\[$bldred\]\h\[$txtrst\]"
fi
PS1="$bashuser$bashhost $bashdir$bashprompt"
if [ "$(awk '$5=="/" {print $1}' </proc/1/mountinfo)" != "$(awk '$5=="/" {print $1}' </proc/$$/mountinfo)" ]; then
PS1="$bashuser$bashhost(chroot) $bashdir$bashprompt"; fi
}
set_prompt_style
PROMPT_COMMAND='echo -ne "$bashuser$bashhost $bashdir$bashprompt"'
# History file: http://tinyurl.com/lvtonry, http://tinyurl.com/q4dvgek
# HS: history command limit in active session (saved in mem. [def.: 500])
# HFS: history command limit in history file
# HC: erase previous matching duplicates
# hst: append entries instead of overwriting
# PC: add command to history after executing
HISTSIZE=5000
HISTFILESIZE=20000
HISTCONTROL=erasedups
shopt -s histappend
PROMPT_COMMAND='history -a'
# Autocorect 'cd' mis-spellings
shopt -s cdspell
# Extended pattern matching features
#shopt -s extglob
# Hostname expansion
#shopt -s hostcomplete
# Bash completion extended (single press on partial or no-completion)
set show-all-if-ambiguous on
# Redirected output will not overwrite files
#set -o noclobber
# Allow 'less' to view non-text files (i.e. compressed files)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
# 'ls' colors
eval $(dircolors -b)
# 'grep' colors
alias grep='grep --color=auto'
export GREP_COLOR="1;37" # white
# Less Colors for Man Pages
if [[ ${TERM} == "xterm" ]]; then
export LESS_TERMCAP_md=$'\e[01;38;5;74m' # bold mode - main (cyan)
export LESS_TERMCAP_us=$'\e[38;5;97m' # underline mode - second (purp)
export LESS_TERMCAP_so=$'\e[38;5;252m' # standout-mode - info/find (gray)
export LESS_TERMCAP_mb=$'\e[01;31m' # begin blinking - unused? (red)
export LESS_TERMCAP_ue=$'\e[0m' # end underline
export LESS_TERMCAP_se=$'\e[0m' # end standout-mode
export LESS_TERMCAP_me=$'\e[0m' # end all mode - txt rest
else
export LESS_TERMCAP_md=$'\e[01;34m'
export LESS_TERMCAP_us=$'\e[01;35m'
export LESS_TERMCAP_so=$'\e[01;30m'
export LESS_TERMCAP_mb=$'\e[01;31m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_me=$'\e[0m'
fi
# Script directory
scrpt_dir=$HOME/.local/bin
# Path
export PATH="$scrpt_dir:$scrpt_dir/arch:$scrpt_dir/bugfixes:$scrpt_dir/others:$scrpt_dir/root:$scrpt_dir/backup:$scrpt_dir/root/testing:$scrpt_dir/testing:$PATH"
## Aliases ##
# Bash Navigation/Tools
alias ls='ls --color=auto --group-directories-first' # add color, group dir
alias ls1='ls -1' # sort by line
alias lsd='ls -lAtrh' # sort by date
alias lsl='ls -lAh' # long list, human-readabl
alias lss='ls -shAxSr' # sort by size
alias lsx='ls -lAhX' # sort by extension
alias treeview='tree -C | less -R' # tree directory w/ pager
alias ebash="v ~/.bashrc"
alias sbash="source ~/.bashrc"
# Shortcuts
if [[ "$(whoami)" == "root" ]]; then
alias cds="cd $scrpt_dir/root && ls -h"
else
alias cds="cd $scrpt_dir && ls -h"; fi
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias cdd="cd ~/Desktop && ls -h"
alias cdp="cd ~/.local/arbld"
alias cdt="cd ~/.local/share/Trash/files && ls -h"
alias cdv="cd ~/Videos"
# System
alias chot="sudo chown -R todd:users"
alias chx="chmod +x"
alias cron="crontab -e"
alias rcron="su -c $(printf "%q " "crontab -e")"
alias pn="ping -c2 archlinux.org"
# Programs
alias d="define"
alias g="bgcmd gedit"
alias rg="bgcmd gksudo gedit"
alias iotop="sudo iotop" # iotop now requires root access
alias lessq="less -R"
alias pasteit="gist -a"
alias v="vim -p"
alias vi="vim -p"
alias vim="vim -p"
alias sv="sudo vim -p" # open in tab
alias wget="wget -c" # always try to resume download first
## functions ##
abacus () { awk "BEGIN { print $* ; }"; }
#ad () { pwd > ~/.config/ad ;}
#bd () { cd "$(cat ~/.config/ad)" ;}
pdfcat () {
gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-sOutputFile=concatenated.pdf "$@" ;}
youple () {
mplayer -cache 200 -really-quiet $(youtube-dl -g --max-quality mp4 "$@" ) ;}
## Bash-completion ##
complete -W "`awk '{ print $2 }' /etc/hosts`" ssh
complete -cf sudo
complete -cf gksu
complete -cf bgcmd
## Other ##
# Package lookup (if get: command not found)
#source /usr/share/doc/pkgfile/command-not-found.bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment