Skip to content

Commit

Permalink
plugins/base: use _command_exists
Browse files Browse the repository at this point in the history
Addresses #1632
  • Loading branch information
gaelicWizard committed Sep 11, 2021
1 parent 454be11 commit 9998234
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions plugins/available/base.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ function ips ()
{
about 'display all ip addresses for this host'
group 'base'
if command -v ifconfig &>/dev/null
if _command_exists ifconfig
then
ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }'
elif command -v ip &>/dev/null
elif _command_exists ip
then
ip addr | grep -oP 'inet \K[\d.]+'
else
Expand Down Expand Up @@ -75,12 +75,12 @@ function passgen ()

# Create alias pass to passgen when pass isn't installed or
# BASH_IT_LEGACY_PASS is true.
if ! command -v pass &>/dev/null || [[ "${BASH_IT_LEGACY_PASS:-}" = "true" ]]
if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]
then
alias pass=passgen
fi

if type -t markdown >/dev/null && type -t browser >/dev/null
if _command_exists markdown && _command_exists browser
then pmdown ()
{
about 'preview markdown file in a browser'
Expand Down Expand Up @@ -151,17 +151,9 @@ then
}
fi

function command_exists ()
{
about 'checks for existence of a command'
param '1: command to check'
example '$ command_exists ls && echo exists'
group 'base'
type -t "$1" >/dev/null
}

if type -t mkisofs >/dev/null
then mkiso ()
if _command_exists mkisofs
then
function mkiso ()
{
about 'creates iso from current dir in the parent dir (unless defined)'
param '1: ISO name'
Expand Down Expand Up @@ -195,8 +187,9 @@ function buf ()
cp -a "${filename}" "${filename}_${filetime}"
}

if ! type -t del >/dev/null
then del() {
if ! _command_exists del
then
function del() {
about 'move files to hidden folder in tmp, that gets cleared on each reboot'
param 'file or folder to be deleted'
example 'del ./file.txt'
Expand Down

0 comments on commit 9998234

Please sign in to comment.