Skip to content

Commit

Permalink
fix new shellcheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Aug 13, 2023
1 parent f66bc32 commit 1b8671f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions stdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ expand_path() {
}

# --- vendored from https://github.com/bashup/realpaths
realpath.dirname() { REPLY=.; ! [[ $1 =~ /+[^/]+/*$|^//$ ]] || REPLY="${1%${BASH_REMATCH[0]}}"; REPLY=${REPLY:-/}; }
realpath.dirname() { REPLY=.; ! [[ $1 =~ /+[^/]+/*$|^//$ ]] || REPLY="${1%"${BASH_REMATCH[0]}"}"; REPLY=${REPLY:-/}; }
realpath.basename(){ REPLY=/; ! [[ $1 =~ /*([^/]+)/*$ ]] || REPLY="${BASH_REMATCH[1]}"; }

realpath.absolute() {
REPLY=$PWD; local eg=extglob; ! shopt -q $eg || eg=; ${eg:+shopt -s $eg}
while (($#)); do case $1 in
//|//[^/]*) REPLY=//; set -- "${1:2}" "${@:2}" ;;
/*) REPLY=/; set -- "${1##+(/)}" "${@:2}" ;;
*/*) set -- "${1%%/*}" "${1##${1%%/*}+(/)}" "${@:2}" ;;
*/*) set -- "${1%%/*}" "${1##"${1%%/*}"+(/)}" "${@:2}" ;;
''|.) shift ;;
..) realpath.dirname "$REPLY"; shift ;;
*) REPLY="${REPLY%/}/$1"; shift ;;
Expand Down Expand Up @@ -279,7 +279,7 @@ user_rel_path() {
if [[ -z $abs_path ]]; then return; fi

if [[ -n $HOME ]]; then
local rel_path=${abs_path#$HOME}
local rel_path=${abs_path#"$HOME"}
if [[ $rel_path != "$abs_path" ]]; then
abs_path=~$rel_path
fi
Expand Down Expand Up @@ -736,7 +736,7 @@ semver_search() {
# Sort by version: split by "." then reverse numeric sort for each piece of the version string
# The first one is the highest
find "$version_dir" -maxdepth 1 -mindepth 1 -type d -name "${prefix}${partial_version}*" \
| while IFS= read -r line; do echo "${line#${version_dir%/}/${prefix}}"; done \
| while IFS= read -r line; do echo "${line#"${version_dir%/}"/"${prefix}"}"; done \
| sort -t . -k 1,1rn -k 2,2rn -k 3,3rn \
| head -1
}
Expand All @@ -746,9 +746,9 @@ semver_search() {
# A semantic dispatch used to describe common project layouts.
#
layout() {
local name=$1
local funcname="layout_$1"
shift
eval "layout_$name" "$@"
"$funcname" "$@"
}

# Usage: layout go
Expand Down Expand Up @@ -913,7 +913,7 @@ layout_anaconda() {
# If only config, it needs a name field
if [[ -n "$env_config" ]]; then
if [[ -e "$env_config" ]]; then
env_name="$(grep -- '^name:' $env_config)"
env_name="$(grep -- '^name:' "$env_config")"
env_name="${env_name/#name:*([[:space:]])}"
if [[ -z "$env_name" ]]; then
log_error "Unable to find 'name' in '$env_config'"
Expand Down Expand Up @@ -1362,6 +1362,7 @@ __main__() {
exec 3>&1
exec 1>&2

# shellcheck disable=SC2317
__dump_at_exit() {
local ret=$?
"$direnv" dump json "" >&3
Expand Down
1 change: 1 addition & 0 deletions test/stdlib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ test_name source_up
test_name direnv_apply_dump
(
tmpfile=$(mktemp)
# shellcheck disable=SC2317
cleanup() { rm "$tmpfile"; }
trap cleanup EXIT

Expand Down

0 comments on commit 1b8671f

Please sign in to comment.