1

I've discovered the joy saving Terminator layouts and adding commands to ~/.config/terminator/config that are run when it starts up. I've also discovered that hitting Ctrl+c to stop a watch command for a moment can't be followed by an up arrow to restart the watch because the command isn't in the history.

Here's an ugly work around that only prints the command:

command = (set -x; watch "date") && bash || bash

This allows copying the command after Ctrl+c but who has time for that? I want my up arrow to work. Hoping some bash magic can fix this.

Using terminator 1.91 in RHEL

6
  • Do the startup commands run as your user? My hunch is that they're run as someone else, hence why they don't show up in your history. Would research myself but gotta leave the house now, let me know and I'll try to help out later
    – ajmeese7
    Oct 8, 2022 at 20:33
  • Note that this will be quite tricky as the commands are run in a non-interactive shell which means history is disabled by default. You can try to enable it but even then you would need to explicitly read the history into the new bash shell you start after killing watch before using it.
    – terdon
    Oct 9, 2022 at 11:49
  • @ajmeese7 no, they are run by the right user but history is not enabled in non-interactive shells so they aren't kept in the history. I've been playing with calling the command in an interactive shell and writing the history (command=bash -ic 'watch date; history -a; bash') and then setting PROMPT_COMMAND to history -r to read it in the new shell but I can't get it to work.
    – terdon
    Oct 9, 2022 at 13:48
  • @Terdon I’ll take a reasonable work around. Oct 9, 2022 at 17:46
  • I hear you, I wish I could offer one. None of the things I tried worked, I only mentioned some of the approaches I looked at in case someone smarter can make them work. Sorry :/
    – terdon
    Oct 10, 2022 at 9:56

2 Answers 2

0

This appears to do what I want:

command = watch date && echo "watch date" >> ~/.bash_history && bash || bash

Inspired by How to add a command to the history when it is run inside of a bash script?

0

To avoid the need to repeat the command put this in ~/.config/terminator/config

command = '''bash -ic 'histrun '\''watch "date"'\''''''

and this in .bash_rc

histrun() {
  eval $1 && printf '%s\n' "$1" >> ~/.bash_history && bash || bash
}

If you have a different command (date in this example) that you don't want run right away but want available in history as soon as you hit ctrl-c then use this:

command = '''bash -ic 'histhold '\''date'\''''''

with this:

histhold() {
  printf '%s\n' "$1" && (watch cat) && printf '%s\n' "$1" >> ~/.bash_history && bash || bash
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .