# Summarizing daily shell activity with [Atuin](https://atuin.sh/) and [shell_gpt](https://github.com/TheR1D/shell_gpt)
`obsidian-import` is a utility designed to enhance productivity and knowledge management for [Obsidian](https://obsidian.md). The tool serves as a bridge between a user's shell environment and their Obsidian vault, specifically targeting the integration of daily shell command history into Obsidian's daily notes.
## Motivation
If you're like me, you do a lot of your work via the shell. The script uses [Atuin](https://atuin.sh/), a shell history management tool, to fetch the history in a structured format. It then employs [shell_gpt](https://github.com/TheR1D/shell_gpt), to generate a high-level summary of the day's work, organized by directory or project, and including information about which files were edited.
By integrating `obsidian-import` into your workflow you can have a high level view of your daily activites in [Obsidian](https://obsidian.md). This not only saves time but also ensures that valuable insights and data are not lost in the shuffle of daily tasks.
# Example
Here's an example output summary for my day on 2024-01-31:
> [!Example]+
> - **y-websocket project**
> - **Git operations**
> - Added files to staging (`bin/`)
> - Committed changes with message "y.dnup.org is used exclusively for websockets"
> - Checked git status
> - **Fly.io operations**
> - Listed certificates
> - Added certificate for `ydoc.live`
> - Created Sentry extension
> - **DNS and Networking**
> - Used `dig` to check A record for `ydoc.live` against Cloudflare's DNS
> - **File and Directory Operations**
> - Edited `Dockerfile`
> - Edited `fly.toml`
> - Moved `homepage` directory to `ydoc.live`
> - **Development and Deployment**
> - Edited `manifest.json` in `ydoc.live`
> - Removed `newtab.html` and `styles.css` from `ydoc.live/public`
> - Edited `package.json`, `tsconfig.json`, and `bin/server.js` for configuration and server setup
> - Deployed locally using `fly deploy --local-only`
> - Created an alias `dp` for deployment
> - Installed `cross-fetch` and attempted to configure it with CommonJS
> - **Obsidian Plugin Development**
> - **Obsidian Multiplayer Plugin**
> - Sought AI assistance for JavaScript URL objects and Node.js HTTP requests without libraries like Axios
> - Reviewed changes with `git diff`
> - Imported data with `obsidian-import`
> - Built the plugin with `npm run build`
> - **RTL_433 Project**
> - **Setup and Installation**
> - Cloned `rtl_433` repository
> - Installed dependencies including `cmake`, `libtool`, `libusb-1.0-0-dev`, `librtlsdr-dev`, `rtl-sdr`, `build-essential`, `cmake`, `pkg-config`
> - Attempted to build the project, including using `cmake-gui`
> - Removed and reattempted build setup
> - Consulted documentation for building instructions
## Functionality
The `obsidian-import` script operates by extracting the user's shell history for a given day, filtering out non-material changes (such as navigation or non-impactful git commands), and then summarizing the meaningful activities into a markdown-formatted document. This document is then saved into the user's Obsidian vault, specifically within a "Logs/Shell" directory, with a filename corresponding to the date of the `obsidian-import` Project.
## Usage
The script is designed to be run at the end of the day or at any time the user wishes to import their shell history into Obsidian. It accepts an optional argument to specify a particular date, defaulting to the current day if no argument is provided.
For example:
```
# uses `date -d` syntax
obsidian-import '1 day ago'
```
# Adding your log summary to your daily note
You can add your shell history summary to your daily note by adding it to your daily note template like this:
```
# Shell Activity
![[Logs/Shell/{{title}}#Summary]]
```
# Adding a role to SGPT
The script uses a special role in order to do summarization.
Here's how you can add the role to sgpt.
```
mkdir -p ~/.config/shell_gpt/roles/
cat <<EOF > ~/.config/shell_gpt/roles/summarize.json
{
"expecting" : "Answer",
"name" : "summarize",
"role" : "You are shell history summarizer. You understand shell commands, and the implications of their usage.",
"variables" : {}
}
EOF
```
# The script
```bash
#!/usr/bin/env bash
# obsidian-import
#
# Import a summary of my daily shell history to Obsidian.
#
export PROMPT="summarize what I worked on today at a very high level in markdown using nested bullet points. For each directory group / project include which files were edited. Ignore commands that don't materially change anything (e.g. navigation, git)."
export AFTER=$(date +"%Y-%m-%dT00:00:00%z")
# Check if at least one argument is provided
if [ $# -gt 0 ]; then
AFTER=$(date -d "$1" +"%Y-%m-%dT00:00:00%z")
fi
echo $AFTER
export BEFORE=$(date -d "$AFTER +1 day" +"%Y-%m-%dT00:00:00%z")
export HISTORY="$(atuin search -f 'time={time} directory={directory} duration={duration} status={exit} command={command}' --after $AFTER --before $BEFORE)"
export HISTORY_BLOCK=$(echo "$HISTORY" | sed 's/^/> /')
export SUMMARY=$(echo -e "$HISTORY" | grep -v 'atuin' | sgpt --role=summarize "$PROMPT")
export DAILY_SHELL=$OBSIDIAN_VAULT/Logs/Shell/$(date -d "$AFTER" "+%Y-%m-%d %a").md
export DOC=$(cat << EOF
# Summary
$SUMMARY
# History
> [!History]-
> \`\`\`atuin
$HISTORY_BLOCK
> \`\`\`
EOF
)
echo -e "$DOC" > "$DAILY_SHELL"
echo "Wrote to $DAILY_SHELL"
echo -e "$SUMMARY"
```