New post for revisiting terminal session history with both input and output.

This commit is contained in:
Norm Rasmussen
2024-03-19 13:47:03 -04:00
parent 7601396ffb
commit 80a579f360
37 changed files with 1399 additions and 56 deletions

View File

@ -8,7 +8,7 @@ showToc: true
TocOpen: false
draft: false
hidemeta: false
description: "Learn about running a quick automation that turns rows in your Google Sheets and plugs it into a Google [Slide](2024-02-26_slide.md) template to easily share more attractive content."
description: "Learn about running a quick automation that turns rows in your Google Sheets and plugs it into a Google Slide template to easily share more attractive content."
disableHLJS: true # to disable highlightjs
disableShare: false
disableHLJS: false
@ -27,6 +27,7 @@ cover:
relative: false
hidden: true
---
# Overview
Recently, my wife needed help in sharing weekly content with a group of people. The original way this group was sharing
@ -61,6 +62,7 @@ screenshots of what this looks like for my example:
![Google Sheets Example](../posts/img/google_sheets_for_scripts_example.png)
![Google Slides Example](../posts/img/google_slides_for_scripts_example.png)
<img src="./img/google_slides_for_scripts_example.png" alt="Example image">
## Sheets Setup

View File

@ -0,0 +1,89 @@
---
title: "How to Revisit your Terminal Session's History"
date: 2024-03-19T11:00:53-04:00
tags: ["cli", "terminal", "documentation"]
author: "Me"
showToc: true
TocOpen: false
draft: false
hidemeta: false
description: 'Go beyond zsh/bash_history and save both your commands and the output to a file for later review! This command will help any homelabber that struggles with documentation for their network and services.'
disableHLJS: true # to disable highlightjs
disableShare: false
disableHLJS: false
hideSummary: false
searchHidden: true
ShowReadingTime: true
ShowBreadCrumbs: true
ShowPostNavLinks: true
ShowWordCount: true
ShowRssButtonInSectionTermList: true
UseHugoToc: true
cover:
image: "<image path/url>"
alt: "<alt text>"
caption: "<text>"
relative: false
hidden: true
---
I can't believe I didn't know about this command beforehand. When I first got into self-hosting and homelabbing, one of the app ideas I had that would help me with internal documentation is a terminal program that saves your input and output to a file for you to review later and extract the key commands you used. I also had the bonus idea that you could add comments as you were writing out commands.
Little did I know at the time that comments from the CLI were already possible! I've already begun using comments which has been helpful if I need to look back at my `zsh_history` file. Here's an example of a command I would use with my docker services.
```bash
docker logs {container_name} --since 5m ;: The container is failing 5 minutes after startup.
```
{{< box info >}}
You can write comments in `bash` and `powershell` as well!
* Powershell: `rem`
* ZSH: `;:`
* Bash: `#`
{{< /box >}}
Turns out, I don't need a fancy app to log the input/output of a terminal session! It exists in most unix based systems already and the command is simply this: `script`. That's it!
Unlike `.zsh_history` or `.bash_history` which only saves the commands you input into the terminal, `script` will save both your commands _and_ it's output. Why didn't I know about this before I started setting up my homelab?!
The next time I want to setup a new service or debug something on a server, I will now make sure I start my session with `script {date}-{service_name}.txt` and then start writing out commands. As long as I can remember to write my inline comments during the session, looking back and trying to figure out what I was thinking at the time should be a breeze! I can dump these files into my internal wiki as placeholders. Then, ideally, I'll remove the commands that lead me down a dead end, clean up and expand comments, and easily keep my wiki growing. Ideally being the key word here... I'll take a dump of history files for the time being.
Either way, I will literally have the output of my brain when doing CLI work in a file. Incredible.
Here's a quick overview about script, taken from `man script`.
```bash
SCRIPT(1)
NAME
script make typescript of terminal session
SYNOPSIS
script [-aeFkqr] [-t time] [file [command ...]]
script -p [-deq] [-T fmt] [file]
DESCRIPTION
The script utility makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be
printed out later with lpr(1).
If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript.
If the argument command is given, script will run the specified command with an optional argument vector instead of an interactive shell.
```
<style>
.box-shortcode {
color: #e8e8e8;
border: none;
}
.post-content img {
margin: auto
}
details {
margin: 0;
padding: 0;
border: none;
background: transparent;
box-shadow: none;
}
</style>