From aab3d5bee32705b1fb44c2c1a60bf4cc08a90ed7 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Sat, 30 Nov 2024 11:06:29 +0530 Subject: [PATCH] fish: functions: Move HieDb helpers to functions Using abbreviations for shell commands does not seem clean. They also seem out of place along with other cabal abbreviations. While at it, we also add a helper to nuke all Haskell build artefacts. This is convenient instead of running cabal clean in every project or relying on Kondo. For deleting directories, we replace -delete with -exec rm -rv {} + or -exec rm -rv {} \ which should delete directories recursively without error. + at the end will result in rm -rv file1 file2 ... while using \ will result in rm -rv file1; rm -rv file2; ... --- fish/.config/fish/conf.d/cabal-abbr.fish | 2 -- fish/.config/fish/functions/hclean.fish | 3 +++ fish/.config/fish/functions/hieg.fish | 3 +++ fish/.config/fish/functions/hier.fish | 3 +++ 4 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 fish/.config/fish/functions/hclean.fish create mode 100644 fish/.config/fish/functions/hieg.fish create mode 100644 fish/.config/fish/functions/hier.fish diff --git a/fish/.config/fish/conf.d/cabal-abbr.fish b/fish/.config/fish/conf.d/cabal-abbr.fish index 6dc681e..5f0b991 100644 --- a/fish/.config/fish/conf.d/cabal-abbr.fish +++ b/fish/.config/fish/conf.d/cabal-abbr.fish @@ -37,5 +37,3 @@ abbr cpD 'cabal-plan dot' abbr cpdp 'cabal-plan dot-png' abbr cpt 'cabal-plan topo' abbr cplr 'cabal-plan license-reportate' -abbr chi 'hiedb -D .hiedb index .hiefiles --src-base-dir .' -abbr chic 'find . -name .hiefiles | awk \'{print $1" "substr($1, 1, length($1) - length(".hiefiles"))}\' | xargs -n2 sh -c \'hiedb -D .hiedb index $0 --src-base-dir=$1 --skip-types\'' diff --git a/fish/.config/fish/functions/hclean.fish b/fish/.config/fish/functions/hclean.fish new file mode 100644 index 0000000..60a0c28 --- /dev/null +++ b/fish/.config/fish/functions/hclean.fish @@ -0,0 +1,3 @@ +function hclean --description "Clean all Haskell build artefacts" + find . -name .hiedb -type f -delete && find . -name .hiefiles -type d -exec rm -rf {} + && find . -name dist-newstyle -type d -exec rm -rf {} + && find . -name tags -type f -delete && find . -name ".ghc.environment*" -type f -delete +end diff --git a/fish/.config/fish/functions/hieg.fish b/fish/.config/fish/functions/hieg.fish new file mode 100644 index 0000000..07f4255 --- /dev/null +++ b/fish/.config/fish/functions/hieg.fish @@ -0,0 +1,3 @@ +function hieg --description "Generate HieDb" + hiedb -D .hiedb index .hiefiles --src-base-dir . +end diff --git a/fish/.config/fish/functions/hier.fish b/fish/.config/fish/functions/hier.fish new file mode 100644 index 0000000..356a442 --- /dev/null +++ b/fish/.config/fish/functions/hier.fish @@ -0,0 +1,3 @@ +function hier --description "Generate HieDb for multi-project workspace" + find . -name .hiefiles | awk '{print $1" "substr($1, 1, length($1) - length(".hiefiles"))}' | xargs -n2 sh -c 'hiedb -D .hiedb index $0 --src-base-dir=$1 --skip-types' +end