dev: automated commit - 2025-11-17 13:07:30

This commit is contained in:
Mariano Z. 2025-11-17 13:07:31 -03:00
parent 9dca029a62
commit ba26418a15
5 changed files with 156 additions and 32 deletions

View file

@ -79,6 +79,76 @@ function zshrc {
cd "$original_dir"
}
function sb {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: sb"
echo "Launch SilverBullet for notes and open in browser"
echo "Notes directory: ~/Documents/Notes"
echo "Port: 42069"
return 0
fi
local notes_dir="$HOME/Documents/Notes"
local port=42069
# Check if silverbullet command exists
if ! command -v silverbullet >/dev/null 2>&1; then
echo "Error: silverbullet command not found" >&2
echo "Please install SilverBullet first" >&2
return 1
fi
# Check if notes directory exists
if [[ ! -d "$notes_dir" ]]; then
echo "Error: Notes directory not found at $notes_dir" >&2
return 1
fi
# Check if SilverBullet is already running on port 42069
if lsof -i ":$port" >/dev/null 2>&1 && pgrep -f "silverbullet.*$notes_dir" >/dev/null 2>&1; then
echo "SilverBullet is already running for $notes_dir on port $port"
echo "Opening browser at http://127.0.0.1:$port..."
xdg-open "http://127.0.0.1:$port" 2>/dev/null || {
echo "Error: Could not open browser. Please open http://127.0.0.1:$port manually" >&2
return 1
}
return 0
fi
echo "Launching SilverBullet on port $port..."
echo "Notes directory: $notes_dir"
# Launch SilverBullet in the background
silverbullet --port "$port" "$notes_dir" >/dev/null 2>&1 &
local sb_pid=$!
# Wait a moment for SilverBullet to start
local wait_count=0
local max_wait=10
while [[ $wait_count -lt $max_wait ]]; do
if lsof -i ":$port" >/dev/null 2>&1; then
break
fi
sleep 0.5
wait_count=$((wait_count + 1))
done
# Check if process is still running
if ! kill -0 "$sb_pid" 2>/dev/null; then
echo "Error: SilverBullet failed to start" >&2
return 1
fi
# Open browser
echo "Opening browser at http://127.0.0.1:$port..."
xdg-open "http://127.0.0.1:$port" 2>/dev/null || {
echo "Error: Could not open browser. Please open http://127.0.0.1:$port manually" >&2
return 1
}
echo "SilverBullet is running (PID: $sb_pid) on port $port"
}
function yay() {
# Set up completion on first call
if [[ -z "$_yay_completion_setup" ]]; then

Binary file not shown.