From c93d36677bf2d8c195949ff8b35b49ab4862033b Mon Sep 17 00:00:00 2001 From: druckdev Date: Fri, 30 Apr 2021 11:48:09 +0200 Subject: [PATCH] zsh:glog: Handle missing commands and OS X As the commit hash is now potentially printed (when no clipboard tool is available), the copy-command needed to be executed not silent. --- .config/zsh/autoload/glog | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) 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 '' <