How Do I Make bashrc File Update Upon Changes?

I edited my bashrc file to have custom aliases, but the only way I can figure out that actually updates it is by running kill 1, and I don’t want to reload the repl every single time. Any ideas?

1 Like

With the pkgs.inotify-tools system dependency added:
If the file changes have been saved, run:

. .config/bashrc

Otherwise, you can wait for the file to change before restarting by pasting this command in Shell (or putting it in a function which you can then run):

inotifywait -qqe create .config --include=bashrc
. .config/bashrc

I’m trying to do this, but it is not working. here’s the related code:

def add_command(command, code):
    if not(os.path.exists(".congig/bashrc")):
        with open('.config/bashrc', 'w') as f:
        bashrc_content = '''
        # Courtesy of
        # Do not edit this code!
        touch "$_RUN_SHELL_COMMAND_LIB_PIPE";
        while true;
          do sleep 0.1;
          if [ -s "$_RUN_SHELL_COMMAND_LIB_PIPE" ];
            echo -n "" > "$_RUN_SHELL_COMMAND_LIB_OUT_PIPE";
            echo -n "" > "$_RUN_SHELL_COMMAND_LIB_PIPE";
        done &

        with open('.config/bashrc', 'w') as f:
    with open(".config/bashrc", "a") as f:
        f.write(f'alias {command}="{code}"\n')

    os.system("inotifywait -qqe create .config --include=bashrc")
    os.system(". .config/bashrc")

    "echo 'Hello, world!'")

It doesn’t properly update the shell, so if I were to now run hello in the shell, it wouldn’t do anything.

oh, if you want to refresh the Shell after the bashrc has been updated programmatically, you’d have to use a command like

. .config/bashrc

if you really want to make the script work on its own, you’d have to restart the whole shell process (and so also reload the nix environment):

os.kill(os.getppid(), 1)

I don’t think you can issue commands to the parent shell as you have tried to do.

It never runs any code after that (the Flask project).

Restarts so can’t use.