plugin/base: `shfmt`

Apply `shfmt` using current project settings. My apologies to future `git blame` hunters. ♥
pull/1930/head
John D Pell 2021-09-23 23:08:26 -07:00
parent 45bf7194a2
commit e66019daf1
2 changed files with 110 additions and 113 deletions

View File

@ -78,6 +78,7 @@ completion/available/wpscan.completion.bash
# #
plugins/available/alias-completion.plugin.bash plugins/available/alias-completion.plugin.bash
plugins/available/autojump.plugin.bash plugins/available/autojump.plugin.bash
plugins/available/base.plugin.bash
plugins/available/basher.plugin.bash plugins/available/basher.plugin.bash
plugins/available/cmd-returned-notify.plugin.bash plugins/available/cmd-returned-notify.plugin.bash
plugins/available/direnv.plugin.bash plugins/available/direnv.plugin.bash

View File

@ -3,116 +3,113 @@ cite about-plugin
about-plugin 'miscellaneous tools' about-plugin 'miscellaneous tools'
function ips() { function ips() {
about 'display all ip addresses for this host' about 'display all ip addresses for this host'
group 'base' group 'base'
if _command_exists ifconfig if _command_exists ifconfig; then
then ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }'
ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }' elif _command_exists ip; then
elif _command_exists ip ip addr | grep -oP 'inet \K[\d.]+'
then else
ip addr | grep -oP 'inet \K[\d.]+' echo "You don't have ifconfig or ip command installed!"
else fi
echo "You don't have ifconfig or ip command installed!"
fi
} }
function down4me() { function down4me() {
about 'checks whether a website is down for you, or everybody' about 'checks whether a website is down for you, or everybody'
param '1: website url' param '1: website url'
example '$ down4me http://www.google.com' example '$ down4me http://www.google.com'
group 'base' group 'base'
curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
} }
function myip() { function myip() {
about 'displays your ip address, as seen by the Internet' about 'displays your ip address, as seen by the Internet'
group 'base' group 'base'
list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/") list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/")
for url in "${list[@]}"; do for url in "${list[@]}"; do
if res="$(curl -fs "${url}")"; then if res="$(curl -fs "${url}")"; then
break; break
fi fi
done done
res="$(echo "$res" | grep -Eo '[0-9\.]+')" res="$(echo "$res" | grep -Eo '[0-9\.]+')"
echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}" echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}"
} }
function pickfrom() { function pickfrom() {
about 'picks random line from file' about 'picks random line from file'
param '1: filename' param '1: filename'
example '$ pickfrom /usr/share/dict/words' example '$ pickfrom /usr/share/dict/words'
group 'base' group 'base'
local file=${1:-} local file=${1:-}
local -i n=0 length local -i n=0 length
if [[ ! -r "$file" ]]; then if [[ ! -r "$file" ]]; then
reference "${FUNCNAME[0]}" && return reference "${FUNCNAME[0]}" && return
fi fi
length="$(wc -l < "$file")" length="$(wc -l < "$file")"
n=$(( RANDOM * length / 32768 + 1 )) n=$((RANDOM * length / 32768 + 1))
head -n "$n" "$file" | tail -1 head -n "$n" "$file" | tail -1
} }
function passgen() { function passgen() {
about 'generates random password from dictionary words' about 'generates random password from dictionary words'
param 'optional integer length' param 'optional integer length'
param 'if unset, defaults to 4' param 'if unset, defaults to 4'
example '$ passgen' example '$ passgen'
example '$ passgen 6' example '$ passgen 6'
group 'base' group 'base'
local -i i length=${1:-4} local -i i length=${1:-4}
local pass local pass
# shellcheck disable=SC2034 # shellcheck disable=SC2034
pass="$(for i in $(eval "echo {1..$length}"); do pickfrom /usr/share/dict/words; done)" pass="$(for i in $(eval "echo {1..$length}"); do pickfrom /usr/share/dict/words; done)"
echo "With spaces (easier to memorize): ${pass//$'\n'/ }" echo "With spaces (easier to memorize): ${pass//$'\n'/ }"
echo "Without spaces (easier to brute force): ${pass//$'\n'/}" echo "Without spaces (easier to brute force): ${pass//$'\n'/}"
} }
# Create alias pass to passgen when pass isn't installed or # Create alias pass to passgen when pass isn't installed or
# BASH_IT_LEGACY_PASS is true. # BASH_IT_LEGACY_PASS is true.
if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]] if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]; then
then alias pass=passgen
alias pass=passgen
fi fi
if _command_exists markdown && _command_exists browser; then if _command_exists markdown && _command_exists browser; then
function pmdown() { function pmdown() {
about 'preview markdown file in a browser' about 'preview markdown file in a browser'
param '1: markdown file' param '1: markdown file'
example '$ pmdown README.md' example '$ pmdown README.md'
group 'base' group 'base'
markdown "${1?}" | browser markdown "${1?}" | browser
} }
fi fi
function mkcd() { function mkcd() {
about 'make one or more directories and cd into the last one' about 'make one or more directories and cd into the last one'
param 'one or more directories to create' param 'one or more directories to create'
example '$ mkcd foo' example '$ mkcd foo'
example '$ mkcd /tmp/img/photos/large' example '$ mkcd /tmp/img/photos/large'
example '$ mkcd foo foo1 foo2 fooN' example '$ mkcd foo foo1 foo2 fooN'
example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing' example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing'
group 'base' group 'base'
mkdir -p -- "$@" && cd -- "${!#}" || return mkdir -p -- "$@" && cd -- "${!#}" || return
} }
# shellcheck disable=SC2010 # shellcheck disable=SC2010
function lsgrep() { function lsgrep() {
about 'search through directory contents with grep' about 'search through directory contents with grep'
group 'base' group 'base'
ls | grep "$@" ls | grep "$@"
} }
function quiet() { function quiet() {
about 'what *does* this do?' about 'what *does* this do?'
group 'base' group 'base'
nohup "$@" &> /dev/null </dev/null & nohup "$@" &> /dev/null < /dev/null &
} }
function usage() { function usage() {
about 'disk usage per directory, in Mac OS X and Linux' about 'disk usage per directory, in Mac OS X and Linux'
param '1: directory name' param '1: directory name'
group 'base' group 'base'
case $OSTYPE in case $OSTYPE in
*'darwin'*) *'darwin'*)
du -hd 1 "$@" du -hd 1 "$@"
@ -124,61 +121,60 @@ function usage() {
} }
# shellcheck disable=SC2144 # the glob matches only one file # shellcheck disable=SC2144 # the glob matches only one file
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" \ if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
&& ! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]] ! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
then # if user has installed todo plugin, skip this...
# if user has installed todo plugin, skip this... function t() {
function t() { about 'one thing todo'
about 'one thing todo' param 'if not set, display todo item'
param 'if not set, display todo item' param '1: todo text'
param '1: todo text' if [[ "$*" == "" ]]; then
if [[ "$*" == "" ]] ; then cat ~/.t
cat ~/.t else
else echo "$*" > ~/.t
echo "$*" > ~/.t fi
fi }
}
fi fi
if _command_exists mkisofs; then if _command_exists mkisofs; then
function mkiso() { function mkiso() {
about 'creates iso from current dir in the parent dir (unless defined)' about 'creates iso from current dir in the parent dir (unless defined)'
param '1: ISO name' param '1: ISO name'
param '2: dest/path' param '2: dest/path'
param '3: src/path' param '3: src/path'
example 'mkiso' example 'mkiso'
example 'mkiso ISO-Name dest/path src/path' example 'mkiso ISO-Name dest/path src/path'
group 'base' group 'base'
local isoname="${1:-${PWD##*/}}" local isoname="${1:-${PWD##*/}}"
local destpath="${2:-../}" local destpath="${2:-../}"
local srcpath="${3:-${PWD}}" local srcpath="${3:-${PWD}}"
if [[ ! -f "${destpath%/}/${isoname}.iso" ]]; then if [[ ! -f "${destpath%/}/${isoname}.iso" ]]; then
echo "writing ${isoname}.iso to ${destpath} from ${srcpath}" echo "writing ${isoname}.iso to ${destpath} from ${srcpath}"
mkisofs -V "${isoname}" -iso-level 3 -r -o "${destpath%/}/${isoname}.iso" "${srcpath}" mkisofs -V "${isoname}" -iso-level 3 -r -o "${destpath%/}/${isoname}.iso" "${srcpath}"
else else
echo "${destpath%/}/${isoname}.iso already exists" echo "${destpath%/}/${isoname}.iso already exists"
fi fi
} }
fi fi
# useful for administrators and configs # useful for administrators and configs
function buf() { function buf() {
about 'back up file with timestamp' about 'back up file with timestamp'
param 'filename' param 'filename'
group 'base' group 'base'
local filename="${1?}" filetime local filename="${1?}" filetime
filetime=$(date +%Y%m%d_%H%M%S) filetime=$(date +%Y%m%d_%H%M%S)
cp -a "${filename}" "${filename}_${filetime}" cp -a "${filename}" "${filename}_${filetime}"
} }
if ! _command_exists del; then if ! _command_exists del; then
function del() { function del() {
about 'move files to hidden folder in tmp, that gets cleared on each reboot' about 'move files to hidden folder in tmp, that gets cleared on each reboot'
param 'file or folder to be deleted' param 'file or folder to be deleted'
example 'del ./file.txt' example 'del ./file.txt'
group 'base' group 'base'
mkdir -p /tmp/.trash && mv "$@" /tmp/.trash; mkdir -p /tmp/.trash && mv "$@" /tmp/.trash
} }
fi fi