Created
November 24, 2024 20:29
-
-
Save ejfox/eebc03d81881722135300e4f4135e1c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# File: ~/.custom_startup.sh | |
# Description: Custom startup script for EJ Fox's terminal, providing a personalized MOTD. | |
get_top_tasks() { | |
things-cli today | head -n 3 | |
} | |
get_last_repos() { | |
find ~/code -maxdepth 1 -type d -exec sh -c ' | |
for dir do | |
if [ -d "$dir/.git" ]; then | |
printf "%s\t%s\n" "$(stat -f "%m" "$dir")" "⌥ $(basename "$dir" | iconv -f utf-8 -t utf-8 -c)" | |
fi | |
done | |
' sh {} + | sort -rn | head -n 3 | cut -f2- | |
} | |
get_last_obsidian_notes() { | |
local obsidian_note_root="${HOME}/Library/Mobile Documents/iCloud~md~obsidian/Documents/ejfox" | |
find "${obsidian_note_root}" -type f -mtime -1 -not -path '*/\.*' -print0 | while IFS= read -r -d '' file; do | |
# Get relative path from obsidian root | |
local rel_path="${file#$obsidian_note_root/}" | |
printf "※ %s\n" "$rel_path" | |
done | head -n 3 | |
} | |
list_tmux_sessions() { | |
tmux list-sessions -F "#{session_name}:#{session_created}:#{session_created_string}" | while IFS=: read -r session_name session_created session_created_string; do | |
now=$(date +%s) | |
elapsed_seconds=$((now - session_created)) | |
elapsed_time=$(printf '%dd:%dh:%dm:%ds' $((elapsed_seconds/86400)) $((elapsed_seconds%86400/3600)) $((elapsed_seconds%3600/60)) $((elapsed_seconds%60))) | |
printf "Session: %-15s | %-25s\n" "$session_name" "$session_created_string ($elapsed_time)" | |
done | |
} | |
list_unsynced_repos() { | |
node ~/code/git-status-dash/index.mjs -d ~/code/ | |
} | |
fetch_mastodon_posts() { | |
local cache_file="/tmp/mastodon_cache.txt" | |
if [[ ! -f $cache_file || $(find "$cache_file" -mmin +60) ]]; then | |
curl -s https://ejfox-mastodon.web.val.run | jq -r '.[].content' | iconv -f utf-8 -t utf-8 -c | tr -d '\n' | head -c 2048 > "$cache_file" | |
fi | |
cat "$cache_file" | |
} | |
get_random_alias() { | |
grep "^alias" ~/.zshrc | sort -R | head -n 1 | cut -d'=' -f1 | awk '{print $2}' | |
} | |
generate_alias_hint() { | |
local alias=$1 | |
local recent_history=$(tail -n 100 ~/.zsh_history | cut -d ';' -f 2-) | |
local all_aliases=$(grep "^alias" ~/.zshrc) | |
local prompt="Here are all the user's aliases: | |
$all_aliases | |
Here are the last 100 commands from the user's history for context: | |
$recent_history | |
Generate a short video game style hint for the shell alias '$alias' as if the user has never heard of it before—include both the alias and what commands it runs. 'Hey, have you tried [X]? It's good for [Y]!' The hint should be concise, helpful, and slightly playful. Plain text only, we are in a shell. Respond with a single sentence hint, nothing else." | |
echo "$prompt" | llm -m gpt-4o-mini -o max_tokens 128 | |
} | |
get_current_weeknote() { | |
local obsidian_note_root="${HOME}/Library/Mobile Documents/iCloud~md~obsidian/Documents/ejfox" | |
local current_week=$(date +%V) | |
local current_year=$(date +%Y) | |
current_week=$(printf "%02d" $current_week) | |
local weeknote_path="${obsidian_note_root}/week-notes/${current_year}-${current_week}.md" | |
if [ -f "$weeknote_path" ]; then | |
sed '/^---$/,/^---$/d' "$weeknote_path" | head -c 8000 | |
fi | |
} | |
main() { | |
local today_tasks=$(get_top_tasks | iconv -f utf-8 -t utf-8 -c) | |
local recent_repos=$(get_last_repos | iconv -f utf-8 -t utf-8 -c) | |
local recent_obsidian_notes=$(get_last_obsidian_notes | iconv -f utf-8 -t utf-8 -c) | |
local mastodon_posts=$(fetch_mastodon_posts | iconv -f utf-8 -t utf-8 -c) | |
local random_alias=$(get_random_alias | iconv -f utf-8 -t utf-8 -c) | |
local alias_hint=$(generate_alias_hint "$random_alias" | iconv -f utf-8 -t utf-8 -c) | |
local recent_history=$(tail -n 24 ~/.zsh_history | cut -d ';' -f 2-) | iconv -f utf-8 -t utf-8 -c | |
local current_weeknote=$(get_current_weeknote) | |
list_unsynced_repos | |
echo -e "\n[TODAY'S MISSION]" | |
echo "$today_tasks" | |
echo -e "\n[RECENTLY ACCESSED]" | |
echo "$recent_repos" | |
echo "$recent_obsidian_notes" | |
echo -e "\n[TMUX SESSIONS]" | |
list_tmux_sessions | |
echo -e "\n[PROTIP]" | |
echo "$alias_hint" | |
echo -e "\n[SYSTEM READY]" | |
local combined_data=" | |
## Working Directory: | |
$(pwd) | |
## This Week's Notes: | |
$current_weeknote | |
## Recent Mastodon Posts: | |
$mastodon_posts | |
## Today's Tasks: | |
$today_tasks | |
## Recent Repos: | |
$recent_repos | |
## Terminal History: | |
$recent_history | |
Tmux Sessions: | |
$(list_tmux_sessions) | |
Current Time: $(date)" | |
local prompt="Your user is EJ Fox, a hacker and journalist based in New York. You are the AI at the heart of his MacBook Pro. Please compose an 'MOTD' that will appear in the terminal when it boots. Try to keep lines relatively short. In a style that captures your unique voice and the spirit of Neal Stephenson, write a precise and descriptive narrative of the user information provided, reflecting on and summarizing the user's recent activities. Elegantly tie threads between the patterns. Relate the timestamped actions to the current time (be it morning or night). Highlight the things they might not even know connect their thoughts. Pick one thread to highlight. Keep it under a few sentences—with the wisdom of the I Ching subtly (never explicitly) woven in. Short but surprisingly meaningful and information-dense. Use only plain text. Do not use any code markup. Just send back the MOTD as it should appear to the user. Weave in the information you know about them. Keep lines short as this is displayed in a terminal. | |
$combined_data" | |
echo "$prompt" | llm -m gpt-4o-mini -o max_tokens 600 | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment