add eww config

This commit is contained in:
matt1432 2023-05-28 18:05:51 -04:00
parent fac0e15a9e
commit 85dde2e9aa
34 changed files with 2112 additions and 0 deletions

35
eww/scripts/bluetooth Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env bash
get_state () {
state=$(bluetoothctl show | grep 'Powered' | awk '{print $2}')
if [[ $state == "yes" ]]; then
echo on
else
echo off
fi
}
turn_off () {
bluetoothctl power off 2>&1 > /dev/null
}
turn_on () {
bluetoothctl power on 2>&1 > /dev/null
}
toggle () {
state=$(get_state)
if [[ $state == "on" ]]; then
turn_off
else
turn_on
fi
}
if [[ $1 == "state" ]]; then
get_state
fi
if [[ $1 == "toggle" ]]; then
toggle
fi

50
eww/scripts/brightness.sh Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
# @requires: brightnessctl
percentage () {
local val=$(echo $1 | tr '%' ' ' | awk '{print $1}')
local icon1=$2
local icon2=$3
local icon3=$4
local icon4=$5
if [ "$val" -le 15 ]; then
echo $icon1
elif [ "$val" -le 30 ]; then
echo $icon2
elif [ "$val" -le 60 ]; then
echo $icon3
else
echo $icon4
fi
}
get_brightness () {
(( br = $(brightnessctl get) * 100 / $(brightnessctl max) ))
echo $br
}
get_percent () {
echo $(get_brightness)%
}
get_icon () {
local br=$(get_percent)
echo $(percentage "$br" "" "" "" "")
}
if [[ $1 == "br" ]]; then
get_brightness
fi
if [[ $1 == "percent" ]]; then
get_percent
fi
if [[ $1 == "icon" ]]; then
get_icon
fi
if [[ $1 == "set" ]]; then
light -S $2
fi

2
eww/scripts/cpu.sh Executable file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}' | tr '.' ' ' | awk '{print $1}'

3
eww/scripts/disk.sh Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
df --output=pcent / | tail -n 1 | sed 's/%//g' | awk '{print $1}'

4
eww/scripts/exec Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
cd ~
${@} 2>&1 >/dev/null &

64
eww/scripts/mic Executable file
View file

@ -0,0 +1,64 @@
#!/usr/bin/env bash
# @requires: pactl
SINK=$(pactl list short sinks | sed -e 's,^\([0-9][0-9]*\)[^0-9].*,\1,' | head -n 1)
status () {
status=$(pactl get-source-mute $SINK | awk '{print $2}')
if [[ $status == 'yes' ]]; then
echo no
else
echo yes
fi
}
set_volume () {
local max_db=65536
local percent=$1
# getting the $percent% of $max_db
local value=$(jq -n ${percent}/100*${max_db} | sed 's/\./ /g' | awk '{print $1}')
# set volume
pacmd set-source-volume $SINK $value
}
get () {
local enabled=$(status)
if [[ $enabled == 'no' ]]; then
echo '0'
else
pacmd list short sinks | grep volume:\ front | tail -n 1 | awk '{print $5}' | sed 's/%//g'
fi
}
percentage () {
local val=$(get)
echo "${val}%"
}
_ () {
${@}
exit 0
}
if [[ $1 == "status" ]]; then
_ status
fi
if [[ $1 == "toggle" ]]; then
_ pactl set-source-mute $SINK toggle
fi
if [[ $1 == "set" ]]; then
_ set_volume ${2}
fi
if [[ $1 == "get" ]]; then
_ get
fi
if [[ $1 == "percent" ]]; then
_ percentage
fi

13
eww/scripts/music/control.sh Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
if [[ $1 == "prev" ]]; then
playerctl previous
fi
if [[ $1 == "play-pause" ]]; then
playerctl play-pause
fi
if [[ $1 == "next" ]]; then
playerctl next
fi

45
eww/scripts/music/songart.sh Executable file
View file

