94 lines
2.0 KiB
Bash
94 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
|
|
if [[ ! $(command -v arch) ]]; then
|
|
function arch() {
|
|
uname -m
|
|
}
|
|
fi
|
|
|
|
function function_list {
|
|
if [ $1 ]; then
|
|
# will list functions in passed file
|
|
local STR
|
|
local func
|
|
declare -a FUNCS
|
|
STR=$(grep '() {\|(){\|function' $1)
|
|
readarray -t LIST <<<"$STR"
|
|
for func in "${LIST[@]}"
|
|
do
|
|
if [[ ! $func =~ ^# ]]; then
|
|
func=${func#function }
|
|
func=${func%()?( ){}
|
|
[[ ! $func =~ ^_ ]] && FUNCS+=($func)
|
|
fi
|
|
done
|
|
echo "${FUNCS[@]}"
|
|
else
|
|
# will list all sourced/declared functions available
|
|
echo
|
|
echo -e "\033[1;4;32m""Functions:""\033[0;34m"
|
|
declare -F | grep -v "declare -f\s_" | awk {'print $3'}
|
|
echo
|
|
echo -e "\033[0m"
|
|
fi
|
|
}
|
|
|
|
function alias_list() {
|
|
echo
|
|
echo -e "\033[1;4;32m""Aliases:""\033[0;34m"
|
|
alias | awk {'print $2'} | awk -F= {'print $1'}
|
|
echo
|
|
echo -e "\033[0m"
|
|
}
|
|
|
|
get_shopt () {
|
|
echo $([ "$(shopt -p $1 | grep '\-s')" ] && echo on || echo off)
|
|
}
|
|
|
|
# edit files
|
|
# echo set the system editor using EDITOR environment variable
|
|
edit() { ${EDITOR:-nano} $@; }
|
|
gedit() { ${GEDITOR:-xed} $@; }
|
|
|
|
|
|
unlocku () ( faillock --user $1 --reset )
|
|
|
|
rsynchg() { rsync --help | grep "\-$1"; }
|
|
|
|
|
|
gip () {
|
|
if which jq &> /dev/null; then
|
|
curl -s "https://dns.google/resolve?name=$1" | jq -r '.Answer[] | .data' | tail -n 1
|
|
return 0
|
|
else
|
|
echo install jq to use this function
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
gpip () {
|
|
curl https://ipv4.nsupdate.info/myip
|
|
}
|
|
|
|
|
|
valid_ipv4() {
|
|
local ip="$1"
|
|
[[ "$ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]] || return 1
|
|
for i in ${ip//./ }; do
|
|
[[ "${#i}" -gt 1 && "${i:0:1}" == 0 ]] && return 1
|
|
[[ "$i" -gt 255 ]] && return 1
|
|
done
|
|
return 0
|
|
}
|
|
|
|
dip () {
|
|
local ip4
|
|
ip4=$(/bin/drill $1 | grep -A1 'ANSWER SECTION' | grep -v "ANSWER SECTION" | rev | cut -f1 | rev)
|
|
# echo first: $ip4
|
|
if valid_ipv4 $ip4; then
|
|
echo $ip4
|
|
else
|
|
/bin/drill $ip4 | grep -A1 'ANSWER SECTION' | grep -v "ANSWER SECTION" | rev | cut -f1 | rev
|
|
fi
|
|
} |