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

67 lines
1.8 KiB
Nix
Raw Normal View History

{ 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"
2022-03-01 22:19:03 +01:00
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";
};
linklib = {
body = ''
function linklib --argument lib
set libcomponents (string split "." "$lib")
set libname $libcomponents[1].$libcomponents[2]
set libmajor $libname.$libcomponents[3]
if test -f $libname -o -L $libname
echo "$libname already exists"
return 1
end
if test -f $libmajor -o -L $libmajor
echo "$libmajor already exists"
return 2
end
ln -s $lib $libmajor
ln -s $libmajor $libname
end
'';
};
}