@ -0,0 +1,45 @@
#!/bin/bash
# thanks to kizu
get_song_art () {
TMP_DIR="$HOME/.cache/eww"
TMP_COVER_PATH=$TMP_DIR/cover.png
TMP_TEMP_PATH=$TMP_DIR/temp.png
if [[ ! -d $TMP_DIR ]]; then
mkdir -p $TMP_DIR
fi
ART_FROM_SPOTIFY="$(playerctl -p %any,spotify metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')"
ART_FROM_BROWSER="$(playerctl -p %any,mpd,firefox,chromium,brave metadata mpris:artUrl | sed -e 's/file:\/\///g')"
if [[ $(playerctl -p spotify,%any,firefox,chromium,brave,mpd metadata mpris:artUrl) ]]; then
curl -s "$ART_FROM_SPOTIFY" --output $TMP_TEMP_PATH
elif [[ -n $ART_FROM_BROWSER ]]; then
cp $ART_FROM_BROWSER $TMP_TEMP_PATH
else
cp $HOME/.config/eww/assets/fallback.png $TMP_TEMP_PATH
fi
cp $TMP_TEMP_PATH $TMP_COVER_PATH
# an epic effekt
# convert $TMP_TEMP_PATH -alpha set -channel A -evaluate multiply 1.0 $TMP_COVER_PATH
# convert $TMP_TEMP_PATH -gravity center +repage -alpha set -channel A \
# -sparse-color Barycentric '%[fx:w*2/32],0 transparent %[fx:w+0.5],0 opaque' \
# -evaluate multiply 0.45 \
# $TMP_COVER_PATH
}
echo_song_art_url () {
echo "$HOME/.cache/eww/cover.png"
}
if [[ $1 == "echo" ]]; then
echo_song_art_url
fi
if [[ $1 == "get" ]]; then
get_song_art
fi

36
eww/scripts/music/songdata.sh Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
capitalize () {
toshow="$1"
maxlen="$2"
sufix=""
if test $(echo $toshow | wc -c) -ge $maxlen ; then
sufix=" ..."
fi
echo "${toshow:0:$maxlen}$sufix"
}
withSafe () {
local txt="$1"
local safe="$2"
if [[ $txt == "" ]]; then
echo $safe
else
echo $txt
fi
}
if [[ $1 == "title" ]]; then
capitalize "$(playerctl metadata --format "{{title}}" || echo "Nothing playing")" 18
fi
if [[ $1 == "artist" ]]; then
withSafe "$(capitalize "$(playerctl metadata --format "{{artist}}" || echo "No artist")" 18)" "No artist detected"
fi
if [[ $1 == "status" ]]; then
playerctl status || echo 'Paused'
fi

101
eww/scripts/network.sh Executable file
View file

@ -0,0 +1,101 @@
#!/bin/bash
symbol() {
[ $(cat /sys/class/net/w*/operstate) = down ] && echo&& exit
echo
}
name() {
iwgetid -r
}
cut () {
toshow="$1"
maxlen="$2"
sufix=""
if test $(echo $toshow | wc -c) -ge $maxlen ; then
sufix=" ..."
fi
echo "${toshow:0:$maxlen}$sufix"
}
[ "$1" = "icon" ] && symbol
if [[ $1 == "ssid" ]]; then
ssid=$(name)
if [[ "$ssid" == "" ]]; then
cut "Disconnected" 10
else
cut "$ssid" 10
fi
fi
if [[ $1 == "name" || $1 == "class" ]]; then
wifiname=$(name)
if [[ $wifiname == "" ]]; then
if [[ $1 == "name" ]]; then
echo "Disconnected"
elif [[ $1 == "class" ]]; then
echo "disconnected"
fi
else
if [[ $1 == "name" ]]; then
echo "Connected to $wifiname"
elif [[ $1 == "class" ]]; then
echo "connected"
fi
fi
fi
if [[ $1 == "status" ]]; then
name=$(name)
if [[ $name != "" ]]; then
echo "Connected"
else
echo "Disconnected"
fi
fi
if [[ $1 == "disconnect" ]]; then
wifiname=$(nmcli d | grep wifi | sed 's/^.*wifi.*connected//g' | xargs)
nmcli con down id "${wifiname}"
fi
if [[ $1 == "connect" ]]; then
nmcli con up ifname "$(/usr/bin/ls /sys/class/ieee80211/*/device/net/)"
fi
if [[ $1 == "toggle" ]]; then
name=$(name)
if [[ "$name" == "" ]]; then
nmcli con up ifname "$(/usr/bin/ls /sys/class/ieee80211/*/device/net/)"
else
wifiname=$(nmcli d | grep wifi | sed 's/^.*wifi.*connected//g' | xargs)
nmcli con down id "${wifiname}"
fi
fi
radio_status () {
radio_status=$(nmcli radio wifi)
if [[ $radio_status == "enabled" ]]; then
echo "on"
else
echo "off"
fi
}
if [[ $1 == "radio-status" ]]; then
radio_status
fi
if [[ $1 == "toggle-radio" ]]; then
stat=$(radio_status)
if [[ $stat == "on" ]]; then
nmcli radio wifi off
else
nmcli radio wifi on
fi
fi

