2016-06-14 19:13:17 +00:00
|
|
|
# Functions gathered from around the internet
|
2017-06-21 19:00:18 +00:00
|
|
|
# Takes 1st argument and attempts to extract them in the current directory
|
2016-06-14 19:13:17 +00:00
|
|
|
extract () { # Extracts most common compressed files
|
|
|
|
if [ -f $1 ] ; then
|
|
|
|
case $1 in
|
|
|
|
*.tar.bz2) tar xjf $1 ;;
|
|
|
|
*.tar.gz) tar xzf $1 ;;
|
|
|
|
*.bz2) bunzip2 $1 ;;
|
|
|
|
*.rar) rar x $1 ;;
|
|
|
|
*.gz) gunzip $1 ;;
|
|
|
|
*.tar) tar xf $1 ;;
|
|
|
|
*.tbz2) tar xjf $1 ;;
|
|
|
|
*.tgz) tar xzf $1 ;;
|
|
|
|
*.zip) unzip $1 ;;
|
2017-06-21 19:00:18 +00:00
|
|
|
*.Z) uncompress $1 ;;
|
2016-06-14 19:13:17 +00:00
|
|
|
*) echo "'$1' cannot be extracted via extract()" ;;
|
2017-06-21 19:00:18 +00:00
|
|
|
esac
|
|
|
|
else
|
2016-06-14 19:13:17 +00:00
|
|
|
echo "'$1' is not a valid file"
|
2017-06-21 19:00:18 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
# Takes 1st argument and makes a .tar.gz archive
|
2018-02-11 03:36:07 +00:00
|
|
|
maketgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
|
2017-06-21 19:00:18 +00:00
|
|
|
# Takes 1st argument and makes a .zip archive
|
2016-06-14 19:13:17 +00:00
|
|
|
makezip() { zip -r "${1%%/}.zip" "$1" ; }
|
2017-06-21 19:00:18 +00:00
|
|
|
# Generate password - 1st argument is the number of characters, defaults to 20
|
|
|
|
gpass() {
|
|
|
|
local l=$1
|
|
|
|
[ "$l" == "" ] && l=20
|
|
|
|
tr -dc A-Za-z0-9-!@%^*_ < /dev/urandom | head -c ${l} | xargs
|
|
|
|
}
|
|
|
|
# Shows the current PS list for the signed in user - Not cygwin compatible
|
|
|
|
myps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; }
|
|
|
|
# Searches the process list (ps) for 1st argument
|
2016-06-14 19:13:17 +00:00
|
|
|
psgrep() {
|
|
|
|
if [ ! -z $1 ] ; then
|
|
|
|
echo "Grepping for processes matching $1..."
|
|
|
|
ps aux | grep $1 | grep -v grep
|
2017-06-21 19:00:18 +00:00
|
|
|
else
|
2016-06-14 19:13:17 +00:00
|
|
|
echo "!! Need name to grep for"
|
2017-06-21 19:00:18 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
# dirsize - finds directory sizes and lists them for the current directory
|
2016-06-14 19:13:17 +00:00
|
|
|
dirsize (){
|
|
|
|
du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
|
|
|
|
egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
|
|
|
|
egrep '^ *[0-9.]*M' /tmp/list
|
|
|
|
egrep '^ *[0-9.]*G' /tmp/list
|
|
|
|
rm -rf /tmp/list
|
2017-06-21 19:00:18 +00:00
|
|
|
}
|
|
|
|
# Usage: up <Number of directories>. Blank for up one dir.
|
|
|
|
up() {
|
|
|
|
local d=""
|
|
|
|
limit=$1
|
|
|
|
for ((i=1; i <= limit; i++)); do
|
|
|
|
d=$d/..
|
|
|
|
done
|
|
|
|
d=$(echo $d | sed 's/^\///')
|
|
|
|
if [ -z "$d" ]; then
|
|
|
|
d=..
|
|
|
|
fi
|
|
|
|
cd $d
|
2017-06-22 17:22:53 +00:00
|
|
|
}
|
2019-10-16 16:45:20 +00:00
|
|
|
# Usage: search <regex string>
|
|
|
|
search () {
|
|
|
|
grep -r "$1" | fzf
|
|
|
|
}
|
2020-03-24 19:55:38 +00:00
|
|
|
# Usage: replay <number of commands> to repeat. Blank for 1
|
|
|
|
replay() {
|
|
|
|
from="${1:-2}"
|
|
|
|
to="${2:-1}"
|
|
|
|
if [ "$from" -ne "$to" ]; then
|
|
|
|
for i in `seq "$from" -1 "$(($to + 1))"`; do
|
|
|
|
printf "$(fc -ln -${i} -${i}) && "
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
$(fc -ln -${to} -${to})
|
|
|
|
}
|