This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# flexible xmessage (uses xmessage or gmessage) or printf for printing messages | |
function x11message() | |
{ #prints a message using xmessage || gxmessage | |
[ -z "$1" ] && return 1 | |
XMESSAGE=$(command -v gxmessage 2>/dev/null) || XMESSAGE=$(command -v xmessage 2>/dev/null) | |
MESSAGE="$(expr "$0" : '.*/\([^/]*\)'): $*" | |
printf "%s\\n" "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2 | |
if [ -n "$DISPLAY" ] && [ -n "$XMESSAGE" ]; then | |
printf "%s\\n" "$MESSAGE" | fold -s -w ${COLUMNS:-80} | $XMESSAGE -center -file - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# checks if string is valid email | |
function isemail(){ | |
emailTest=$(echo "${1}" | grep '^[a-zA-Z0-9._%+-]*@[a-zA-Z0-9]*[\.[a-zA-Z0-9]*]*[a-zA-Z0-9]$') | |
if [[ "$emailTest" != "" ] ; then return 0; else return 1; fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns 0 if parameter is a valid ip4 address, non-zero otherwise | |
function isvalidip4() | |
{ #return 0 if parameter is a valid ip4 address, non-zero otherwise | |
#https://groups.google.com/forum/#!original/comp.unix.shell/NDu-kAL5cHs/7Zpc6Q2Hu5YJ | |
[ -z "$1" ] && return 1 | |
case "$*" in | |
""|*[!0-9.]*|*[!0-9]) return 1 ;; | |
esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns 0 if parameter is a valid network interface, 1 otherwise | |
function isvalidinterface() | |
{ | |
[ -z "$1" ] && return 1 | |
ip addr show | grep "$1": >/dev/null && return 0 | |
return 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uploads images e too imgur.com, returns url on success, 1 otherwise | |
# @dependancy curl | |
function uploadimg() | |
{ | |
[ -z "$1" ] && return 1 | |
for img | |
do | |
if [ -f "$img" ] ; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replaces a string with another string | |
# @param string source string | |
# @param string search string | |
# @param string replacement string" | |
# usage: result="$(str_replace "foo bar" "foo" "hi")" | |
function str_replace() | |
{ | |
[ -z "$1" ] && return 1 | |
[ -z "$2" ] && return 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prints out the length of a string | |
# @param string input | |
function strlen() | |
{ | |
[ -z "$1" ] && return 1 | |
printf "%s\\n" "${#1}" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prints out the duplicate parts of 2 strings | |
# @param string input1 | |
# @param string input2 | |
function stroverlap() | |
{ | |
[ -z "$1" ] && return 1 | |
[ -z "$2" ] && return 1 | |
printf "%s\\n" $@ | awk 'x[$0]++' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prints out the differences of two strings | |
# @param string input1 | |
# @param string input2 | |
function strdiff() | |
{ | |
[ -z "$1" ] && return 1 | |
[ -z "$2" ] && return 1 | |
set -x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# converts a string to lower characters | |
# @param string input | |
function strtoupper() | |
{ | |
[ -z "$1" ] && return 1 | |
printf "%s\\n" "$@" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # tr '[:upper:]' '[:lower:]' | |
} |