Split fish functions off into separate file, add clangfmt
function
This commit is contained in:
parent
949c67f829
commit
e6643c0d1d
2 changed files with 44 additions and 19 deletions
|
@ -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 = [
|
||||
{
|
||||
|
|
43
home-manager/modules/fish/functions.nix
Normal file
43
home-manager/modules/fish/functions.nix
Normal file
|
@ -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";
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue