diff --git a/.config/zsh/autoload/glog b/.config/zsh/autoload/glog index 89d0cf6..7fe2404 100755 --- a/.config/zsh/autoload/glog +++ b/.config/zsh/autoload/glog @@ -7,6 +7,12 @@ # extendedglob is necessary for the expansion of the binds array emulate -L zsh -o extendedglob +# Return if fzf is not available +if ! command -v fzf &>/dev/null; then + printf "command not found: fzf" >&2 + return 1 +fi + # Return if not in git repo git rev-parse || return @@ -40,18 +46,29 @@ local dateshort='--date=format:%F' # year local date="$dateshort %T %z" # year time timezone # Put the commit hash into the clipboard -local fzf_copy_command="echo -nE {} | sed -E '$commit_hash' | xclip -sel c" +# (If no known clipboard tool is available, just print it) +local fzf_copy_command="echo -nE {} | sed -E '$commit_hash'" +if [[ $OSTYPE =~ darwin ]] && command -v pbcopy &>/dev/null; then + fzf_copy_command+=" | pbcopy" +elif command -v xclip &>/dev/null; then + fzf_copy_command+=" | xclip -selection c" +fi local -A fzf_preview read -r -d '' </dev/null; then + fzf_preview[patch]+=" | diff-so-fancy --color=always" +fi +fzf_preview[patch]+=" }" + read -r -d '' <