plugins/base: conditional function definitions

Instead of functions failing when required tools aren't installed, just don't define the function.
Alsö, don't redefine del() if it already exists.
pull/1930/head
John D Pell 2021-09-23 23:02:32 -07:00
parent 63869e0c37
commit 5cb7522713
1 changed files with 20 additions and 22 deletions

View File

@ -73,19 +73,16 @@ then
alias pass=passgen alias pass=passgen
fi fi
function pmdown () if _command_exists markdown && _command_exists browser; then
{ 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'
if _command_exists markdown
then markdown "${1?}" | browser
markdown $1 | browser
else
echo "You don't have a markdown command installed!"
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'
@ -141,7 +138,8 @@ function usage ()
fi fi
} }
if [[ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ]] && [[ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}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" ]]
then then
# if user has installed todo plugin, skip this... # if user has installed todo plugin, skip this...
function t () function t ()
@ -163,10 +161,11 @@ function command_exists ()
param '1: command to check' param '1: command to check'
example '$ command_exists ls && echo exists' example '$ command_exists ls && echo exists'
group 'base' group 'base'
type "$1" &> /dev/null ; type -t "$1" >/dev/null
} }
mkiso () if type -t mkisofs >/dev/null; then
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'
@ -176,21 +175,18 @@ mkiso ()
example 'mkiso ISO-Name dest/path src/path' example 'mkiso ISO-Name dest/path src/path'
group 'base' group 'base'
if type "mkisofs" > /dev/null; then [ -z ${1+x} ] && local isoname=${PWD##*/} || local isoname=$1
[[ -z ${1+x} ]] && local isoname=${PWD##*/} || local isoname=$1 [ -z ${2+x} ] && local destpath=../ || local destpath=$2
[[ -z ${2+x} ]] && local destpath=../ || local destpath=$2 [ -z ${3+x} ] && local srcpath=${PWD} || local srcpath=$3
[[ -z ${3+x} ]] && local srcpath=${PWD} || local srcpath=$3
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
echo "${destpath}${isoname}.iso already exists"
fi
else else
echo "mkisofs cmd does not exist, please install cdrtools" echo "${destpath}${isoname}.iso already exists"
fi fi
} }
fi
# useful for administrators and configs # useful for administrators and configs
function buf () function buf ()
@ -203,6 +199,7 @@ function buf ()
cp -a "${filename}" "${filename}_${filetime}" cp -a "${filename}" "${filename}_${filetime}"
} }
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'
@ -210,3 +207,4 @@ function del() {
group 'base' group 'base'
mkdir -p /tmp/.trash && mv "$@" /tmp/.trash; mkdir -p /tmp/.trash && mv "$@" /tmp/.trash;
} }
fi