12
eww/scripts/pfp.sh Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env bash
declare -a profiles_photos=("$HOME/.face.jpg" "$HOME/.face.png")
for pfp in ${profiles_photos[@]}; do
if test -f $pfp; then
echo $pfp
exit 0
fi
done
echo $HOME/.config/dk/eww/assets/default-pfp.png

42
eww/scripts/ram.sh Executable file
View file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
percentage () {
local val=$(echo $1 | tr '%' ' ' | awk '{print $1}')
local icon1=$2
local icon2=$3
local icon3=$4
local icon4=$5
if [ "$val" -le 15 ]; then
echo $icon1
elif [ "$val" -le 30 ]; then
echo $icon2
elif [ "$val" -le 60 ]; then
echo $icon3
else
echo $icon4
fi
}
get_ram () {
free -m | grep Mem | awk '{print ($3/$2)*100}' | tr '.' ' ' | awk '{print $1}'
}
get_percent () {
echo $(get_ram)%
}
get_class () {
local percent=$(get_percent)
echo $(percentage "$percent" "yellow" "magenta" "purple" "red")
}
if [[ $1 == "ram" ]]; then
get_ram
fi
if [[ $1 == "percent" ]]; then
get_percent
fi
if [[ $1 == "class" ]]; then
get_class
fi

70
eww/scripts/redshift Executable file
View file

@ -0,0 +1,70 @@
#!/usr/bin/env bash
cache_file=$HOME/.cache/eww/services/redshift_state
initial_hook () {
if [ ! -d $(dirname $cache_file) ]; then
mkdir -p $(dirname $cache_file)
fi
if [ ! -f $cache_file ]; then
echo off > $cache_file
fi
}
get_state () {
# check if redshift is running
cat $cache_file
}
restore () {
local state=$(get_state)
if [[ $state == "on" ]]; then
enable_redshift
else
disable_redshift
fi
}
disable_redshift () {
redshift -x 2>&1 > /dev/null
# saving state
echo off > $cache_file
}
enable_redshift () {
redshift -x 2>&1 > /dev/null
redshift -O 5000 2>&1 > /dev/null
# saving new state
echo on > $cache_file
}
toggle () {
local state=$(get_state)
if [[ $state == "on" ]]; then
disable_redshift
else
enable_redshift
fi
}
initial_hook
if [[ $1 == "state" ]]; then
get_state
fi
if [[ $1 == "enable" ]]; then
enable_redshift
fi
if [[ $1 == "disable" ]]; then
disable_redshift
fi
if [[ $1 == "toggle" ]]; then
toggle
fi
if [[ $1 == "restore" ]]; then
restore
fi

34
eww/scripts/screensht Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env bash
TMP_PATH="$HOME/.cache/eww/tmp-screenshot.png"
report () {
xclip -selection clipboard -target image/png -i $TMP_PATH
notify-send -i $TMP_PATH -a Screenshot "Screenshot" "Screenshot copied successfully"
}
recollect () {
rm $TMP_PATH
}
full () {
maim $TMP_PATH
}
area () {
maim --select $TMP_PATH
}
if [[ $1 == "full" ]]; then
full
report
recollect
fi
if [[ $1 == "area" ]]; then
area
report
recollect
fi
exit 0

39
eww/scripts/temp.sh Executable file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env bash
# thanks to rxyhn
path () {
local temp_path=null
for i in /sys/class/hwmon/hwmon*/temp*_input;
do
temp_path="$(echo "$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null ||
echo $(basename ${i%_*})) $(readlink -f $i)");"
label="$(echo $temp_path | awk '{print $2}')"
if [ "$label" = "Package" ];
then
echo ${temp_path} | awk '{print $5}' | tr -d ';\n'
exit;
fi
done
}
get () {
local path=$(path)
if [[ $path == "" ]]; then
path="/sys/class/thermal/thermal_zone0/temp"
fi
local max_temp=100
local temp=$(cat $path)
jq -n $(jq -n $temp/1000)/$max_temp*100
}
_ () {
${@}
exit 0
}
if [[ $1 == "get" ]]; then
_ get
fi

8
eww/scripts/user.sh Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env bash
name () {
username=$(whoami)
echo ${username^}
}
name

93
eww/scripts/volume.sh Executable file
View file

