Last active
August 11, 2024 22:22
-
-
Save ejfox/6e9dae1dc4fe907333655d6a4e667af3 to your computer and use it in GitHub Desktop.
Productive start-up script to track Git branches, top tasks, and more details about your latest projects and sessions
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 | |
# Function to get Git branch | |
get_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | |
} | |
# Function to get top tasks from Things | |
get_top_tasks() { | |
echo "[TODAY'S MISSION]" | |
things-cli today | head -n 1 | |
} | |
# Function to get last 3 edited repos | |
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")" "$dir" | |
fi | |
done | |
' sh {} + | sort -rn | head -n 4 | cut -f2- | xargs -n1 basename | |
} | |
# Function to count words in Obsidian vault | |
count_obsidian_words() { | |
local vault_path="/Users/ejfox/Library/Mobile Documents/iCloud~md~obsidian/Documents/ejfox" | |
local total_words | |
total_words=$(find "$vault_path" -name "*.md" -type f -print0 | xargs -0 cat | wc -w) | |
# printf "[NEURAL ARCHIVE STATUS]\n" | |
# printf "Total words: %'d\n" "$total_words" | |
# Get all directories and their word counts | |
local data | |
data=$(find "$vault_path" -type d ! -path "*/.obsidian*" ! -path "*/.trash*" | while read -r dir; do | |
local folder_words | |
folder_words=$(find "$dir" -name "*.md" -type f -print0 | xargs -0 cat | wc -w) | |
printf "%s:%d\n" "$(basename "$dir")" "$folder_words" | |
done) | |
# Sort directories by word count (descending), but keep years in chronological order | |
local sorted_data | |
sorted_data=$(echo "$data" | sort -t':' -k2 -nr | sort -t':' -k1 -n -s) | |
# Calculate the maximum length of directory names and word counts | |
local max_name_length max_count_length | |
max_name_length=$(echo "$sorted_data" | cut -d':' -f1 | wc -L) | |
max_count_length=$(echo "$sorted_data" | cut -d':' -f2 | wc -L) | |
# Calculate number of columns based on terminal width | |
local term_width cols | |
term_width=$(tput cols) | |
cols=$(( (term_width + 3) / (max_name_length + max_count_length + 10) )) # Increased padding | |
[ "$cols" -lt 1 ] && cols=1 | |
# Print the grid | |
local i=0 | |
echo "$sorted_data" | while IFS=':' read -r name count; do | |
printf "%-*s %'*d " "$max_name_length" "$name" "$max_count_length" "$count" | |
i=$((i + 1)) | |
[ $((i % cols)) -eq 0 ] && echo | |
done | |
[ $((i % cols)) -ne 0 ] && echo # Ensure we end with a newline | |
} | |
list_tmux_sessions() { | |
# Get the list of sessions with detailed info | |
tmux list-sessions -F "#{session_name}:#{session_created}:#{session_created_string}:#{session_id}" | while IFS=: read -r session_name session_created session_created_string session_id; do | |
# Calculate how long the session has been open | |
now=$(date +%s) | |
elapsed_seconds=$((now - session_created)) | |
elapsed_time=$(printf '%dd:%dh:%dm:%ds\n' $((elapsed_seconds/86400)) $((elapsed_seconds%86400/3600)) $((elapsed_seconds%3600/60)) $((elapsed_seconds%60))) | |
session_created_string="$session_created_string ($elapsed_time)" | |
# Get the primary process running in the session | |
primary_process=$(tmux list-panes -t "$session_id" -F "#{pane_pid}" | xargs ps -o comm= -p | head -n 1) | |
# Format the output | |
printf "Session: %-15s | %-25s\n" "$session_name" "$session_created_string" | |
done | |
} | |
list_unsynced_repos() { | |
npx git-status-dash -d ~/code/ | |
} | |
# Add this to your main script: | |
list_unsynced_repos | |
# Display information | |
get_top_tasks | |
echo -e "\n[RECENTLY ACCESSED CODEBASES]" | |
get_last_repos | |
echo -e "\n[TMUX SESSIONS]" | |
list_tmux_sessions | |
# echo -e "\n$(count_obsidian_words)" | |
echo -e "\n[SYSTEM READY]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment