nixos-config/home-manager/modules/fish/functions.nix

43 lines
1.3 KiB
Nix

{ git }: {
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}/bin/git diff --diff-filter=ACMR --name-only $argv[1])
set repo_path (realpath --relative-to=$PWD (${git}/bin/git rev-parse --show-toplevel))
set clangformat (${git}/bin/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";
};
}