diff options
| author | typebrook <typebrook@gmail.com> | 2020-05-06 10:50:04 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-05-06 10:58:22 +0800 |
| commit | fd28bccdac32c670b7a94469d5fbd7b84caea853 (patch) | |
| tree | 8ca3fa038c97536b5829d4319dc8e9a4178343ff | |
| parent | 0f64e108ba5dc7dff075b67dcab2b10390608a92 (diff) | |
Fix Mac Compatibility
Looks like alias fails in bash script, even after adding:
shopt -s expand_aliases
| -rwxr-xr-x | gist | 19 |
1 files changed, 17 insertions, 2 deletions
| @@ -73,9 +73,24 @@ protocol=https | |||
| 73 | # Shell configuration | 73 | # Shell configuration |
| 74 | set -o pipefail | 74 | set -o pipefail |
| 75 | [[ $TRACE == 'true' ]] && set -x | 75 | [[ $TRACE == 'true' ]] && set -x |
| 76 | [[ $(uname) == 'Darwin' ]] && alias tac='tail -r' | ||
| 77 | trap 'rm -f "$http_data" "$tmp_file"' EXIT | 76 | trap 'rm -f "$http_data" "$tmp_file"' EXIT |
| 78 | 77 | ||
| 78 | # Mac compatibility | ||
| 79 | tac() { | ||
| 80 | if [[ $(uname) == Darwin ]]; then | ||
| 81 | tail -r | ||
| 82 | else | ||
| 83 | $(which tac) | ||
| 84 | fi | ||
| 85 | } | ||
| 86 | mtime() { | ||
| 87 | if [[ $(uname) == Darwin ]]; then | ||
| 88 | stat -x $1 | grep Modify | cut -d' ' -f2- | ||
| 89 | else | ||
| 90 | stat -c %y $1 | ||
| 91 | fi | ||
| 92 | } | ||
| 93 | |||
| 79 | # This function determines which http get tool the system has installed and returns an error if there isnt one | 94 | # This function determines which http get tool the system has installed and returns an error if there isnt one |
| 80 | getConfiguredClient() { | 95 | getConfiguredClient() { |
| 81 | if command -v curl &>/dev/null; then | 96 | if command -v curl &>/dev/null; then |
| @@ -331,7 +346,7 @@ _show_list() { | |||
| 331 | echo > /dev/tty | 346 | echo > /dev/tty |
| 332 | echo Pinned tags: "${pinned_tags[*]/#/#} " > /dev/tty | 347 | echo Pinned tags: "${pinned_tags[*]/#/#} " > /dev/tty |
| 333 | elif [[ -z $INPUT && $hint != 'false' ]]; then | 348 | elif [[ -z $INPUT && $hint != 'false' ]]; then |
| 334 | local mtime="$(stat -c %y $INDEX | cut -d'.' -f1)" | 349 | local mtime="$(mtime $INDEX | cut -d'.' -f1)" |
| 335 | echo > /dev/tty | 350 | echo > /dev/tty |
| 336 | echo "Last updated at $mtime" > /dev/tty | 351 | echo "Last updated at $mtime" > /dev/tty |
| 337 | echo 'Run "gist fetch" to keep gists up to date, or "gist help" for more details' > /dev/tty | 352 | echo 'Run "gist fetch" to keep gists up to date, or "gist help" for more details' > /dev/tty |