@ -0,0 +1,93 @@
#!/bin/bash
# @requires: pactl
#SINK=$(pactl list short sinks | sed -e 's,^\([0-9][0-9]*\)[^0-9].*,\1,' | head -n 1)
SINK="@DEFAULT_SINK@"
percentage () {
local val=$(echo $1 | tr '%' ' ' | awk '{print $1}')
local icon1=$2
local icon2=$3
local icon3=$4
local icon4=$5
if [ "$val" -le 15 ]; then
echo $icon1
elif [ "$val" -le 30 ]; then
echo $icon2
elif [ "$val" -le 60 ]; then
echo $icon3
else
echo $icon4
fi
}
is_muted () {
pacmd list-sinks | awk '/muted/ { print $2 }'
}
get_percentage () {
local muted=$(is_muted)
if [[ $muted == 'yes' ]]; then
echo 0%
else
vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep Volume | awk '{print $5}' | tr % " ")
echo "${vol}%"
fi
}
get_icon () {
local vol=$(get_percentage)
if [[ $vol == "0%" ]]; then
echo "婢"
else
echo $(percentage "$vol" "" "" "墳" "")
fi
}
get_class () {
local vol=$(get_percentage)
if [[ $vol == "0%" ]]; then
echo "red"
else
echo $(percentage "$vol" "red" "magenta" "yellow" "blue")
fi
}
get_vol () {
#local percent=$(get_percentage)
#echo $percent | tr -d '%'
echo $(pactl get-sink-volume @DEFAULT_SINK@ | grep Volume | awk '{print $5}' | tr % " ")
}
if [[ $1 == "icon" ]]; then
get_icon
fi
if [[ $1 == "class" ]]; then
get_class
fi
if [[ $1 == "percentage" ]]; then
get_percentage
fi
if [[ $1 == "vol" ]]; then
get_vol
fi
if [[ $1 == "muted" ]]; then
is_muted
fi
if [[ $1 == "toggle-muted" ]]; then
pactl set-sink-mute $SINK toggle
fi
if [[ $1 == "set" ]]; then
val=$(echo $2 | tr '.' ' ' | awk '{print $1}')
if test $val -gt 100; then
val=100
fi
pactl set-sink-volume $SINK $val%
fi

77
eww/scripts/volume.sh.bak Executable file
View file

@ -0,0 +1,77 @@
#!/usr/bin/env bash
VOLUME=$(pactl get-sink-volume @DEFAULT_SINK@ | grep Volume | awk '{print $5}' | tr % " ")
function icon {
if [[ $VOLUME -ge 66 ]]; then echo '󰕾'
elif [[ $VOLUME -ge 33 ]]; then echo '󰖀'
elif [[ $VOLUME -ge 1 ]]; then echo '󰕿'
else echo '󰝟'
fi
}
function level {
echo $(pactl get-sink-volume @DEFAULT_SINK@ | grep Volume | awk '{print $5}' | tr % " ")
}
function lower {
pactl set-sink-volume @DEFAULT_SINK@ -5%
update
}
function raise {
pactl set-sink-volume @DEFAULT_SINK@ +5%
update
}
function update {
eww update volume="$(get)"
~/.config/eww/scripts/osd $(icon) $(level)
}
function type_icon {
SINK=$(pactl get-default-sink)
if [[ $SINK == *'bluez_output'* ]]; then echo "󰋋"
else echo "󰓃"
fi
}
function mute_state {
STATE=$(pactl get-source-mute @DEFAULT_SOURCE@ | awk '{print $2}')
if [[ $STATE == 'no' ]]; then echo 'off'
else echo 'on'; fi
}
function mute_icon {
STATE=$(mute_state)
if [[ $STATE == 'off' ]]; then echo '󰍬'
else echo '󰍭'; fi
}
function mute_toggle {
pactl set-source-mute @DEFAULT_SOURCE@ toggle
eww update volume="$(get)"
}
function set {
pactl set-sink-volume @DEFAULT_SINK@ $1"%"
eww update volume="$(get)"
}
function get {
echo "{
\"level\": \"$(level)\",
\"icon\": \"$(icon)\",
\"type_icon\": \"$(type_icon)\",
\"mute\": {
\"state\": \"$(mute_state)\",
\"icon\": \"$(mute_icon)\"
}
}"
}
if [[ $1 == 'mute_toggle' ]]; then mute_toggle; fi
if [[ $1 == 'down' ]]; then lower; fi
if [[ $1 == 'up' ]]; then raise; fi
if [[ $1 == 'set' ]]; then set $2; fi
if [[ $1 == 'get' ]]; then get; fi