Files
dotfiles/bash/bash_functions

92 lines
1.6 KiB
Bash
Raw Normal View History

2013-09-14 14:35:23 +02:00
#!/bin/bash
# File to define bash functions. Read by ~/.bashrc.
function mount() {
if [[ $# == 0 ]] ; then
/usr/bin/env mount | column -t
else
/usr/bin/env mount $*
fi
}
ff() {
find . -type f -iname "*"$*"*" ;
}
ffcs() {
find . -type f -name "*"$*"*" ;
}
extract() # Handy Extract Program.
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2 ) tar xvjf $1 ;;
*.tar.gz ) tar xvzf $1 ;;
*.bz2 ) bunzip2 $1 ;;
*.rar ) unrar x $1 ;;
*.gz ) gunzip $1 ;;
*.tar ) tar xvf $1 ;;
*.tbz2 ) tar xvjf $1 ;;
*.tgz ) tar xvzf $1 ;;
*.zip ) unzip $1 ;;
*.Z ) uncompress $1 ;;
*.7z ) 7z x $1 ;;
*) echo "$1 cannot be extracted via extract()" ;;
esac
else
echo "$1 is not a valid file"
fi
}
update() {
sudo bash -c "apt-get update && apt-get -y dist-upgrade && apt-get -y autoremove"
}
showclock() {
while : ; do
clear
echo "========"
date +"%T"
echo "========"
sleep 1
done
}
ruler() {
for s in '....^....|' '1234567890'; do
w=${#s}
str=$(for (( i=1; $i<=$(( ($COLUMNS + $w) / $w )) ; i=$i+1 )); do echo -n $s; done )
str=$(echo $str | cut -c -$COLUMNS)
echo $str
done
}
up() {
[ "${1/[^0-9]/}" == "$1" ] && {
local ups=""
for i in $(seq 1 $1)
do
ups=$ups"../"
done
cd $ups
} || echo "usage: up <INTEGER>"
}
ckwww() {
ping -c 3 www.google.com
}
topcmds() {
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head
}
fnottype() {
find . -maxdepth 1 ! -type $1
}
# simple calculator
? () {
echo "$*" | bc -l
}