Skip to content

Instantly share code, notes, and snippets.

@dtkav
Created January 10, 2024 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtkav/e1e7b34b472a2a90ea54990ec7318e64 to your computer and use it in GitHub Desktop.
Save dtkav/e1e7b34b472a2a90ea54990ec7318e64 to your computer and use it in GitHub Desktop.
Import and summarize shell activity into Obsidian
#!/usr/bin/env bash
#
# 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
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 SUMMARY=$(echo -e "$HISTORY" | grep -v 'atuin' | grep -v 'Pop!_OS' | 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
\`\`\`atuin
$HISTORY
\`\`\`
EOF
)
echo -e "$DOC" > "$DAILY_SHELL"
echo "Wrote to $DAILY_SHELL"
echo -e "$SUMMARY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment