[GH-ISSUE #145] Question / documentation: bashrc #113

Closed
opened 2026-02-25 20:32:40 +03:00 by kerem · 4 comments
Owner

Originally created by @fulldecent on GitHub (Feb 9, 2016).
Original GitHub issue: https://github.com/asciinema/asciinema/issues/145

I would like to record all shell sessions to files like:

~/ShellHistory/history-asciinema-20160209T173337Z.json

What needs to be done in bashrc to make this happen? And is this implementation advice worth documenting for others?

Originally created by @fulldecent on GitHub (Feb 9, 2016). Original GitHub issue: https://github.com/asciinema/asciinema/issues/145 I would like to record all shell sessions to files like: > ~/ShellHistory/history-asciinema-20160209T173337Z.json What needs to be done in bashrc to make this happen? And is this implementation advice worth documenting for others?
kerem closed this issue 2026-02-25 20:32:40 +03:00
Author
Owner

@dflock commented on GitHub (Feb 19, 2016):

This would probably get you most of the way there:

command_exists () {
    command -v "$1" &> /dev/null 2>&1 ;
}

if command_exists asciinema ; then
  mkdir -p ~/ShellHistory
  asciinema rec ~/ShellHistory/history-asciinema-$(date +"%Y%m%dT%H%M%S%Z").json
fi;

This defines as bash function called command_exists, then uses it to only run this if the command asciinema is available.

It then ensures that the ShellHistory folder exists, then starts recording to a timestamped file inside that folder.

<!-- gh-comment-id:186426971 --> @dflock commented on GitHub (Feb 19, 2016): This would probably get you most of the way there: ``` bash command_exists () { command -v "$1" &> /dev/null 2>&1 ; } if command_exists asciinema ; then mkdir -p ~/ShellHistory asciinema rec ~/ShellHistory/history-asciinema-$(date +"%Y%m%dT%H%M%S%Z").json fi; ``` This defines as bash function called `command_exists`, then uses it to only run this if the command `asciinema` is available. It then ensures that the `ShellHistory` folder exists, then starts recording to a timestamped file inside that folder.
Author
Owner

@dflock commented on GitHub (Feb 19, 2016):

Not 100% sure about this, but probably be careful to put this at the bottom of the .bashrc - I think that when the user types exit, the subshell will exit, and execution will continue at the next line of the .bashrc - i.e. it'll run the rest of the .bashrc file.

<!-- gh-comment-id:186428442 --> @dflock commented on GitHub (Feb 19, 2016): Not 100% sure about this, but probably be careful to put this at the bottom of the `.bashrc` - I think that when the user types `exit`, the subshell will exit, and execution will continue at the next line of the `.bashrc` - i.e. it'll run the rest of the `.bashrc` file.
Author
Owner

@ku1ik commented on GitHub (Feb 20, 2016):

Note that asciinema spawns new shell process ($SHELL by default) so if you add asciinema rec... to your .bashrc it will most probably start spawning thousands of nested asciinema+bash processes, eventually crashing your machine.

asciinema rec sets ASCIINEMA_REC env var to 1. This can be used to detect if the current bash session is being recorded and preventing asciinema rec to start. Something like this at the bottom of .bashrc could do:

if [[ -z $ASCIINEMA_REC ]]; then
  asciinema rec ......
fi
<!-- gh-comment-id:186659957 --> @ku1ik commented on GitHub (Feb 20, 2016): Note that asciinema spawns new shell process (`$SHELL` by default) so if you add `asciinema rec...` to your `.bashrc` it will most probably start spawning thousands of nested asciinema+bash processes, eventually crashing your machine. `asciinema rec` sets `ASCIINEMA_REC` env var to `1`. This can be used to detect if the current bash session is being recorded and preventing `asciinema rec` to start. Something like this at the bottom of `.bashrc` could do: ``` bash if [[ -z $ASCIINEMA_REC ]]; then asciinema rec ...... fi ```
Author
Owner

@fulldecent commented on GitHub (Feb 20, 2016):

Thank you. These look great!

<!-- gh-comment-id:186705289 --> @fulldecent commented on GitHub (Feb 20, 2016): Thank you. These look great!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asciinema#113
No description provided.