From d4e82cf9cdbab7e85be905a18920c5e5cf3a2434 Mon Sep 17 00:00:00 2001 From: Lara Date: Mon, 27 Jul 2020 13:56:38 -0400 Subject: [PATCH] [zsh] Improve BSD compatibility --- aliases | 4 +++- functions | 23 +++++++++++++---------- zshrc | 9 ++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/aliases b/aliases index 3560e1a..cb60d06 100644 --- a/aliases +++ b/aliases @@ -5,7 +5,7 @@ # Detect if we have GNU coreutils or BSD if date --version > /dev/null 2>&1 ;then alias ls='ls --classify --tabsize=0 --literal --color=auto --show-control-chars -h' - alias diff='diff -u --color' + alias diff='diff --color' alias less='less --quiet' alias grep="grep --color" alias rm='rm -I' @@ -13,6 +13,7 @@ if date --version > /dev/null 2>&1 ;then alias ipa='ip route && echo && ip --brief address' alias ipr='ip --brief address && echo && ip route' else + alias ls='ls -FGh' alias ipa='ip address' alias ipa='ip route' fi @@ -35,6 +36,7 @@ case $(uname -s) in esac alias ll='ls -lha' alias df='df -h' +alias diff='diff -u' alias du='du -h' alias feh="feh -. --auto-rotate --action1 'dragon -x %F'" alias which='which -a' diff --git a/functions b/functions index f3eed29..e1189eb 100755 --- a/functions +++ b/functions @@ -2,16 +2,19 @@ # Debugging # ############# -# Global counter that can be used to diagnose duplicated calls -printf "0" > /dev/shm/debug_counter -debug_counter_inc() { - count="$(cat /dev/shm/debug_counter)" - ((count++)) - printf "%d" "$count" > /dev/shm/debug_counter -} -debug_counter_print(){ - printf "%d" "$(cat /dev/shm/debug_counter)" -} +# Detect if we have GNU coreutils or BSD +if date --version > /dev/null 2>&1 ;then + # Global counter that can be used to diagnose duplicated calls + printf "0" > /dev/shm/debug_counter + debug_counter_inc() { + count="$(cat /dev/shm/debug_counter)" + ((count++)) + printf "%d" "$count" > /dev/shm/debug_counter + } + debug_counter_print(){ + printf "%d" "$(cat /dev/shm/debug_counter)" + } +fi ################### # Update checking # diff --git a/zshrc b/zshrc index c63e0b6..ab94575 100644 --- a/zshrc +++ b/zshrc @@ -56,9 +56,12 @@ colors . "$RC_PATH/functions" . "$RC_PATH/aliases" . "$RC_PATH/prompt" -# Setup colors for GNU ls -# TODO: check for GNU ls -eval "$(dircolors -b)" + +# Detect if we have GNU coreutils or BSD +if date --version > /dev/null 2>&1 ;then + # Setup colors for GNU ls + eval "$(dircolors -b)" +fi # Check for rc updates in the background (check_rc_update&) 2> /dev/null