Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Sep 7, 2023
1 parent cc60200 commit 85be4fb
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 8 deletions.
6 changes: 5 additions & 1 deletion commands/is-headless
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
function is_headless() (
source "$DOROTHY/sources/bash.bash"

! is-headful
if is-headful; then
return 1
else
return 0
fi
)

# fire if invoked standalone
Expand Down
7 changes: 5 additions & 2 deletions commands/is-interactive
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ function is_interactive() (
# =====================================
# Action

is-tty
! is-ci
if is-tty && ! is-ci; then
return 0
else
return 1
fi
)

# fire if invoked standalone
Expand Down
27 changes: 26 additions & 1 deletion commands/is-missing
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,32 @@
function is_missing() (
source "$DOROTHY/sources/bash.bash"

! is-present "$1"
# help
function help {
cat <<-EOF >/dev/stderr
ABOUT:
Check if a path is missing (not a file/directory/symlink).
Opposite of [is-present].
USAGE:
is-missing <input>
EOF
if test "$#" -ne 0; then
echo-error "$@"
fi
return 22 # EINVAL 22 Invalid argument
}

# process
if test "$#" -eq 0; then
help 'No <input> provided.'
elif test "$*" = '--help'; then
help
elif test -e "$1" -o -L "$1"; then # just -e is faulty, as -e fails on symlinks
return 1
else
return 0
fi
)

# fire if invoked standalone
Expand Down
6 changes: 5 additions & 1 deletion commands/is-nonempty-string
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
function is_nonempty_string() (
source "$DOROTHY/sources/bash.bash"

! is-empty-string "$1"
if is-empty-string "$1"; then
return 1
else
return 0
fi
)

# fire if invoked standalone
Expand Down
28 changes: 26 additions & 2 deletions commands/is-present
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,32 @@
function is_present() (
source "$DOROTHY/sources/bash.bash"

# just -e is faulty, as -e fails on symlinks
test -e "$1" -o -L "$1"
# help
function help {
cat <<-EOF >/dev/stderr
ABOUT:
Check if a path is present (is a file/directory/symlink).
Opposite of [is-missing].
USAGE:
is-present <input>
EOF
if test "$#" -ne 0; then
echo-error "$@"
fi
return 22 # EINVAL 22 Invalid argument
}

# process
if test "$#" -eq 0; then
help 'No <input> provided.'
elif test "$*" = '--help'; then
help
elif test -e "$1" -o -L "$1"; then # just -e is faulty, as -e fails on symlinks
return 0
else
return 1
fi
)

# fire if invoked standalone
Expand Down
6 changes: 5 additions & 1 deletion commands/is-value
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
function is_value() (
source "$DOROTHY/sources/bash.bash"

! is-empty-value "${1-}"
if is-empty-value "${1-}"; then
return 1
else
return 0
fi
)

# fire if invoked standalone
Expand Down
4 changes: 4 additions & 0 deletions docs/bash/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,7 @@ For more information on this, refer to:

- https://gist.github.com/balupton/21ded5cefc26dc20833e6ed606209e1b
- https://github.com/bevry/dorothy/blob/master/sources/bash.bash

### a final gotcha

https://github.com/koalaman/shellcheck/wiki/SC2251

0 comments on commit 85be4fb

Please sign in to comment.