Skip to content

Commit

Permalink
POSIX-compliant conditions for better portability
Browse files Browse the repository at this point in the history
  • Loading branch information
mfhepp committed Jan 28, 2024
1 parent 811d6b4 commit faa2547
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ _validate_basename() {
local sanitized
# Remove leading and trailing whitespace and replace forbidden characters
sanitized=$(echo "$input" | xargs | sed 's/[^a-zA-Z0-9_-]/_/g')
if [[ "$sanitized" != "$input" ]]; then
if [ "$sanitized" != "$input" ]; then
# echo "ERROR: Argument contains invalid characters (consider $sanitized instead)"
return 1
fi
}


_cdf_list() {
# List all available shortcuts
printf "Usage: cdf NAME\n\n"
Expand Down Expand Up @@ -81,7 +82,8 @@ addfav() {
else
# Check that the current directory is neither the place for the symlinks nor a subdirectory therof
CURRENT_DIR=$(pwd)
if [[ "$CURRENT_DIR" = "$CDFPATH" || "$CURRENT_DIR" == "$CDFPATH"/* ]]; then
# Bash-only version: if [[ "$CURRENT_DIR" = "$CDFPATH" || "$CURRENT_DIR" == "$CDFPATH"/* ]]; then
if [ "$CURRENT_DIR" = "$CDFPATH" ] || [ "${CURRENT_DIR##$CDFPATH/}" != "$CURRENT_DIR" ]; then
printf "ERROR: You cannot create shortcuts to the shortcuts folder or its subdirectories\n"
return 1
# Check if we are INSIDE a symbolic link
Expand Down

0 comments on commit faa2547

Please sign in to comment.