From fd28bccdac32c670b7a94469d5fbd7b84caea853 Mon Sep 17 00:00:00 2001 From: typebrook Date: Wed, 6 May 2020 10:50:04 +0800 Subject: Fix Mac Compatibility Looks like alias fails in bash script, even after adding: shopt -s expand_aliases --- gist | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gist b/gist index 2c0e817..c2769eb 100755 --- a/gist +++ b/gist @@ -73,9 +73,24 @@ protocol=https # Shell configuration set -o pipefail [[ $TRACE == 'true' ]] && set -x -[[ $(uname) == 'Darwin' ]] && alias tac='tail -r' trap 'rm -f "$http_data" "$tmp_file"' EXIT +# Mac compatibility +tac() { + if [[ $(uname) == Darwin ]]; then + tail -r + else + $(which tac) + fi +} +mtime() { + if [[ $(uname) == Darwin ]]; then + stat -x $1 | grep Modify | cut -d' ' -f2- + else + stat -c %y $1 + fi +} + # This function determines which http get tool the system has installed and returns an error if there isnt one getConfiguredClient() { if command -v curl &>/dev/null; then @@ -331,7 +346,7 @@ _show_list() { echo > /dev/tty echo Pinned tags: "${pinned_tags[*]/#/#} " > /dev/tty elif [[ -z $INPUT && $hint != 'false' ]]; then - local mtime="$(stat -c %y $INDEX | cut -d'.' -f1)" + local mtime="$(mtime $INDEX | cut -d'.' -f1)" echo > /dev/tty echo "Last updated at $mtime" > /dev/tty echo 'Run "gist fetch" to keep gists up to date, or "gist help" for more details' > /dev/tty -- cgit v1.2.3-70-g09d2