From 16896efa02430f142070e454d905c0943ff9cad7 Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Mon, 21 Sep 2020 22:51:03 +0200 Subject: [PATCH] Replace cformat() with a clang-format wrapper Replace the function with extra functionality with a wrapper for clang-format that looks for the style flag and substitutes a given filename with its parsed content. --- .config/zsh/plugins/functionsPost.zsh | 46 ++++++++++++++++++--------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/.config/zsh/plugins/functionsPost.zsh b/.config/zsh/plugins/functionsPost.zsh index 48d19c9..5c3a956 100644 --- a/.config/zsh/plugins/functionsPost.zsh +++ b/.config/zsh/plugins/functionsPost.zsh @@ -308,23 +308,39 @@ function histgrep() { grep "$@" "${HISTFILE:-$HOME/.zsh_history}" } -function cformat() { - # TODO: respect manual changes made in meld - CLANG_FORMAT_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/clang/config" - FORMAT="$( - sed -E '/^\s*($|#)/d' "$CLANG_FORMAT_FILE" \ - | tr '\n' ',' \ - | sed 's/,$//' - )" - FORMAT="{${FORMAT}}" - if [ $# -eq 1 ]; then - meld <(clang-format -style="$FORMAT" $1) $1 +function clang-format() { + local idx=${@[(I)-style*]} + if (( ! idx )); then + # No style flag given + command clang-format "$@" + return fi - echo -n "Are you happy? [yn] " - read yn - if [ $yn = "y" ]; then - clang-format -i -style="$FORMAT" $1 + + local style="${@[$idx]#-style}" prefix="" + if [ -n "$style" ]; then + # Flag was given in form -style=