Cleanup and comment functions
now up() works in zsh
This commit is contained in:
parent
9ab748a6ca
commit
4d3e31d399
@ -1,4 +1,5 @@
|
|||||||
# Functions gathered from around the internet
|
# Functions gathered from around the internet
|
||||||
|
# Takes 1st argument and attempts to extract them in the current directory
|
||||||
extract () { # Extracts most common compressed files
|
extract () { # Extracts most common compressed files
|
||||||
if [ -f $1 ] ; then
|
if [ -f $1 ] ; then
|
||||||
case $1 in
|
case $1 in
|
||||||
@ -18,8 +19,19 @@ extract () { # Extracts most common compressed files
|
|||||||
echo "'$1' is not a valid file"
|
echo "'$1' is not a valid file"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
# Takes 1st argument and makes a .tar.gz archive
|
||||||
maketar() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
|
maketar() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
|
||||||
|
# Takes 1st argument and makes a .zip archive
|
||||||
makezip() { zip -r "${1%%/}.zip" "$1" ; }
|
makezip() { zip -r "${1%%/}.zip" "$1" ; }
|
||||||
|
# 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
|
||||||
psgrep() {
|
psgrep() {
|
||||||
if [ ! -z $1 ] ; then
|
if [ ! -z $1 ] ; then
|
||||||
echo "Grepping for processes matching $1..."
|
echo "Grepping for processes matching $1..."
|
||||||
@ -28,25 +40,7 @@ psgrep() {
|
|||||||
echo "!! Need name to grep for"
|
echo "!! Need name to grep for"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
gpass() { # Generates passwords
|
# dirsize - finds directory sizes and lists them for the current directory
|
||||||
local l=$1
|
|
||||||
[ "$l" == "" ] && l=20
|
|
||||||
tr -dc A-Za-z0-9-!@%^*_ < /dev/urandom | head -c ${l} | xargs
|
|
||||||
}
|
|
||||||
|
|
||||||
#up() { # Usage: up <Number of directories>. Blank for up one dir.
|
|
||||||
# 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
|
|
||||||
#}
|
|
||||||
#dirsize - finds directory sizes and lists them for the current directory
|
|
||||||
dirsize (){
|
dirsize (){
|
||||||
du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
|
du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
|
||||||
egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
|
egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
|
||||||
@ -54,18 +48,16 @@ dirsize (){
|
|||||||
egrep '^ *[0-9.]*G' /tmp/list
|
egrep '^ *[0-9.]*G' /tmp/list
|
||||||
rm -rf /tmp/list
|
rm -rf /tmp/list
|
||||||
}
|
}
|
||||||
myps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; }
|
# Usage: up <Number of directories>. Blank for up one dir.
|
||||||
ii() { # Get current host related info.
|
up() {
|
||||||
echo -e "\nYou are logged on ${BRed}$HOST"
|
local d=""
|
||||||
echo -e "\n${BRed}Additionnal information:$NC " ; uname -a
|
limit=$1
|
||||||
echo -e "\n${BRed}Users logged on:$NC " ; w -hs | cut -d " " -f1 | sort | uniq
|
for ((i=1; i <= limit; i++)); do
|
||||||
echo -e "\n${BRed}Current date :$NC " ; date
|
d=$d/..
|
||||||
echo -e "\n${BRed}Machine stats :$NC " ; uptime
|
done
|
||||||
echo -e "\n${BRed}Memory stats :$NC " ; free
|
d=$(echo $d | sed 's/^\///')
|
||||||
echo -e "\n${BRed}Diskspace :$NC " ; mydf / $HOME
|
if [ -z "$d" ]; then
|
||||||
echo -e "\n${BRed}Local IP Address :$NC" ; my_ip
|
d=..
|
||||||
echo -e "\n${BRed}Open connections :$NC "; netstat -pan --inet;
|
fi
|
||||||
echo
|
cd $d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user