eww: dashboard(fake) & spotify player
This commit is contained in:
28
eww/Main/scripts/details
Executable file
28
eww/Main/scripts/details
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $1 == "--image" ]]; then
|
||||
FILE=$HOME/.face
|
||||
if [[ -f "$FILE" ]]; then
|
||||
echo "../../.face"
|
||||
else
|
||||
echo "Main/images/profile.png"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [[ $1 == "--name" ]]; then
|
||||
fullname=$(getent passwd "$(whoami)" | cut -d ':' -f 5 | cut -d ',' -f 1 | tr -d "\n")
|
||||
if [ -z "$fullname" ]; then
|
||||
echo "$(whoami)@$(hostnamectl | awk 'FNR==1 {print $3}')"
|
||||
else
|
||||
echo "$fullname"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $1 == "--kernel" ]]; then
|
||||
echo "$(uname -r)"
|
||||
fi
|
||||
|
||||
if [[ $1 == "--os" ]]; then
|
||||
echo "$(cat /etc/os-release | awk 'NR==1'| awk -F '"' '{print $2}')"
|
||||
fi
|
||||
92
eww/Main/scripts/fortune.py
Executable file
92
eww/Main/scripts/fortune.py
Executable file
@@ -0,0 +1,92 @@
|
||||
#!/bin/env python3
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
def wrap(text, width, height):
|
||||
lines = []
|
||||
|
||||
paragraphs = text.split('\n')
|
||||
|
||||
for paragraph in paragraphs:
|
||||
if len(lines) >= height:
|
||||
return []
|
||||
|
||||
# Skip empty paragraphs
|
||||
if not paragraph.strip():
|
||||
lines.append('')
|
||||
continue
|
||||
|
||||
current_line = ''
|
||||
words = paragraph.split()
|
||||
|
||||
for word in words:
|
||||
if current_line:
|
||||
test_line = current_line + ' ' + word
|
||||
else:
|
||||
test_line = word
|
||||
|
||||
if len(test_line) <= width:
|
||||
current_line = test_line
|
||||
else:
|
||||
if current_line:
|
||||
lines.append(current_line)
|
||||
current_line = word
|
||||
else:
|
||||
while len(word) > width:
|
||||
lines.append(word[:width])
|
||||
word = word[width:]
|
||||
current_line = word
|
||||
|
||||
if current_line:
|
||||
lines.append(current_line)
|
||||
|
||||
return lines
|
||||
|
||||
|
||||
RETRY_LIMIT = 10
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: fortune.py <width> <height>")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
width = int(sys.argv[1])
|
||||
if width <= 0:
|
||||
raise ValueError()
|
||||
height = int(sys.argv[2])
|
||||
if height <= 0:
|
||||
raise ValueError()
|
||||
except ValueError:
|
||||
print("Invalid argument.")
|
||||
sys.exit(1)
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
if i >= RETRY_LIMIT:
|
||||
print("Failed to get fortune after multiple attempts.")
|
||||
sys.exit(1)
|
||||
i += 1
|
||||
|
||||
try:
|
||||
buffer = subprocess.check_output(['fortune', '-s'], text=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error running fortune: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
lines = wrap(buffer, width, height)
|
||||
|
||||
if lines:
|
||||
break
|
||||
else:
|
||||
print("retrying...")
|
||||
|
||||
for line in lines:
|
||||
print(line)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
22
eww/Main/scripts/music-art
Executable file
22
eww/Main/scripts/music-art
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
tmp_dir="$HOME/.config/eww/Main/images"
|
||||
tmp_cover_path=$tmp_dir/cover.png
|
||||
tmp_temp_path=$tmp_dir/temp.png
|
||||
|
||||
if [ ! -d $tmp_dir ]; then
|
||||
mkdir -p $tmp_dir
|
||||
fi
|
||||
|
||||
artlink="$(playerctl -p spotify,$any,mpd,firefox,chromium,brave metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')"
|
||||
artFromBrowser=$(playerctl metadata mpris:artUrl | sed 's/file:\/\///g')
|
||||
|
||||
if [ $(playerctl -p spotify,%any,firefox,chromium,brave,mpd metadata mpris:artUrl) ]; then
|
||||
curl -s "$artlink" --output $tmp_temp_path
|
||||
echo $tmp_temp_path
|
||||
elif [[ -n $artFromBrowser ]]; then
|
||||
cp $artFromBrowser $tmp_temp_path
|
||||
echo $tmp_temp_path
|
||||
else
|
||||
echo Main/images/default-music.svg
|
||||
fi
|
||||
32
eww/Main/scripts/music-artist
Executable file
32
eww/Main/scripts/music-artist
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set the source audio player here.
|
||||
# Players supporting the MPRIS spec are supported.
|
||||
# Examples: spotify, vlc, chrome, mpv and others.
|
||||
# Use `playerctld` to always detect the latest player.
|
||||
# See more here: https://github.com/altdesktop/playerctl/#selecting-players-to-control
|
||||
PLAYER="playerctld"
|
||||
|
||||
# Format of the information displayed
|
||||
# Eg. {{ artist }} - {{ album }} - {{ title }}
|
||||
# See more attributes here: https://github.com/altdesktop/playerctl/#printing-properties-and-metadata
|
||||
FORMAT="{{ artist }}"
|
||||
|
||||
PLAYERCTL_STATUS=$(playerctl --player=$PLAYER status 2>/dev/null)
|
||||
EXIT_CODE=$?
|
||||
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
STATUS=$PLAYERCTL_STATUS
|
||||
else
|
||||
STATUS="No Artist"
|
||||
fi
|
||||
|
||||
if [ "$STATUS" = "Stopped" ]; then
|
||||
echo "No Artist"
|
||||
elif [ "$STATUS" = "Paused" ]; then
|
||||
playerctl --player=$PLAYER metadata --format "$FORMAT"
|
||||
elif [ "$STATUS" = "No Artist" ]; then
|
||||
echo "$STATUS"
|
||||
else
|
||||
playerctl --player=$PLAYER metadata --format "$FORMAT"
|
||||
fi
|
||||
32
eww/Main/scripts/music-length
Executable file
32
eww/Main/scripts/music-length
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set the source audio player here.
|
||||
# Players supporting the MPRIS spec are supported.
|
||||
# Examples: spotify, vlc, chrome, mpv and others.
|
||||
# Use `playerctld` to always detect the latest player.
|
||||
# See more here: https://github.com/altdesktop/playerctl/#selecting-players-to-control
|
||||
PLAYER="playerctld"
|
||||
|
||||
# Format of the information displayed
|
||||
# Eg. {{ artist }} - {{ album }} - {{ title }}
|
||||
# See more attributes here: https://github.com/altdesktop/playerctl/#printing-properties-and-metadata
|
||||
FORMAT="{{ duration(position) }} / {{ duration(mpris:length) }}"
|
||||
|
||||
PLAYERCTL_STATUS=$(playerctl --player=$PLAYER status 2>/dev/null)
|
||||
EXIT_CODE=$?
|
||||
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
STATUS=$PLAYERCTL_STATUS
|
||||
else
|
||||
STATUS="--:-- / --:--"
|
||||
fi
|
||||
|
||||
if [ "$STATUS" = "Stopped" ]; then
|
||||
echo "--:-- / --:--"
|
||||
elif [ "$STATUS" = "Paused" ]; then
|
||||
playerctl --player=$PLAYER metadata --format "$FORMAT"
|
||||
elif [ "$STATUS" = "--:-- / --:--" ]; then
|
||||
echo "$STATUS"
|
||||
else
|
||||
playerctl --player=$PLAYER metadata --format "$FORMAT"
|
||||
fi
|
||||
43
eww/Main/scripts/music-title
Executable file
43
eww/Main/scripts/music-title
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set the source audio player here.
|
||||
# Players supporting the MPRIS spec are supported.
|
||||
# Examples: spotify, vlc, chrome, mpv and others.
|
||||
# Use `playerctld` to always detect the latest player.
|
||||
# See more here: https://github.com/altdesktop/playerctl/#selecting-players-to-control
|
||||
PLAYER="playerctld"
|
||||
|
||||
# Format of the information displayed
|
||||
# Eg. {{ artist }} - {{ album }} - {{ title }}
|
||||
# See more attributes here: https://github.com/altdesktop/playerctl/#printing-properties-and-metadata
|
||||
FORMAT="{{ title }}"
|
||||
|
||||
|
||||
PLAYERCTL_STATUS=$(playerctl --player=$PLAYER status 2>/dev/null)
|
||||
EXIT_CODE=$?
|
||||
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
STATUS=$PLAYERCTL_STATUS
|
||||
else
|
||||
STATUS="Nothing is playing"
|
||||
fi
|
||||
|
||||
if [ "$1" == "--status" ]; then
|
||||
if [ "$STATUS" = "Stopped" ]; then
|
||||
echo "Nothing is playing"
|
||||
elif [ "$STATUS" = "Paused" ]; then
|
||||
playerctl --player=$PLAYER metadata --format "$FORMAT"
|
||||
elif [ "$STATUS" = "Nothing is playing" ]; then
|
||||
echo "$STATUS"
|
||||
else
|
||||
playerctl --player=$PLAYER metadata --format "$FORMAT"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$1" == "--icon" ]; then
|
||||
if [[ $STATUS == "Playing" ]]; then
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
66
eww/Main/scripts/system
Executable file
66
eww/Main/scripts/system
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Files and Data
|
||||
PREV_TOTAL=0
|
||||
PREV_IDLE=0
|
||||
cpuFile="/tmp/.cpu_usage"
|
||||
|
||||
## Get CPU usage
|
||||
get_cpu() {
|
||||
if [[ -f "${cpuFile}" ]]; then
|
||||
fileCont=$(cat "${cpuFile}")
|
||||
PREV_TOTAL=$(echo "${fileCont}" | head -n 1)
|
||||
PREV_IDLE=$(echo "${fileCont}" | tail -n 1)
|
||||
fi
|
||||
|
||||
CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics.
|
||||
unset CPU[0] # Discard the "cpu" prefix.
|
||||
IDLE=${CPU[4]} # Get the idle CPU time.
|
||||
|
||||
# Calculate the total CPU time.
|
||||
TOTAL=0
|
||||
|
||||
for VALUE in "${CPU[@]:0:4}"; do
|
||||
let "TOTAL=$TOTAL+$VALUE"
|
||||
done
|
||||
|
||||
if [[ "${PREV_TOTAL}" != "" ]] && [[ "${PREV_IDLE}" != "" ]]; then
|
||||
# Calculate the CPU usage since we last checked.
|
||||
let "DIFF_IDLE=$IDLE-$PREV_IDLE"
|
||||
let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL"
|
||||
let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10"
|
||||
echo "${DIFF_USAGE}"
|
||||
else
|
||||
echo "?"
|
||||
fi
|
||||
|
||||
# Remember the total and idle CPU times for the next check.
|
||||
echo "${TOTAL}" > "${cpuFile}"
|
||||
echo "${IDLE}" >> "${cpuFile}"
|
||||
}
|
||||
|
||||
## Get Used memory
|
||||
get_mem() {
|
||||
printf "%.0f\n" "$(free -m | grep Mem | awk '{print ($3/$2)*100}')"
|
||||
}
|
||||
|
||||
## Get Volume
|
||||
get_vol() {
|
||||
pamixer --get-volume
|
||||
}
|
||||
|
||||
## Get Brightness
|
||||
get_brightness() {
|
||||
brightnessctl i --machine-readable -d intel_backlight | tr ',' ' ' | awk '{print $4}' | tr -d '%'
|
||||
}
|
||||
|
||||
## Execute accordingly
|
||||
if [[ "$1" == "--cpu" ]]; then
|
||||
get_cpu
|
||||
elif [[ "$1" == "--mem" ]]; then
|
||||
get_mem
|
||||
elif [[ "$1" == "--vol" ]]; then
|
||||
get_vol
|
||||
elif [[ "$1" == "--bri" ]]; then
|
||||
get_brightness
|
||||
fi
|
||||
132
eww/Main/scripts/weather
Executable file
132
eww/Main/scripts/weather
Executable file
@@ -0,0 +1,132 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Collect data
|
||||
cache_dir="$HOME/.cache/eww/weather"
|
||||
cache_weather_stat=${cache_dir}/weather-stat
|
||||
cache_weather_degree=${cache_dir}/weather-degree
|
||||
cache_weather_hex=${cache_dir}/weather-hex
|
||||
cache_weather_icon=${cache_dir}/weather-icon
|
||||
|
||||
if [[ -z "$OPENWEATHER_API_KEY" ]]; then
|
||||
echo "Please set the OPENWEATHER_API_KEY environment variable."
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z "$OPENWEATHER_LAT" ]]; then
|
||||
echo "Please set the OPENWEATHER_LAT environment variable."
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z "$OPENWEATHER_LON" ]]; then
|
||||
echo "Please set the OPENWEATHER_LON environment variable."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## Weather data
|
||||
KEY=$OPENWEATHER_API_KEY
|
||||
LAT=$OPENWEATHER_LAT
|
||||
LON=$OPENWEATHER_LON
|
||||
UNITS=metric
|
||||
|
||||
## Make cache dir
|
||||
if [[ ! -d "$cache_dir" ]]; then
|
||||
mkdir -p ${cache_dir}
|
||||
fi
|
||||
|
||||
## Get data
|
||||
get_weather_data() {
|
||||
weather=`curl -sf "http://api.openweathermap.org/data/3.0/onecall?lat=${LAT}&lon=${LON}&exclude=minutely,hourly,daily&appid=${KEY}&units=${UNITS}" | jq -r ".current"`
|
||||
echo ${weather}
|
||||
|
||||
if [ ! -z "$weather" ]; then
|
||||
weather_temp=`echo "$weather" | jq ".temp" | cut -d "." -f 1`
|
||||
weather_icon_code=`echo "$weather" | jq -r ".weather[].icon" | head -1`
|
||||
weather_description=`echo "$weather" | jq -r ".weather[].description" | head -1 | sed -e "s/\b\(.\)/\u\1/g"`
|
||||
|
||||
#Big long if statement of doom
|
||||
if [ "$weather_icon_code" == "50d" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7aa2f7"
|
||||
elif [ "$weather_icon_code" == "50n" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7aa2f7"
|
||||
elif [ "$weather_icon_code" == "01d" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#e0af68"
|
||||
elif [ "$weather_icon_code" == "01n" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#c0caf5"
|
||||
elif [ "$weather_icon_code" == "02d" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7aa2f7"
|
||||
elif [ "$weather_icon_code" == "02n" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7aa2f7"
|
||||
elif [ "$weather_icon_code" == "03d" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7aa2f7"
|
||||
elif [ "$weather_icon_code" == "03n" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7aa2f7"
|
||||
elif [ "$weather_icon_code" == "04d" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7aa2f7"
|
||||
elif [ "$weather_icon_code" == "04n" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7aa2f7"
|
||||
elif [ "$weather_icon_code" == "09d" ]; then
|
||||
weather_icon=""
|
||||
weather_hex="#7dcfff"
|
||||
elif [ "$weather_icon_code" == "09n" ]; then
|
||||
weather_icon=""
|
||||
weather_hex="#7dcfff"
|
||||
elif [ "$weather_icon_code" == "10d" ]; then
|
||||
weather_icon=""
|
||||
weather_hex="#7dcfff"
|
||||
elif [ "$weather_icon_code" == "10n" ]; then
|
||||
weather_icon=""
|
||||
weather_hex="#7dcfff"
|
||||
elif [ "$weather_icon_code" == "11d" ]; then
|
||||
weather_icon=""
|
||||
weather_hex="#ff9e64"
|
||||
elif [ "$weather_icon_code" == "11n" ]; then
|
||||
weather_icon=""
|
||||
weather_hex="#ff9e64"
|
||||
elif [ "$weather_icon_code" == "13d" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#c0caf5"
|
||||
elif [ "$weather_icon_code" == "13n" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#c0caf5"
|
||||
elif [ "$weather_icon_code" == "40d" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7dcfff"
|
||||
elif [ "$weather_icon_code" == "40n" ]; then
|
||||
weather_icon=" "
|
||||
weather_hex="#7dcfff"
|
||||
else
|
||||
weather_icon=" "
|
||||
weather_hex="#c0caf5"
|
||||
fi
|
||||
echo "$weather_icon" > ${cache_weather_icon}
|
||||
echo "$weather_description" > ${cache_weather_stat}
|
||||
echo "$weather_temp""°C" > ${cache_weather_degree}
|
||||
echo "$weather_hex" > ${cache_weather_hex}
|
||||
else
|
||||
echo "Weather Unavailable" > ${cache_weather_stat}
|
||||
echo " " > ${cache_weather_icon}
|
||||
echo "-" > ${cache_weather_degree}
|
||||
echo "#adadff" > ${cache_weather_hex}
|
||||
fi
|
||||
}
|
||||
|
||||
## Execute
|
||||
if [[ "$1" == "--getdata" ]]; then
|
||||
get_weather_data
|
||||
elif [[ "$1" == "--icon" ]]; then
|
||||
cat ${cache_weather_icon}
|
||||
elif [[ "$1" == "--temp" ]]; then
|
||||
cat ${cache_weather_degree}
|
||||
elif [[ "$1" == "--hex" ]]; then
|
||||
tail -F ${cache_weather_hex}
|
||||
elif [[ "$1" == "--stat" ]]; then
|
||||
cat ${cache_weather_stat}
|
||||
fi
|
||||
Reference in New Issue
Block a user