Skip to content

Instantly share code, notes, and snippets.

@illucent
Last active April 2, 2021 00:20
Show Gist options
  • Save illucent/8132033 to your computer and use it in GitHub Desktop.
Save illucent/8132033 to your computer and use it in GitHub Desktop.
.bashrc file
# /etc/profile: This file contains system-wide defaults used by
# all Bourne (and related) shells.
# http://www.guguncube.com/259/unix-collection-of-useful-bash-aliases
# aliases//http://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html
# http://dotfiles.org/~basileaf/.bashrc
[ -z "$PS1" ] && return
if [ -n "$PS1" ]; then PATH='cw-definitions-path':$PATH; export PATH; fi
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
force_color_prompt=yes
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
# Prefer US English and use UTF-8
LANG=en_GB.UTF-8; export LANG
GDM_LANG=en_GB.UTF-8; export GDM_LANG
LC_ALL=en_GB.UTF-8; export LC_ALL
LC_TIME=en_GB.UTF-8; export LC_TIME
# Default umask. A umask of 022 prevents new files from being created group and world writable.
umask 022
# Set the values for some environment variables:
export MINICOM="-c on"
export MANPATH=/usr/local/man:/usr/man:$JAVA_HOME/man:$MANPATH
export HOSTNAME="`cat /etc/HOSTNAME`"
export LESSOPEN="|lesspipe.sh %s"
export LESS="-M" #FiX
export JAVA_HOME=/usr/lib/java/
export CLASSPATH=:$JAVA_HOME/lib/:$CLASSPATH
export JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel'
export LIBVA_DRIVER_NAME=vdpau
#export DRI_DRIVERS="radeon,r200"
export VDPAU_DRIVER=r600 # va_gl
export R600_HYPERZ=1
export R600_TILING=1
export R600_SURF=1
export R600_GLSL130=1
export R600_DEBUG=sb
export R600_STREAMOUT=1
#export GALLIUM_HUD=fps
#export XLIB_SKIP_ARGB_VISUALS=1
export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus
export SAL_GTK_USE_PIXMAPPAINT=1
# Set the default system $PATH:
export PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/google/depot_tools::/usr/games:$HOME/bin:$PATH:$JAVA_HOME/bin/:$PATH"
export LD_LIBRARY_PATH=$PATH:/usr/lib/i386-linux-gnu/:/usr/lib:/usr/local/lib
export vblank_mode=0
export AUDIODEV=hw
export SDL_AUDIODRIVER=alsa
# Bash history
export HISTSIZE=10000
export HISTFILESIZE=${HISTSIZE}
export HISTCONTROL=ignoreboth
export HISTTIMEFORMAT="%h/%d-%H:%M:%S "
export XDG_CURRENT_DESKTOP='xfce'
# Use GNOME UI https://wiki.openoffice.org/wiki/Environment_Variables
export OOO_FORCE_DESKTOP="GNOME"
export BROWSER="chrome"
export OS_LINUX
#export XDG_MENU_PREFIX="lxde-"
export EDITOR=vim
#GPG
export GPGKEY=5B3B1802
#prompt
export black="\[\033[0;38;5;0m\]"
export red="\[\033[0;38;5;1m\]"
export orange="\[\033[0;38;5;130m\]"
export green="\[\033[0;38;5;2m\]"
export yellow="\[\033[0;38;5;3m\]"
export blue="\[\033[0;38;5;4m\]"
export bblue="\[\033[0;38;5;12m\]"
export magenta="\[\033[0;38;5;55m\]"
export cyan="\[\033[0;38;5;6m\]"
export white="\[\033[0;38;5;7m\]"
export coldblue="\[\033[0;38;5;33m\]"
export smoothblue="\[\033[0;38;5;111m\]"
export iceblue="\[\033[0;38;5;45m\]"
export turqoise="\[\033[0;38;5;50m\]"
export smoothgreen="\[\033[0;38;5;42m\]"
export custom="\[\033[0;38;5;23m\]"
export custom2="\[\033[0;38;5;79m\]"
## some shopt options ##
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# correct minor spelling errors in cd
shopt -s cdspell
#include dotfiles in wildcard expansion, and match case-insensitively
shopt -s dotglob
# Case-insensitive globbing (used in pathname expansion)
shopt -s nocaseglob
shopt -s histappend
export prog='/home/IT/PROJECTS'
export packg='/home/IT/PACKAGES'
export gitrepo='/home/IT/GIT/'
alias ports='netstat -tulanp'
alias cat='LC_ALL=C cat -n'
alias openports='netstat -nape --inet'
alias grep='grep --color -n'
alias list='ls -al --color=always $@ | sort -k9,9'
alias calc='bc -l'
alias opsh='git add -A :/ && git commit -m "minor changes to css or js" --verbose && git push --verbose && git status'
alias l.='ls -d .* --color=auto'
alias mkdate='mkdir "$(date)" | sed 's/[[:space:]]//g''
alias gdrivewget='wget --no-check-certificate -O outputfile'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
#-----------------------------------------
# history completion using the arrow keys:
#-----------------------------------------
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
#-----------------------------------------
# search history of typed commands for a phrase / http://forum.manjaro.org/index.php?topic=995.0
#-----------------------------------------
hs() {
history | grep "$1"
}
# If the user doesn't have a .inputrc, use the one in /etc.
if [ ! -r "$HOME/.inputrc" ]; then
export INPUTRC=/etc/inputrc
fi
# For root users, ensure that /usr/local/sbin, /usr/sbin, and /sbin are in
# the $PATH. Some means of connection don't add these by default (sshd comes
# to mind).
if [ "`id -u`" = "0" ]; then
echo $PATH | grep /usr/local/sbin 1> /dev/null 2> /dev/null
if [ ! $? = 0 ]; then
PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH
fi
fi
# I had problems with the backspace key using 'eval tset' instead of 'TERM=',
# but you might want to try it anyway instead of the section below it. I
# think with the right /etc/termcap it would work.
# eval `tset -sQ "$TERM"`
# Set TERM to linux for unknown type or unset variable:
if [ "$TERM" = "" -o "$TERM" = "unknown" ]; then
TERM=linux
fi
# Notify user of incoming mail. This can be overridden in the user's
# local startup file (~/.bash.login or whatever, depending on the shell)
if [ -x /usr/bin/biff ]; then
biff y 2> /dev/null
fi
# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
if [ -x $profile_script ]; then
. $profile_script
fi
done
unset profile_script
# Load the shell dotfiles, and then some:
# * ~/.path can be used to extend `$PATH`.
# * ~/.extra can be used for other settings you don’t want to commit.
for file in ~/.{path,bash_prompt,exports,aliases,functions,extra}; do
[ -r "$file" ] && [ -f "$file" ] && source "$file"
done
unset file
# Enable some Bash 4 features when possible:
# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux`
# * Recursive globbing, e.g. `echo **/*.txt`
for option in autocd globstar; do
shopt -s "$option" 2> /dev/null
done
# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2)" scp sftp ssh
# Add tab completion for `defaults read|write NSGlobalDomain`
# You could just use `-g` instead, but I like being explicit
complete -W "NSGlobalDomain" defaults
# HTTP serve the current directory to 0.0.0.0 and safety port 8765
# Detect python version
# http://alias.sh/python-simple-http-server-1
ret=`python -c 'import sys; print("%i" % (sys.hexversion<0x03000000))'`
if [ $ret -eq 0 ]; then # Python version is >= 3
alias pyhttp='python -m http.server 8000'
else # Python version is < 3
alias pyhttp='python -m SimpleHTTPServer 8000'
fi
function mkdate
{
now=$(date +"%m_%d_%Y_%H_%M_%S");
mkdir -p $now
}
#### SAFETY ####
alias rm='rm -Iv --preserve-root'
alias mv='mv -iv'
alias cp='cp -iv'
alias ln='ln -i'
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$@"
}
# Automatically do an ls after each cd
cd() {
if [ -n "$1" ]; then
builtin cd "$@" && ls --group-directories-first -al
else
builtin cd ~ && ls --group-directories-first -al
fi
}
#=============================================================
# cd & ls in one :- when you cd to a directory the ls command
# automatically lists it's contents however you have configred
# ls to do so:
#-------------------------------------------------------------
cl() {
if [ -d "$1" ]; then
cd "$1"
ls -la --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F
else
echo "bash: cl: '$1': Directory not found"
fi
}
#=============================================================
# cd & ls & more in the same command. Pipes the output to more
#for use with directories with many files in their contents:
#-------------------------------------------------------------
# cd and ls & more in one
cm() {
if [ -d "$1" ]; then
cd "$1"
ls | more
else
echo "bash: cl: '$1': Directory not found"
fi
}
#functions
function extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
#
function psg() {
if [ ! -z $1 ] ; then
echo "Grepping for processes matching $1..."
ps aux | grep $1
else
echo "!! Need name to grep for"
fi
}
function path(){
old=$IFS
IFS=:
printf "%s\n" $PATH
IFS=$old
}
#trash
function trash(){
if [ -z "$*" ] ; then
echo "Usage: trash filename"
else
DATE=$( date +%F )
[ -d "${HOME}/.Trash/${DATE}" ] || mkdir -p ${HOME}/.Trash/${DATE}
for FILE in $@ ; do
mv "${FILE}" "${HOME}/.Trash/${DATE}"
echo "${FILE} trashed!"
done
fi
}
function pre_prompt {
newPWD="${PWD}"
user="whoami"
host=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
datenow=$(date "+%a, %d %b %y")
let promptsize=$(echo -n "┌(${PWD})($user@$host ddd., DD mmm YY)┐" \
| wc -c | tr -d " ")
let fillsize=${COLUMNS}-${promptsize}
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="${fill}─"
let fillsize=${fillsize}-1
done
if [ "$fillsize" -lt "0" ]
then
let cutt=3-${fillsize}
newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cutt\}\)\(.*\)/\2/")"
fi
}
PROMPT_COMMAND=pre_prompt
case "$TERM" in
xterm)
PS1="$bblue┌─($orange\u@\h \$(date \"+%a, %d %b %y\")$bblue)─\${fill}─($orange\$newPWD\
$bblue)─┐\n$bblue└─($orange\$(date \"+%H:%M\") \$$bblue)─>$custom "
;;
screen)
PS1="$bblue┌─($orange\u@\h \$(date \"+%a, %d %b %y\")$bblue)─\${fill}─($orange\$newPWD\
$bblue)─┐\n$bblue└─($orange\$(date \"+%H:%M\") \$$bblue)─>$custom "
;;
*)
PS1="┌─(\u@\h \$(date \"+%a, %d %b %y\"))─\${fill}─(\$newPWD\
)─┐\n└─(\$(date \"+%H:%M\") \$)─> "
;;
esac
# Determine what prompt to display:
# 1. Display simple custom prompt for shell sessions started
# by script.
# 2. Display "bland" prompt for shell sessions within emacs or
# xemacs.
# 3 Display promptcmd for all other cases.
function load_prompt () {
# Get PIDs
local parent_process=$(cat /proc/$PPID/cmdline | cut -d \. -f 1)
local my_process=$(cat /proc/$$/cmdline | cut -d \. -f 1)
if [[ $parent_process == script* ]]; then
PROMPT_COMMAND=""
PS1="\t - \# - \u@\H { \w }\$ "
elif [[ $parent_process == emacs* || $parent_process == xemacs* ]]; then
PROMPT_COMMAND=""
PS1="\u@\h { \w }\$ "
else
export DAY=$(date +%A)
PROMPT_COMMAND=pre_prompt
fi
export PS1 PROMPT_COMMAND
}
load_prompt
# Common junk
#[[ -s "$HOME/.commonrc" ]] && source "$HOME/.commonrc"
#alais.sh
findreplace(){
printf "Search: ${1}\n"
printf "Replace: ${2}\n"
printf "In: ${3}\n\n"
find . -name "*${3}" -type f | xargs perl -pi -e 's/${1}/${2}/g'
}
ft() {
find . -name "$2" -exec grep -il "$1" {} \;
}
#alias.sh
spy() {
lsof -i -P +c 0 +M | grep -i "$1"
}
# find - exclude svn, git, mercurial, repo, eclipse and intellij idea directories
# usage : f [directory] [find-options]
f(){
dir=$1
shift
find $dir -type d \( -name .svn -o -name .git -o -name .hg -o -name .repo -o -name .metadata -o -name .idea \) -prune -o $@ -print
}
pause() {
if $(killall -STOP "$1"); then
echo "[+] $1 successfully paused!"
else
echo "[-] Failed to pause $1"
fi
}
unpause() {
if $(killall -CONT "$1"); then
echo "[+] $1 successfully unpaused!"
else
echo "[-] Failed to unpause $1"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment