I would like to create a key binding, using the key sequence
C-x r, to reload the configuration of
bash, stored in
~/.bashrc, and the one of the readline library stored in
To reload the configuration of readline, I think I could use the
re-read-init-file function which is described in
man 3 readline:
re-read-init-file (C-x C-r) Read in the contents of the inputrc file, and incorporate any bindings or variable assignments found there.
To reload the configuration of
bash, I could use the
. command. However, I'm not sure what's the best way to combine a shell command with a readline function. So, I came up with the combination of 2 key bindings:
bind '"\C-xr": ". ~/.bashrc \C-x\C-z1\C-m"' bind '"\C-x\C-z1": re-read-init-file'
When I hit
C-x r in bash, here's what happens:
. ~/.bashrc `~/.bashrc` is inserted on the command line C-x C-z 1 `C-x C-z 1` is typed which is bound to `re-read-init-file` C-m `C-m` is hit which executes the current command line
It seems to work because, inside tmux, if I have 2 panes, one to edit
~/.bashrc, the other with a shell, and I change a configuration file, after hitting
C-x r in the shell, I can see the change taking effect (be it a new alias or a new key binding), without the need to close the pane to reopen a new shell.
But, is there a better way of achieving the same result? In particular, is it possible to execute the commands without leaving an entry in the history? Because if I hit
C-p to recall the last executed command, I get
. ~/.bashrc, while I would prefer to directly get the command which was executed before I re-sourced the shell configuration.
I have the same issue with
bindkey -s '^Xr' '. ~/.zshrc^M'
Again, after hitting
C-x r, the command
. ~/.zshrc is logged in the history. Is there a better way to re-source the config of