Comments (2)
I was refactoring the code to be more idiomatic of Mac OS X and take advantage of zsh. Now it gets through most of the .zlogin before it just closes arbitrarily.
#!/bin/zsh
set -euo pipefail
setopt extended_glob
#!/bin/zsh
set -euo pipefail
setopt extended_glob
# --- Function Definitions ---
get_moon_icon() {
local moon_phase="$1"
if (( $(echo "$moon_phase < 0.0625 || $moon_phase > 0.9375" | bc -l) )); then
printf 'π New Moon'
elif (( $(echo "$moon_phase > 0.4375 && $moon_phase < 0.5625" | bc -l) )); then
printf 'π Full Moon'
elif (( $(echo "$moon_phase < 0.5" | bc -l) )); then
printf 'π Waxing'
else
printf 'π Waning'
fi
}
get_weather_icon() {
local icon_code="$1"
case $icon_code in
01*) printf 'βοΈ' ;; # Clear sky
02*) printf 'π€οΈ' ;; # Few clouds
03*) printf 'βοΈ' ;; # Scattered clouds
04*) printf 'π₯οΈ' ;; # Broken clouds
09*) printf 'π§οΈ' ;; # Shower rain
10*) printf 'π¦οΈ' ;; # Rain
11*) printf 'βοΈ' ;; # Thunderstorm
13*) printf 'βοΈ' ;; # Snow
50*) printf 'π«οΈ' ;; # Mist
*) printf 'βοΈ' ;; # Default to cloud
esac
}
fetch_weather_data() {
local api_url="$1"
if ! curl -sf "$api_url"; then
print -u2 "Failed to fetch data from API." >&2 # Redirect error message to stderr
return 1
fi
}
get_weather_and_moon() {
local api_key="your_openweathermap_api_key" # Replace with your actual API key
local home_city=$(defaults read NSGlobalDomain AppleLocale | tr '_' ' ')
local home_coords=$(
corelocationcli get-location |
plutil -extract latitude raw - | xargs printf "%.4f," &&
plutil -extract longitude raw - | xargs printf "%.4f"
)
local weather_data_url="https://api.openweathermap.org/data/2.5/onecall?lat=$home_coords&exclude=minutely,hourly,daily,alerts&units=imperial&appid=$api_key"
local weather_data=$(fetch_weather_data "$weather_data_url") || return
local moon_phase=$(echo "$weather_data" | jq -r '.current.moon_phase')
local icon_code=$(echo "$weather_data" | jq -r '.current.weather[0].icon')
local moon_icon=$(get_moon_icon "$moon_phase")
local weather_icon=$(get_weather_icon "$icon_code")
printf "π %s %s\n" "$moon_icon" "$weather_icon"
}
get_uptime() {
sysctl -n kern.boottime | awk '{print $4}' | sed 's/,//' | xargs -I{} uptime -s {}
}
# ... (rest of the script is the same)
# Function to get system uptime
get_uptime() {
local boot_time
local current_time
local uptime_seconds
local days
local hours
local minutes
local seconds
boot_time=$(sysctl -n kern.boottime | awk '{print $4}' | sed 's/,//')
current_time=$(date +%s)
uptime_seconds=$((current_time - boot_time))
days=$((uptime_seconds / 86400))
hours=$(( (uptime_seconds % 86400) / 3600 ))
minutes=$(( (uptime_seconds % 3600) / 60 ))
seconds=$((uptime_seconds % 60))
printf "%d days, %d hours, %d minutes, %d seconds" "$days" "$hours" "$minutes" "$seconds"
}
# --- Session Login Commands ---
# Welcome Message
printf "\n$(tput bold)$(tput setaf 2)Welcome to your Zsh session, %s!$(tput sgr0)\n\n" "$(whoami)"
# Date & Time (Local and UTC)
printf "Local Time: %s\n" "$(date +'%a, %b %d %Y, %I:%M %p %Z')"
printf "UTC Time: %s\n\n" "$(date -u +'%a, %b %d %Y, %I:%M %p UTC')"
# Weather & Moon Phase
get_weather_and_moon
# System Information
printf "$(tput bold)System Info:$(tput sgr0)\n"
printf "Uptime: %s\n" "$(get_uptime)"
printf "Disk Usage: %s used of %s\n" "$(df -h / | awk 'NR==2{print $5}')" "$(df -h / | awk 'NR==2{print $2}')"
printf "Memory Usage: %s\n\n" "$(top -l 1 | awk '/PhysMem/{print $2}')"
# Random Quote/Tip
printf "$(tput bold)Thought for the day:$(tput sgr0)\n"
curl -s https://api.quotable.io/random | jq -r '.content'
# Update Checks (Optional)
if command -v brew &> /dev/null; then
printf "\n$(tput bold)Checking for updates...$(tput sgr0)\n"
brew update &>/dev/null
brew outdated --quiet || brew upgrade --quiet
printf "Done.\n"
fi
# Custom Messages/Reminders
printf "\n$(tput bold)Remember to review your tasks for the day!$(tput sgr0)\n"
from warp.
Hi @thomasvincent thanks for letting us know. I was able to isolate the line which is causing the issue.
# Enable strict mode
set -euo pipefail
There are a few options here that may be able to help with the issue.
- Move the line to the bottom of the script, this will allow the functions to run and not exit the session.
- Remove the
-eu
flag which appears to be causing the session quit. - Wrap the code in a conditional to disable it just for Warp:
if [[ $TERM_PROGRAM != "WarpTerminal" ]]; then
# Enable strict mode
set -euo pipefail
fi
I'll notify the team of this issue and we'll post further updates on this thread.
from warp.
Related Issues (20)
- Option to exclude directories/files from autocompletion/suggestion HOT 2
- When suggesting commands from recently run, intelligently place wildcards HOT 1
- Warp no longer accepts terminal commands and only accepts natural language HOT 8
- Unable to move cursor back to second line after latest update (using Starship) HOT 5
- Tapping Update Warp button should immediately start the update flow HOT 2
- Workflow usage not working when connected to remote ssh shell HOT 1
- Double pasting when using middle mouse button HOT 2
- ohmyzsh sudo plugin non-functional HOT 1
- Agent Mode: `exit` evaluated as natural language HOT 2
- Add pipe the output to another command or workflow HOT 2
- warp hangs after paste in vi HOT 2
- Warp for Linux doesn't open a window HOT 1
- Import/export not working on Fedora Silverblue HOT 2
- Window isn't opening HOT 6
- User easily loses entire natural language chat session tab which closes and can't bring it back HOT 2
- Adding start and end times for blocks HOT 3
- Ability to select single panes for synchronize inputs HOT 1
- AI agent needs some UX help with clipboard HOT 1
- Configuration: export/import or auto-cloud-backup, and multiple profiles. HOT 1
- Rectangleεwrapηwork樑εΌθΏθ‘θε¨ HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from warp.