Skip to content

Commit

Permalink
! fix osx ci fail
Browse files Browse the repository at this point in the history
- prefer greadlink than readlink
- prefer gsed than sed
  • Loading branch information
oldratlee committed Feb 19, 2021
1 parent 3723073 commit 71e763e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ language: bash
# https://docs.travis-ci.com/user/reference/linux/
# The macOS Build Environment
# https://docs.travis-ci.com/user/reference/osx/
# Installing Dependencies
# https://docs.travis-ci.com/user/installing-dependencies/#installing-packages-on-macos
matrix:
include:
- os: linux
Expand All @@ -19,6 +21,10 @@ matrix:
- os: linux
dist: focal
- os: osx
osx_image: xcode11.3
install:
- HOMEBREW_NO_AUTO_UPDATE=1 brew install coreutils
- HOMEBREW_NO_AUTO_UPDATE=1 brew install gnu-sed

script:
- test-cases/integration-test.sh
Expand Down
7 changes: 6 additions & 1 deletion bin/ap
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

READLINK_CMD=readlink
if command -v greadlink > /dev/null; then
READLINK_CMD=greadlink
fi

[ $# -eq 0 ] && files=(.) || files=("$@")

for f in "${files[@]}"; do
! [ -e "$f" ] && {
echo "$f does not exists!"
continue
}
readlink -f "$f"
$READLINK_CMD -f "$f"
done
7 changes: 6 additions & 1 deletion bin/uq
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

READLINK_CMD=readlink
if command -v greadlink > /dev/null; then
READLINK_CMD=greadlink
fi

PROG="$(basename "$0")"
PROG_PATH="$(readlink -f "${BASH_SOURCE[0]}")"
PROG_PATH="$($READLINK_CMD -f "${BASH_SOURCE[0]}")"
PROG_DIR="$(dirname "$PROG_PATH")"

################################################################################
Expand Down
7 changes: 6 additions & 1 deletion lib/console-text-color-themes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-console-text-color-themessh
# @author Jerry Lee (oldratlee at gmail dot com)

readonly _ctct_PROG="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
_ctct_READLINK_CMD=readlink
if command -v greadlink > /dev/null; then
_ctct_READLINK_CMD=greadlink
fi

readonly _ctct_PROG="$(basename "$($_ctct_READLINK_CMD -f "${BASH_SOURCE[0]}")")"
[ "$_ctct_PROG" == 'console-text-color-themes.sh' ] && readonly _ctct_is_direct_run=true

readonly _ctct_ec=$'\033' # escape char
Expand Down
11 changes: 8 additions & 3 deletions lib/parseOpts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
readonly _opts_ec=$'\033' # escape char
readonly _opts_eend=$'\033[0m' # escape end

_opts_SED_CMD=sed
if command -v gsed &> /dev/null; then
_opts_SED_CMD=gsed
fi

_opts_colorEcho() {
local color=$1
shift
Expand All @@ -42,7 +47,7 @@ _opts_convertToVarName() {
_opts_redEcho "NOT 1 arguemnts when call _opts_convertToVarName: $@"
return 1
}
echo "$1" | sed 's/-/_/g'
echo "$1" | $_opts_SED_CMD 's/-/_/g'
}

#####################################################################
Expand Down Expand Up @@ -177,7 +182,7 @@ parseOpts() {

local optDescLines=`echo "$optsDescription" |
# cut head and tail space
sed -r 's/^\s+//;s/\s+$//' |
$_opts_SED_CMD -r 's/^\s+//;s/\s+$//' |
awk -F '[\t ]*\\\\|[\t ]*' '{for(i=1; i<=NF; i++) print $i}'`

local optDesc
Expand Down Expand Up @@ -258,7 +263,7 @@ parseOpts() {
;;
-*) # short & long option(-a, -a-long), use same read-in logic.
local opt="$1"
local optName=`echo "$1" | sed -r 's/^--?//'`
local optName=`echo "$1" | $_opts_SED_CMD -r 's/^--?//'`
local mode=`_opts_findOptMode "$optName"`
case "$mode" in
-)
Expand Down
8 changes: 7 additions & 1 deletion test-cases/integration-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/bash
set -eEuo pipefail
cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"

READLINK_CMD=readlink
if command -v greadlink &> /dev/null; then
READLINK_CMD=greadlink
fi

cd "$(dirname "$($READLINK_CMD -f "${BASH_SOURCE[0]}")")"

################################################################################
# constants
Expand Down
7 changes: 6 additions & 1 deletion test-cases/uq_test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash
set -eEuo pipefail

BASE="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
READLINK_CMD=readlink
if command -v greadlink &> /dev/null; then
READLINK_CMD=greadlink
fi

BASE="$(dirname "$($READLINK_CMD -f "${BASH_SOURCE[0]}")")"
cd "$BASE"

#################################################
Expand Down

0 comments on commit 71e763e

Please sign in to comment.