nix/module/common/bash/Init.nix

29 lines
754 B
Nix
Raw Normal View History

2024-04-06 03:03:58 +03:00
{ style, util, pkgs, ... } @args: let
2024-04-08 18:26:01 +03:00
modules = pkgs.writeText "bashModules" (util.trimTabs (builtins.foldl' (acc: mod:
2024-04-06 03:03:58 +03:00
acc + (import mod args).text
) "" (util.ls ./module)));
in {
2024-04-08 18:26:01 +03:00
inherit modules;
2024-04-06 03:03:58 +03:00
config = util.trimTabs (''
# If not running interactively, don't do anything.
2024-04-08 18:26:01 +03:00
# [[ "$-" != *i* ]] && return
2024-04-06 03:03:58 +03:00
2024-04-08 18:26:01 +03:00
'') + builtins.readFile modules + util.trimTabs (''
2024-04-06 03:03:58 +03:00
# Find all functions.
function find_function() {
2024-04-08 18:26:01 +03:00
/usr/bin/env cat ${modules} | /usr/bin/env grep "^function.*()" | /usr/bin/env sed -e "s/^function //" -e "s/().*//"
2024-04-06 03:03:58 +03:00
}
# Export all functions.
export -f $(find_function | tr '\n' ' ')
2024-04-07 19:57:58 +03:00
export -f find_function
2024-04-06 03:03:58 +03:00
# Autostart Sway.
if [[ -z $DISPLAY ]] && [[ "$(tty)" = "/dev/tty1" ]]; then
exec sway
fi
'');
}