Montag, 10. Dezember 2012

This is my bashrc ...

based on debian 7 (wheezy) with systemd


# Dont Save duplicated history lines and remove these form the history file
HISTCONTROL=irgnoredups:erasedups

# show the date and time when the command was actually executed
HISTTIMEFORMAT="%F-%M-%S --> "

# ignore these command and receord them never to the history
HISTIGNORE="su":"su *":"sudo *":"sudo":"his":"his *":"history":"history *":"halt":"reboot":"apt-get *":"apt-cache *":"aptitude *":"dpkg *"

#CDPATH can be confgiured to have a list of fast available and often used paths
#use colons to add more , make sure using the . and .. so you always can cd into a directory whenver it is present in your $PWD and in another
CDPATH=.:..:/usr/share/:/media/:/home/l1zard/workspace/:/media/

# #functions
# this function is to search certain keywords in certain section
section()
{
if [ $# -eq 2 ]
then
apropos $1|grep \^\.\*[[:blank:]]\($2\) || echo "sorry no entry for $1 in section $2"
else
echo "Usgae: section word number"
fi
}


# function traffic lists open ports for user
traffic()
{
ping -c3 google.de && watch -n 10 lsof -i || echo "no network connecttivity"
}

# function to list kernel threads
showthreads()
{
if [ -z "$1" ]
then
ps -A u |sort -k5 -n|awk '{if($5 == 0){print}}'
else

ps -A u|sort -k5 -n|awk '{ if($5 == 0){print }}'| grep $1
fi
}


# function returns status information about the battery health (which is how good the baateries live is in general) and its status (which return how long it takes until the battery needs the next charge)
battery ()
{
case "$1" in
# returns the percentage of battery charge when discharging
"load")
now=$(cat /sys/class/power_supply/BAT0/energy_now)
full=$(cat /sys/class/power_supply/BAT0/energy_full)
out=$(echo $now/$full*100 | bc -l | cut -c 1-5)
echo "Charge: "$out"%"
;;

# returns the battery health. that is the percenatge of the maximal capacity
"health")
design=$(cat /sys/class/power_supply/BAT0/energy_full_design)
current=$(cat /sys/class/power_supply/BAT0/energy_full)
out=$(echo $current/$design*100 | bc -l | cut -c 1-5)
echo "Capacity: "$out"%"
;;

*) echo "Usage: battery load|health"
esac
}


# function cl to list and cd into a directory at the same time
cl()
{
if [ -z $1 ]
then
cd $HOME
ls
else
cd "$1"
ls
fi
echo "Content of $PWD:^^^"
}


# top 10 processes consuming the most cpu-time
top10()
{
if [[ -n $1 && $1 == "-m" ]]
then
ps auxf | sort -nr -k 4 | head -10
else
ps auxf | sort -nr -k 3 | head -10
fi
}

# function to get translate from dings default dictionary
translate ()
{
clear
tr \| \n < /usr/share/trans/de-en|grep --color $1
}

# little function to search for words in rfcs installed locally
rfcfind()
{
zgrep --color $* /usr/share/doc/RFC/rfc-index.txt.gz || echo "no subject found in rfc for $*"
}

# little function to access locally installed rfcs easily
rfc()
{
find /usr/share/doc/RFC/ -name rfc${1}.txt.gz -exec zless {} \; || echo "rfc ${1} does not exist"
}

# function to create and change into a directory in one step
# function adopted from O'Reilly Coookbook
mcd()
{
local NEW_DIR='_command_failed_'
if [ -z "$1" ]
then
echo "mcd: <Datei> [nnn]"
return 1
fi

if [ -d "$1" ]
then
echo "$1 exists"
NEW_DIR="$1"
else
if [ -n "$2" ]
then
mkdir -p -m $1 "$2" && NEW_DIR="$1" || return 1
else
mkdir -p "$1" && NEW_DIR="$1" || return 1
fi
fi

cd "$NEW_DIR"
}


##
# funkctions for systemctl
all()
{
echo "Functions for systemctl to handle more easily:"
echo "failed"
echo "loaded"
echo "masked"
echo "active"
echo "inactive"
echo "waiting"
echo "running"
echo "plugged"
echo "mounted"
echo "exited"
echo "dead"
echo "elpased"
}

failed ()
{
systemctl --no-pager --all|grep --color failed
systemctl --no-pager --all|grep --color error
}

loaded ()
{
systemctl --no-pager --all|grep --color loaded
}

masked ()
{
systemctl --no-pager --all|grep --color masked
}

active ()
{
systemctl --no-pager --all|grep --color active
}

inactive ()
{
systemctl --no-pager --all|grep --color inactive
}

waiting ()
{
systemctl --no-pager --all|grep --color waiting
}

running ()
{
systemctl --no-pager --all|grep --color running
}

plugged ()
{
systemctl --no-pager --all|grep --color plugged
}

mounted ()
{
systemctl --no-pager --all|grep --color mounted
}

exited ()
{
systemctl --no-pager --all|grep --color exited
}

dead ()
{
systemctl --no-pager --all|grep --color dead
}

elapsed ()
{
systemctl --no-pager --all|grep --color elapsed
}
##


# add /sbin to PATH to avoid anoying message
# add ~/bin to PATH
export PATH=$PATH:/sbin:/usr/local/sbin:/usr/sbin:~/bin

test -s ~/.alias && . ~/.alias || true


## make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi

## Nice greeting
echo -e '\E[32m Viel Spaß am Gerät!'; tput sgr0
## show the todo script i wrote everytime i open a shell
todo

## aliases set by user
alias df='dfc -sWT'
alias pine='alpine'
alias vimpdf='apvlv'
alias his='history'
alias last10='tail ~/.bash_history'
alias del='rm -i'
alias emacs='/usr/bin/emacs-nox'
alias fstat='stat -c "%a %n"'
alias hd='hexdump -C'
alias nameservers='grep 'nameserver' /etc/resolv.conf'
alias route='route -n'
alias vusers='cut -d: -f1 /etc/passwd'
# aliasses make the live with python more easier
alias py='/usr/bin/python3'
alias pydoc='pydoc3'
alias pyhelp='w3m /usr/share/doc/python3.2/html/index.html || echo "E: python documentation not installed, linked to wrong location or w4m not installed"'
alias ntpdate='/usr/bin/ntpq -p'
alias h='man'
alias lconfig='cd ~/.local_gitrc'
alias release='cat /etc/debian_version'
alias halt='sudo shutdown -P now'
alias reboot='sudo reboot'
alias update='sudo apt-get -y update && sudo apt-get -y --ignore-hold upgrade && sudo apt-get clean && sudo update-command-not-found && sudo  freshclam && sudo -k'
alias netstat='sudo /usr/bin/watch /bin/netstat -patunel'
# aliasses for systemctl
alias systemctl='systemctl --no-pager --all'
alias india='TZ=Asia/Kolkata date'
alias synaptic='gksu synaptic &'
alias deborphan='sudo gtkorphan'
alias gtkorphan='sudo gtkorphan'
alias fusebundlegen='avira_fusebundlegen'
alias howto='w3m /usr/local/share/doc/HOWTO/index.html'

Keine Kommentare:

Kommentar veröffentlichen

Hinweis: Nur ein Mitglied dieses Blogs kann Kommentare posten.