From e6643c0d1dce91f7f11b8e5fd0d590b07b0fbe8f Mon Sep 17 00:00:00 2001 From: Erwin Boskma Date: Tue, 1 Mar 2022 08:11:26 +0100 Subject: [PATCH] Split fish functions off into separate file, add `clangfmt` function --- home-manager/modules/fish/default.nix | 20 +----------- home-manager/modules/fish/functions.nix | 43 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 home-manager/modules/fish/functions.nix diff --git a/home-manager/modules/fish/default.nix b/home-manager/modules/fish/default.nix index 9586e81..df80322 100644 --- a/home-manager/modules/fish/default.nix +++ b/home-manager/modules/fish/default.nix @@ -11,25 +11,7 @@ in config = mkIf (cfg.enable) { programs.fish = { enable = true; - functions = { - reload = { - body = '' - history --save - set -gx dirprev $dirprev - set -gx dirnext $dirnext - set -gx dirstack $dirstack - set -g fish_greeting "" - exec fish - ''; - description = "Reload Fish while keeping some context"; - }; - update-env = { - body = '' - set -gx SWAYSOCK /run/user/(id -u)/sway-ipc.(id -u).(pgrep -x sway).sock - ''; - description = "Update environment variables"; - }; - }; + functions = (import ./functions.nix); plugins = [ { diff --git a/home-manager/modules/fish/functions.nix b/home-manager/modules/fish/functions.nix new file mode 100644 index 0000000..b40dc27 --- /dev/null +++ b/home-manager/modules/fish/functions.nix @@ -0,0 +1,43 @@ +{ + reload = { + body = '' + history --save + set -gx dirprev $dirprev + set -gx dirnext $dirnext + set -gx dirstack $dirstack + set -g fish_greeting "" + exec fish + ''; + description = "Reload Fish while keeping some context"; + }; + update-env = { + body = '' + set -gx SWAYSOCK /run/user/(id -u)/sway-ipc.(id -u).(pgrep -x sway).sock + ''; + description = "Update environment variables"; + }; + clangfmt = { + body = '' + set source_exts "h" "hpp" "c" "cpp" "cc" "cp" "c++" "cxx" "cu" "proto" + set files (git diff --diff-filter=ACMR --name-only $argv[1]) + set repo_path (realpath --relative-to=$PWD (git rev-parse --show-toplevel)) + set clangformat (git config --get clangFormat.binary) + echo "Formatting files in $repo_path with $clangformat" + + for f in $files + set file (realpath $repo_path/$f) + echo "Processing $file" + + set ext (string match -r ".*\.([^\.]+)\$" $file)[2] + + if contains $ext $source_exts + echo "Formatting $file" + $clangformat -i -style=file $file + else + echo "Extension $ext not found in $source_exts" + end + end + ''; + description = "Use clang-format to format all changed and added files"; + }; +}