From 8dae19c21cbbfb11e88e32b2385c11256802cd55 Mon Sep 17 00:00:00 2001 From: Sankalp Tharu Date: Thu, 25 May 2023 01:33:22 +0545 Subject: [PATCH] fresh init --- home/.config/bspwm/scripts/ExternalRules | 98 ++++++ home/.config/bspwm/scripts/MediaControl | 281 ++++++++++++++++++ home/.config/bspwm/scripts/OpenApps | 49 +++ home/.config/bspwm/scripts/SetSysVars | 49 +++ home/.config/bspwm/scripts/Updates | 39 +++ home/.config/bspwm/scripts/Weather | 135 +++++++++ home/.config/bspwm/scripts/application.sh | 13 + .../bspwm/scripts/getNotificationCount.sh | 3 + home/.config/bspwm/scripts/info_weather | 164 ++++++++++ home/.config/bspwm/scripts/lockscreen | 86 ++++++ home/.config/bspwm/scripts/music | 107 +++++++ home/.config/bspwm/scripts/noti-center | 28 ++ .../bspwm/scripts/openNotificationCenter.sh | 26 ++ .../bspwm/scripts/pipewire-microphone.sh | 70 +++++ home/.config/bspwm/scripts/winmask | 9 + 15 files changed, 1157 insertions(+) create mode 100755 home/.config/bspwm/scripts/ExternalRules create mode 100755 home/.config/bspwm/scripts/MediaControl create mode 100755 home/.config/bspwm/scripts/OpenApps create mode 100755 home/.config/bspwm/scripts/SetSysVars create mode 100755 home/.config/bspwm/scripts/Updates create mode 100755 home/.config/bspwm/scripts/Weather create mode 100755 home/.config/bspwm/scripts/application.sh create mode 100755 home/.config/bspwm/scripts/getNotificationCount.sh create mode 100755 home/.config/bspwm/scripts/info_weather create mode 100755 home/.config/bspwm/scripts/lockscreen create mode 100755 home/.config/bspwm/scripts/music create mode 100755 home/.config/bspwm/scripts/noti-center create mode 100755 home/.config/bspwm/scripts/openNotificationCenter.sh create mode 100755 home/.config/bspwm/scripts/pipewire-microphone.sh create mode 100755 home/.config/bspwm/scripts/winmask diff --git a/home/.config/bspwm/scripts/ExternalRules b/home/.config/bspwm/scripts/ExternalRules new file mode 100755 index 0000000..555e7a1 --- /dev/null +++ b/home/.config/bspwm/scripts/ExternalRules @@ -0,0 +1,98 @@ +#!/usr/bin/env bash +# ╔═╗═╗ ╦╔╦╗╔═╗╦═╗╔╗╔╔═╗╦ ╦═╗╦ ╦╦ ╔═╗╔═╗ +# ║╣ ╔╩╦╝ ║ ║╣ ╠╦╝║║║╠═╣║ ╠╦╝║ ║║ ║╣ ╚═╗ +# ╚═╝╩ ╚═ ╩ ╚═╝╩╚═╝╚╝╩ ╩╩═╝ ╩╚═╚═╝╩═╝╚═╝╚═╝ +# + +wid=$1 +class=$2 +instance=$3 +consequences=$4 + +main () { +case "$class" in + FloaTerm) + eval "$consequences" + [ "$state" ] || echo "state=floating center=on rectangle=780x450+0+0" + ;; + Updates) + eval "$consequences" + [ "$state" ] || echo "state=floating rectangle=650x268+200+72 sticky=on" + ;; + Updating) + eval "$consequences" + [ "$state" ] || echo "state=floating rectangle=419x268+200+72 sticky=on" + ;; + Ranger) + eval "$consequences" + [ "$state" ] || echo "state=floating rectangle=811x286+0+0 center=on" + ;; + MusicPlayer) + eval "$consequences" + [ "$state" ] || echo "state=floating rectangle=525x370+0+0 center=on" + ;; + Sysfetch) + eval "$consequences" + [ "$state" ] || echo "state=floating rectangle=352x550+1250+72 sticky=on" + ;; + mpv|vlc) + eval "$consequences" + [ "$state" ] || echo "state=floating focus=on center=on rectangle=849x477+0+0" + ;; + Viewnior|obs|Inkscape|feh) + eval "$consequences" + [ "$state" ] || echo "state=floating focus=on center=on" + ;; + whatsapp-nativefier-d40211|TelegramDesktop|discord) + eval "$consequences" + [ "$state" ] || echo "state=pseudo_tiled center=on follow=on rectangle=930x617+0+0" + ;; + retroarch) + eval "$consequences" + [ "$state" ] || echo "state=pseudo_tiled center=on follow=on" + ;; + ranger) + eval "$consequences" + [ "$state" ] || echo "state=floating rectangle=811x316+0+0 center=on" + ;; + Pavucontrol|stacer|Lxappearance|Xfce4-power-manager-settings|System-config-printer.py|Lxtask|Lxrandr|Arandr|Exo-helper-1) + eval "$consequences" + [ "$state" ] || echo "state=floating center=on" + ;; + Virt-manager) + eval "$consequences" + [ "$state" ] || echo "state=floating follow=on center=on" + ;; + Thunar) + eval "$consequences" + [ "$state" ] || echo "state=pseudo_tiled rectangle=966x576+0+0 follow=on center=on" + ;; + firefox|Navigator) + eval "$consequences" + [ "$state" ] || echo "follow=on" + ;; + Transmission-gtk|qBittorrent) + eval "$consequences" + [ "$state" ] || echo "follow=on" + ;; + Spotify) + eval "$consequences" + [ "$state" ] || echo "state=pseudo_tiled center=on rectangle=1125x600 follow=on" + ;; + "") ## spotify hack + sleep 0.5 + wm_class=($(xprop -id $wid | grep "WM_CLASS" | grep -Po '"\K[^,"]+')) + class=${wm_class[-1]} + [[ ${#wm_class[@]} == "2" ]] && instance=${wm_class[0]} + [[ -n "$class" ]] && main + ;; +esac +} + +main +case "$instance" in + Toolkit) + eval "$consequences" + [ "$state" ] || echo "state=floating sticky=on rectangle=500x290+1054+593" + ;; +esac diff --git a/home/.config/bspwm/scripts/MediaControl b/home/.config/bspwm/scripts/MediaControl new file mode 100755 index 0000000..c212a94 --- /dev/null +++ b/home/.config/bspwm/scripts/MediaControl @@ -0,0 +1,281 @@ +#!/usr/bin/env bash + +# ╔╦╗ ╦ ╦ ╔═╗ ╦ ╔═╗ +# ║║║ ║ ║ ╚═╗ ║ ║ +# ╩ ╩ ╚═╝ ╚═╝ ╩ ╚═╝ + +# author Niraj +# github niraj998 + +# ┌─┐┌─┐┌┐┌┌─┐┬┌─┐┬ ┬┬─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐ +# │ │ ││││├┤ ││ ┬│ │├┬┘├─┤ │ ││ ││││└─┐ +# └─┘└─┘┘└┘└ ┴└─┘└─┘┴└─┴ ┴ ┴ ┴└─┘┘└┘└─┘ + +# uncomment your music players below. +# + +Control="MPD" +[ -n "$(pgrep spotify)" ] && Control="spotify" +# [ -n "$(pgrep firefox)" ] && Control="firefox" +# [ -n "$(pgrep rhythmbox)" ] && Control="rhythmbox" +# [ -n "$(pgrep audacious)" ] && Control="audacious" +# [ -n "$(pgrep clementine)" ] && Control="clementine" +# [ -n "$(pgrep strawberry)" ] && Control="strawberry" + + + +# saves covers here +Cover=/tmp/cover.png +# if cover not found in metadata use this instead +bkpCover=~/.config/bspwm/assets/fallback.png +# mpd music directory +mpddir=~/Music + +# ┌─┐┬ ┌─┐┬ ┬┌─┐┬─┐┌─┐┌┬┐┬ ┌─┐┌─┐┬─┐┬┌─┐┌┬┐┌─┐ +# ├─┘│ ├─┤└┬┘├┤ ├┬┘│ │ │ └─┐│ ├┬┘│├─┘ │ └─┐ +# ┴ ┴─┘┴ ┴ ┴ └─┘┴└─└─┘ ┴ ┴─┘ └─┘└─┘┴└─┴┴ ┴ └─┘ + +########################## Title ########################## +title() { +title=$(playerctl --player=$Control metadata --format {{title}}) +[ -z "$title" ] && title="Play Something" +echo "$title" +} + +########################## Artist ########################## +artist() { +artist=$(playerctl --player=$Control metadata --format {{artist}}) +[ -z "$artist" ] && artist="Artist" +echo "$artist" +} + +########################## Album ########################## +album() { +album=$(playerctl --player=$Control metadata --format {{album}}) +[ -z "$album" ] && album="Album" +echo "$album" +} + +########################## Status ########################## +status() { +status=$(playerctl --player=$Control status) +[ -z "$status" ] && status="Stopped" +echo "$status" +} + +########################## Time ########################## +ctime() { +time=$(playerctl --player=$Control position --format "{{ duration(position) }}") +[ -z "$time" ] && time="0:00" +echo "$time" +} + +########################## Length ########################## +length() { +length=$(playerctl --player=$Control metadata --format "{{ duration(mpris:length) }}") +[ -z "$length" ] && length="0:00" +echo "$length" +} + +########################## trackNumber ########################## +playlist() { +playlist=$(playerctl --player=$Control metadata xesam:trackNumber) +[ -z "$playlist" ] && playlist="0" +echo "$playlist" +} + +########################## Cover ########################## +cover() { +albumart="$(playerctl --player=$Control metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')" +[ $(playerctl --player=$Control metadata mpris:artUrl) ] && curl -s "$albumart" --output $Cover || cp $bkpCover $Cover +echo "$Cover" +} + +########################## Statusicon ########################## +statusicon() { +icon="" +[ $(playerctl --player=$Control status) = "Playing" ] && icon="" +[ $(playerctl --player=$Control status) = "Paused" ] && icon="" +echo "$icon" +} + +########################## Lyrics ########################## +lyrics() { +Title=$(playerctl --player=$Control metadata --format {{title}}) +Artist=$(playerctl --player=$Control metadata --format {{artist}}) +URL="https://api.lyrics.ovh/v1/$Artist/$Title" +lyrics=$(curl -s "$( echo "$URL" | sed s/" "/%20/g | sed s/"&"/%26/g | sed s/,/%2C/g | sed s/-/%2D/g)" | jq '.lyrics' ) +[ "$lyrics" = "null" ] && lyrics=$( curl -s --get "https://makeitpersonal.co/lyrics" --data-urlencode "artist=$Artist" --data-urlencode "title=$Title") +printf "$lyrics" | less +} + +# ┌┬┐┌─┐┌┬┐ ┌─┐┌─┐┬─┐┬┌─┐┌┬┐┌─┐ +# │││├─┘ ││ └─┐│ ├┬┘│├─┘ │ └─┐ +# ┴ ┴┴ ─┴┘ └─┘└─┘┴└─┴┴ ┴ └─┘ + +########################## Title ########################## +mpctitle() { +title=$(mpc -f %title% current) +[ -z "$title" ] && title="Play Something" +echo "$title" +} + +########################## Artist ########################## +mpcartist() { +artist=$(mpc -f %artist% current) +[ -z "$artist" ] && artist="Artist" +echo "$artist" +} + +########################## Album ########################## +mpcalbum() { +album=$(mpc -f %album% current) +[ -z "$album" ] && album="Album" +echo "$album" +} + +########################## Cover ########################## +mpccover() { +ffmpeg -i "$mpddir"/"$(mpc current -f %file%)" -vf scale=500:500 "${Cover}" -y || cp $bkpCover $Cover +echo "$Cover" && exit +} + +## Cover for ncmpcpp ## +ncmpcppcover() { +ffmpeg -i "$mpddir"/"$(mpc current -f %file%)" -vf scale=500:500 "${Cover}" -y || cp $bkpCover $Cover +exit +} + +########################## Time ########################## +mpctime() { +time=$(mpc status %currenttime%) +[ -z "$time" ] && time="0:00" +echo "$time" +} + +########################## Length ########################## +mpclength() { +length=$(mpc status %totaltime%) +[ -z "$length" ] && length="0:00" +echo "$length" +} + +########################## Icon ########################## +mpcicon() { +status=$(mpc status | head -2 | tail -1 | cut -c2-7 ) +icon="" +[ "$status" = "playin" ] && icon="" +[ "$status" = "paused" ] && icon="" +echo "$icon" +} + +########################## Status ########################## +mpcstatus() { +stat=$(mpc status | head -2 | tail -1 | cut -c2-7 ) +status="Stopped" +[ "$stat" = "playin" ] && status="Playing" +[ "$stat" = "paused" ] && status="Paused" +echo "$status" +} + +########################## Percent ########################## +mpcperc() { +perc=$(mpc status | grep "%)" | awk '{ print $4 }' | awk -F% '{ print $1 }' | awk 'sub(/^.{1}/,"")') +[ -z "$perc" ] && perc="0" +echo "$perc" +} + +########################## Playlist ########################## +mpcsongpos() { +playlist=$(mpc status %songpos%/%length%) +[ -z "$playlist" ] && playlist="0/0" +echo "$playlist" +} + +########################## Lyrics ########################## +mpclyrics() { +Title=$(mpc -f %title% current) +Artist=$(mpc -f %artist% current) +URL="https://api.lyrics.ovh/v1/$Artist/$Title" +lyrics=$(curl -s "$( echo "$URL" | sed s/" "/%20/g | sed s/"&"/%26/g | sed s/,/%2C/g | sed s/-/%2D/g)" | jq '.lyrics' ) +[ "$lyrics" = "null" ] && lyrics=$( curl -s --get "https://makeitpersonal.co/lyrics" --data-urlencode "artist=$Artist" --data-urlencode "title=$Title") +printf "$lyrics" | less +} + +# ┬ ┬┌─┐┬ ┌─┐ +# ├─┤├┤ │ ├─┘ +# ┴ ┴└─┘┴─┘┴ + +doc() { +echo "Usage: + MediaControl [Options] + +Options: + --previous previous song + --next next song + --toggle toggle between play-pause song + --stop stop song + title shows title of current song + album shows album of current song + artist shows artist of current song + status music status (playing/paused/stopped) + statusicon music status icons (playing/paused/stopped) + coverloc saves cover and shows location to cover of current song + showcover opens cover using feh + time shows current time of song + length shows length of song + percent shows percent song + playlist shows playlist position of current song + lyrics shows lyrics" +} + +# ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐ +# │ │├─┘ │ ││ ││││└─┐ +# └─┘┴ ┴ ┴└─┘┘└┘└─┘ + +case $Control in + MPD) + case $1 in + --next) mpc -q next ;; + --previous) mpc -q prev ;; + --toggle) mpc -q toggle ;; + --stop) mpc -q stop ;; + title) mpctitle ;; + artist) mpcartist ;; + album) mpcalbum ;; + status) mpcstatus ;; + statusicon) mpcicon ;; + player) echo "$Control" ;; + coverloc) mpccover ;; + nccover) ncmpcppcover ;; + showcover) mpccover | xargs feh ;; + time) mpctime ;; + length) mpclength ;; + percent) mpcperc ;; + playlist) mpcsongpos ;; + lyrics) mpclyrics ;; + *) doc ;; + esac + ;; + *) + case $1 in + --next) playerctl --player=$Control next ;; + --previous) playerctl --player=$Control previous ;; + --toggle) playerctl --player=$Control play-pause ;; + --stop) playerctl --player=$Control stop ;; + title) title ;; + artist) artist ;; + album) album ;; + status) status ;; + statusicon) statusicon ;; + player) echo "$Control" ;; + coverloc) cover ;; + showcover) cover | xargs feh ;; + time) ctime ;; + length) length ;; + percent) echo "0" ;; + playlist) playlist ;; + lyrics) lyrics ;; + *) doc ;; + esac +esac 2>/dev/null diff --git a/home/.config/bspwm/scripts/OpenApps b/home/.config/bspwm/scripts/OpenApps new file mode 100755 index 0000000..288575f --- /dev/null +++ b/home/.config/bspwm/scripts/OpenApps @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# ╔═╗╔═╗╔═╗╔═╗ ╦ ╔═╗╦ ╦╔╗╔╔═╗╦ ╦╔═╗╦═╗ +# ╠═╣╠═╝╠═╝╚═╗ ║ ╠═╣║ ║║║║║ ╠═╣║╣ ╠╦╝ +# ╩ ╩╩ ╩ ╚═╝ ╩═╝╩ ╩╚═╝╝╚╝╚═╝╩ ╩╚═╝╩╚═ +# Script to control apps launcher + + +# From here you can control your favorite applications for all themes. + +case "$1" in + --menu) + rofi -show drun \ + -theme $HOME/.config/bspwm/rofi/rasi/launcher.rasi & disown;; + --terminal) + alacritty & disown;; + --floating) + alacritty --class FloaTerm,Alacritty & disown;; + --update) + alacritty --hold --class Updates,Alacritty -e Updates --update-system & disown;; + --checkupdates) + alacritty --hold --class Updating,Alacritty -e Updates --print-updates & disown;; + --ranger) + alacritty --class Ranger,Alacritty -e ranger & disown;; + --nvim) + alacritty -e nvim & disown;; + --music) + alacritty --class MusicPlayer,Alacritty -e ncmpcpp & disown;; + --fetch) + alacritty --hold --class Sysfetch,Alacritty -e ~/.local/bin/sysfetch & disown;; + --Player) + sh ~/.config/bspwm/widgets/MusicPlayer/Music_Player & disown;; + #Apps + --filemanager) + thunar & disown;; + --browser) + firefox & disown;; + --private_browser) + firefox --private-window & disown;; + --editor) + geany & disown;; + --telegram) + telegram & disown;; + --whats) + whatsapp-nativefier --disable-gpu & disown;; + --soundcontrol) + pavucontrol & disown;; + *) + echo "Option Not Valid";; +esac diff --git a/home/.config/bspwm/scripts/SetSysVars b/home/.config/bspwm/scripts/SetSysVars new file mode 100755 index 0000000..55c1333 --- /dev/null +++ b/home/.config/bspwm/scripts/SetSysVars @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +SFILE="$HOME/.config/polybar/.sys" + + +function get_values() { + +DEFNETWORK=$(ip route | grep '^default' | awk '{print $5}' | head -n1) +CARD=$(ls -1 /sys/class/backlight/) +power_supply_files=$(ls /sys/class/power_supply/) + +for file in $power_supply_files +do + if [ -e "/sys/class/power_supply/$file/capacity" ]; then + battery_file=$file + fi + + if [ -e "/sys/class/power_supply/$file/online" ]; then + adapter_file=$file + fi +done + +BATTERY="$battery_file" +ADAPTER="$adapter_file" + +} + +function set_values() { + + if [[ "$DEFNETWORK" ]]; then + sed -i -e "s/sys_network_interface = .*/sys_network_interface = $DEFNETWORK/g" $HOME/.config/polybar/system.ini + fi + if [[ "$ADAPTER" ]]; then + sed -i -e "s/sys_adapter = .*/sys_adapter = $ADAPTER/g" $HOME/.config/polybar/system.ini + fi + if [[ "$BATTERY" ]]; then + sed -i -e "s/sys_battery = .*/sys_battery = $BATTERY/g" $HOME/.config/polybar/system.ini + fi + if [[ "$CARD" ]]; then + sed -i -e "s/sys_graphics_card = .*/sys_graphics_card = $CARD/g" $HOME/.config/polybar/system.ini + fi + +} + +if [[ ! -f "$SFILE" ]]; then + get_values + set_values + touch "$SFILE" +fi diff --git a/home/.config/bspwm/scripts/Updates b/home/.config/bspwm/scripts/Updates new file mode 100755 index 0000000..e3e347c --- /dev/null +++ b/home/.config/bspwm/scripts/Updates @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + + +get_total_updates() { +local total_updates=$(($(checkupdates 2> /dev/null | wc -l || echo 0) + $(paru -Qua 2> /dev/null | wc -l || echo 0))) +echo "${total_updates:-0}" +} + +get_list_updates() { + echo -e "\033[1m\033[34mRegular updates:\033[0m" + checkupdates | sed 's/->/\x1b[32;1m\x1b[0m/g' +} + +print_updates() { +local print_updates=$(get_total_updates) + +if [[ "$print_updates" -gt 0 ]]; then + echo -e "\033[1m\033[33mThere are $print_updates updates available:\033[0m\n" + get_list_updates +else + echo -e "\033[1m\033[32mYour system is already updated!\033[0m" +fi +} + +update_system() { + paru -Syu --nocombinedupgrade +} + +case "$1" in + --get-updates)get_total_updates;; + --print-updates)print_updates;; + --update-system)update_system;; + --help|*)echo -e "Updates [options] + +Options: + --get-updates Get the numer of updates available. + --print-updates Print the available package to updates. + --update-system Update your system including AUR.\n" +esac diff --git a/home/.config/bspwm/scripts/Weather b/home/.config/bspwm/scripts/Weather new file mode 100755 index 0000000..9cfd0c4 --- /dev/null +++ b/home/.config/bspwm/scripts/Weather @@ -0,0 +1,135 @@ +#!/usr/bin/env bash + +encode_to_url_format() { + echo "$1" | sed 's/ /%20/g' +} + +check_if_empty() { + [[ -z "$1" ]] && echo "0" || echo "$1" +} + +KEY="1f6e449790b8cf73a3cab8d5715483f8" +CITY="Kohalpur" +CITYN=$(encode_to_url_format "$CITY") +UNITS="metric" # Available "metric" "imperial" +WEATHER=$(curl -sf "api.openweathermap.org/data/2.5/weather?q=$CITYN&appid=$KEY&units=$UNITS") + +WEATHER_DESC=$(echo "$WEATHER" | jq -r ".weather[0].main") +WEATHER_TEMP=$(echo "$WEATHER" | jq ".main.temp" | cut -d "." -f 1) +WEATHER_ICON_CODE=$(echo "$WEATHER" | jq -r ".weather[].icon" | head -1) +WEATHER_FEELS_LIKE=$(echo "$WEATHER" | jq ".main.feels_like" | cut -d "." -f 1) +WEATHER_HUMIDITY=$(echo "$WEATHER" | jq ".main.humidity" | cut -d "." -f 1) +WEATHER_ICON="" +WEATHER_HEX="" + +case $WEATHER_ICON_CODE in + "01d") + WEATHER_ICON="" + WEATHER_HEX="#ffd86b" + ;; + "01n") + WEATHER_ICON="" + WEATHER_HEX="#fcdcf6" + ;; + "02d") + WEATHER_ICON="" + WEATHER_HEX="#adadff" + ;; + "02n") + WEATHER_ICON="" + WEATHER_HEX="#adadff" + ;; + "03d") + WEATHER_ICON="" + WEATHER_HEX="#adadff" + ;; + "03n") + WEATHER_ICON="" + WEATHER_HEX="#adadff" + ;; + "04d") + WEATHER_ICON="" + WEATHER_HEX="#adadff" + ;; + "04n") + WEATHER_ICON="" + WEATHER_HEX="#acb0d0" + ;; + "09d") + WEATHER_ICON="" + WEATHER_HEX="#6b95ff" + ;; + "09n") + WEATHER_ICON="" + WEATHER_HEX="#6b95ff" + ;; + "10d") + WEATHER_ICON="" + WEATHER_HEX="#6b95ff" + ;; + "10n") + WEATHER_ICON="" + WEATHER_HEX="#6b95ff" + ;; + "11d") + WEATHER_ICON="" + WEATHER_HEX="#ffeb57" + ;; + "11n") + WEATHER_ICON="" + WEATHER_HEX="#ffeb57" + ;; + "13d") + WEATHER_ICON="" + WEATHER_HEX="#e3e6fc" + ;; + "13n") + WEATHER_ICON="" + WEATHER_HEX="#e3e6fc" + ;; + "40d") + WEATHER_ICON="" + WEATHER_HEX="#84afdb" + ;; + "40n") + WEATHER_ICON="" + WEATHER_HEX="#84afdb" + ;; + *) + WEATHER_ICON="" + WEATHER_HEX="#adadff" + ;; +esac + +case $1 in + "current_temp") + check_if_empty "$WEATHER_TEMP" + ;; + "current_temp_fahrenheit") + WEATHER_TEMP=$("$WEATHER_TEMP" 9 / 5 + 32) + check_if_empty "$WEATHER_TEMP" + ;; + "feels_like") + check_if_empty "$WEATHER_FEELS_LIKE" + ;; + "humidity") + check_if_empty "$WEATHER_HUMIDITY" + ;; + "weather_desc") + [[ -z $WEATHER_DESC ]] && echo "Not Available." || echo "$WEATHER_DESC" + ;; + "icon") + echo $WEATHER_ICON + ;; + "hex") + echo $WEATHER_HEX + ;; + "full") + echo "$WEATHER" + ;; + "city") + echo "$CITY" + ;; + "wmodule") + echo $WEATHER_ICON "$WEATHER_TEMP"° +esac diff --git a/home/.config/bspwm/scripts/application.sh b/home/.config/bspwm/scripts/application.sh new file mode 100755 index 0000000..60c16a4 --- /dev/null +++ b/home/.config/bspwm/scripts/application.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +xprop -root -spy _NET_ACTIVE_WINDOW | while read -r wid; do + wid=$(echo $wid | cut -d ' ' -f 5) + if [ "$wid" != "0x0" ]; then + cls=$(xprop -id $wid WM_CLASS) + cls=$(echo $cls | cut -d ' ' -f 4) + cls=$(echo $cls | sed -e 's/^.//;s/.$//;s/^\(.\)/\u\1/') + echo "$cls" + else + echo "0xjack-S4NKALP" + fi +done \ No newline at end of file diff --git a/home/.config/bspwm/scripts/getNotificationCount.sh b/home/.config/bspwm/scripts/getNotificationCount.sh new file mode 100755 index 0000000..f2ae71d --- /dev/null +++ b/home/.config/bspwm/scripts/getNotificationCount.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +[[ "$(dunstctl history | jq -r '.data[0]')" = "[]" ]] && echo true || echo false diff --git a/home/.config/bspwm/scripts/info_weather b/home/.config/bspwm/scripts/info_weather new file mode 100755 index 0000000..fc57a4b --- /dev/null +++ b/home/.config/bspwm/scripts/info_weather @@ -0,0 +1,164 @@ +#!/bin/bash + +cache="$HOME/.cache/eww/weather" +cache_status="$cache/status" +cache_temperature="$cache/temperature" +cache_gradient_1="$cache/gradient_1" +cache_gradient_2="$cache/gradient_2" +cache_icon="$cache/icon" +cache_city="$cache/city" +cache_country="$cache/country" + +[ ! -d $cache ] && mkdir $cache + +key="1f6e449790b8cf73a3cab8d5715483f8" +id="6941099" +unit="metric" # Available options : 'metric' or 'imperial' + +data () { + weather=`curl -sf "http://api.openweathermap.org/data/2.5/weather?APPID=$key&id=$id&units=$unit"` + + if [ ! -z "$weather" ]; then + temperature=$(echo "$weather" | jq ".main.temp" | cut -d "." -f 1) + city=$(echo "$weather" | jq -r ".name" | head -1) + country=$(echo "$weather" | jq -r ".sys.country" | head -1) + icon_code=$(echo "$weather" | jq -r ".weather[].icon" | head -1) + description=$(echo "$weather" | jq -r ".weather[].description" | head -1 | sed -e "s/\b\(.\)/\u\1/g") + + if [ "$icon_code" == "50d" ]; then + icon="󰖐" + gradient_1="#ece3b1" + gradient_2="#c9d4ff" + elif [ "$icon_code" == "50n" ]; then + icon="󰖐" + gradient_1="#ceace8" + gradient_2="#c9d4ff" + elif [ "$icon_code" == "01d" ]; then + icon="󰖙" + gradient_1="#ece3b1" + gradient_2="#ece3b1" + elif [ "$icon_code" == "01n" ]; then + icon="" + gradient_1="#ceace8" + gradient_2="#ceace8" + elif [ "$icon_code" == "02d" ]; then + icon="" + gradient_1="#ece3b1" + gradient_2="#a3cbe7" + elif [ "$icon_code" == "02n" ]; then + icon="" + gradient_1="#ceace8" + gradient_2="#a3cbe7" + elif [ "$icon_code" == "03d" ]; then + icon="" + gradient_1="#ece3b1" + gradient_2="#a3cbe7" + elif [ "$icon_code" == "03n" ]; then + icon="" + gradient_1="#ceace8" + gradient_2="#a3cbe7" + elif [ "$icon_code" == "04d" ]; then + icon="" + gradient_1="#a3cbe7" + gradient_2="#ece3b1" + elif [ "$icon_code" == "04n" ]; then + icon="" + gradient_1="#a3cbe7" + gradient_2="#ceace8" + elif [ "$icon_code" == "09d" ]; then + icon="" + gradient_1="#b4e3ad" + gradient_2="#ece3b1" + elif [ "$icon_code" == "09n" ]; then + icon="" + gradient_1="#b4e3ad" + gradient_2="#ceace8" + elif [ "$icon_code" == "10d" ]; then + icon="" + gradient_1="#ffdede" + gradient_2="#ece3b1" + elif [ "$icon_code" == "10n" ]; then + icon="" + gradient_1="#ffdede" + gradient_2="#ceace8" + elif [ "$icon_code" == "11d" ]; then + icon="" + gradient_1="#e5a3a1" + gradient_2="#ece3b1" + elif [ "$icon_code" == "11n" ]; then + icon="" + gradient_1="#e5a3a1" + gradient_2="#ceace8" + elif [ "$icon_code" == "13d" ]; then + icon="" + gradient_1="#c9d4ff" + gradient_2="#c9d4ff" + elif [ "$icon_code" == "13n" ]; then + icon="" + gradient_1="#c9d4ff" + gradient_2="#c9d4ff" + elif [ "$icon_code" == "40d" ]; then + icon="煮" + gradient_1="#a3cbe7" + gradient_2="#a3cbe7" + elif [ "$icon_code" == "40n" ]; then + icon="煮" + gradient_1="#a3cbe7" + gradient_2="#a3cbe7" + else + icon="" + gradient_1="#b4e3ad" + gradient_2="#a3cbe7" + fi + + echo "$icon" > $cache_icon + echo "$city" > $cache_city + echo "$country" > $cache_country + echo "$description" > $cache_status + echo "$temperature""°C" > $cache_temperature + echo "$gradient_1" > $cache_gradient_1 + echo "$gradient_2" > $cache_gradient_2 + else + echo "-" > $cache_city + echo "-" > $cache_country + echo "Weather Unavailable" > $cache_status + echo "" > $cache_icon + echo "-" > $cache_temperature + echo "#b4e3ad" > $cache_gradient_1 + echo "#a3cbe7" > $cache_gradient_2 + fi +} + +case $1 in + data) + data + ;; + icon) + data & + cat $cache_icon + ;; + color-1) + data & + cat $cache_gradient_1 + ;; + color-2) + data & + cat $cache_gradient_2 + ;; + city) + data & + cat $cache_city + ;; + country) + data & + cat $cache_country + ;; + temperature) + data & + cat $cache_temperature + ;; + status) + data & + cat $cache_status + ;; +esac \ No newline at end of file diff --git a/home/.config/bspwm/scripts/lockscreen b/home/.config/bspwm/scripts/lockscreen new file mode 100755 index 0000000..fcf8c76 --- /dev/null +++ b/home/.config/bspwm/scripts/lockscreen @@ -0,0 +1,86 @@ +#!/bin/bash + +LOCK_FILE="$HOME/.cache/eww-lock.lock" + +hide_unhide_windows() { + while bspc node any.hidden.window -g hidden=off; do false; done && while bspc node 'any.!hidden.window' -g hidden=on; do :; done +} + +lock() { + hsetroot -fill "$HOME/Pictures/cube.png" + # Wait for eww to finish load widget + sleep 0.5 + + i3lock -n -c 00000000 -t -e --pass-media-keys --pass-power-keys --pass-volume-keys --indicator \ + --radius 64 --modif-size=9 --modif-pos="w/2:h/2-15" \ + \ + --time-str="" \ + --time-pos="w/2:h/2+35" \ + --time-color=e5e9f0 \ + --time-size=14 \ + --time-font="Sarasa Mono CL Nerd Font" \ + \ + --verif-text="" \ + --verif-color=7ba5dd \ + --verif-size=10 \ + --verif-font="Sarasa Mono CL Nerd Font" \ + \ + --wrong-text="" \ + --wrong-color=bf616a \ + --wrong-size=10 \ + --wrong-font="Sarasa Mono CL Nerd Font" \ + \ + --greeter-text="" \ + --greeter-color=8fbcbb \ + --greeter-size=60 \ + --greeter-font="Sarasa Mono CL Nerd Font" \ + --greeter-pos="w/2-22:h/2+285" \ + \ + --ring-color=81a1c1 \ + --ringver-color=88c0d0 \ + --ringwrong-color=bf616a \ + --ring-width=5 \ + \ + --insidever-color=2e3440A8 \ + --insidewrong-color=2e3440A8 \ + --inside-color=2e344000 \ + --ind-pos="w/2-150:h/2-45" \ + \ + --noinput-text="" \ + \ + --line-uses-inside --keyhl-color=7ba5dd --bshl-color=ee6a70 --separator-color=7ba5dd \ + --pointer=default +} + +run() { + $HOME/.config/bspwm/scripts/toggle-polybar + hide_unhide_windows + eww -c ~/.config/bspwm/widgets/lockscreen open lock-screen + lock +} + +status=$(playerctl -p %any status || true) +if [ "$status" == "Playing" ]; then + playerctl pause +fi + +if [[ ! -f "$LOCK_FILE" ]]; then + if pgrep -x rofi; then + killall rofi + fi + + touch "$LOCK_FILE" + run +fi + +rm "$LOCK_FILE" +hsetroot -fill "$HOME/Pictures/cube.png" +# hsetroot -solid "#192022" +killall eww +sleep 0.2 && hide_unhide_windows +$HOME/.config/bspwm/scripts/toggle-polybar + +status2=$(playerctl -p %any status || true) +if [ "$status2" == "Paused" ]; then + playerctl play +fi diff --git a/home/.config/bspwm/scripts/music b/home/.config/bspwm/scripts/music new file mode 100755 index 0000000..fe0396d --- /dev/null +++ b/home/.config/bspwm/scripts/music @@ -0,0 +1,107 @@ +#!/bin/bash + +players="spotify,%any,firefox,chromium,brave,mpd" +player_status=$(playerctl -p $players status) +artist=$(playerctl -p $players metadata --format '{{ artist }}') +title=$(playerctl -p $players metadata --format '{{ title }}') +albumart="$(playerctl -p $players metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')" +cache="$HOME/.cache/eww/music" + +[ ! -d $cache ] && mkdir $cache + +status_icon () { + if [ "$player_status" = "Playing" ]; then + echo "" + elif [ "$player_status" = "Paused" ]; then + echo "" + else + echo "" + fi +} + +status_value () { + player_name=$(playerctl -p $players -l | head -n 1) + + [ "$player_status" = "Playing" ] && echo "Now Playing - via ${player_name^}" || echo "Music" +} + +title () { + [ -z "$title" ] && echo "Nothing Playing" || echo $title +} + +artist () { + if [ "$title" = "Advertisement" ]; then + echo "Spotify Free" + else + if [ -z "$artist" ]; then + echo "Unknown Artist"; + else + echo "by $artist" + fi + fi +} + +cover_notification () { + cover_dir="$cache/notification-cover" + [ ! -d $cover_dir ] && mkdir $cover_dir + cover="$cover_dir/$RANDOM-cover.png" + fallback="$HOME/.config/bspwm/assets/fallback.png" + + players_pass=$1 + + if [[ $players_pass == "mpd" ]]; then + albumart="$(playerctl -p mpd metadata mpris:artUrl)" + else + albumart="$(playerctl -p $players_pass metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')" + fi + + [ $(playerctl -p $players_pass metadata mpris:artUrl) ] && curl -s "$albumart" --output $cover || cp $fallback $cover + + echo $cover | tail -n 1 +} + +cover () { + cover="$cache/cover.png" + fallback="$HOME/.config/bspwm/assets/fallback.png" + + [ $(playerctl -p $players metadata mpris:artUrl) ] && curl -s "$albumart" --output $cover || cp $fallback $cover + echo $cover +} + +position () { + position=$(playerctl -p $players position | sed 's/..\{6\}$//') + duration=$(playerctl -p $players metadata mpris:length | sed 's/.\{6\}$//') + + if [[ $position -gt 0 ]]; then + printf "%0d:%02d" $((position%3600/60)) $((position%60)) + printf " / " + printf "%0d:%02d" $((duration%3600/60)) $((duration%60)) + fi +} + +case $1 in + status) + status_value + ;; + status-icon) + status_icon + ;; + title) + title + ;; + artist) + artist + ;; + title-artist) + echo $(title) - $(artist) + ;; + cover) + cover + ;; + cover-notification) + cover_notification $2 + ;; + position) + position || echo "--:-- / --:-- " + ;; +esac diff --git a/home/.config/bspwm/scripts/noti-center b/home/.config/bspwm/scripts/noti-center new file mode 100755 index 0000000..a1a068e --- /dev/null +++ b/home/.config/bspwm/scripts/noti-center @@ -0,0 +1,28 @@ +#!/bin/bash + +[ ! -d $cache_dir ] && mkdir $cache_dir + +cache_dir="$HOME/.cache/eww" +cache="$cache_dir/notification-center.eww" +config="$HOME/.config/bspwm/widgets/notification-center" + +run () { + eww -c $config open notification-center + sleep 0 + eww -c $config update notification-center=true +} + +if [[ ! `pidof eww` ]]; then + eww -c $config daemon + sleep 0 +else + if [ ! -f $cache ]; then + touch $cache + run + else + eww -c $config update notification-center=false + sleep 0 + eww -c $config close notification-center + rm $cache + fi +fi diff --git a/home/.config/bspwm/scripts/openNotificationCenter.sh b/home/.config/bspwm/scripts/openNotificationCenter.sh new file mode 100755 index 0000000..151a668 --- /dev/null +++ b/home/.config/bspwm/scripts/openNotificationCenter.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +LOCK_FILE="$HOME/.cache/eww-notification-center.lock" +EWW_BIN="$HOME/.local/bin/eww" + +run() { + ${EWW_BIN} open notification-center + sleep 0.2 + ${EWW_BIN} update noticenter=true +} + +# Run eww daemon if not running +if [[ ! `pidof eww` ]]; then + ${EWW_BIN} daemon + sleep 1 +else + if [[ ! -f "$LOCK_FILE" ]]; then + touch "$LOCK_FILE" + run + else + ${EWW_BIN} update noticenter=false + sleep 0.8 + ${EWW_BIN} close notification-center + rm "$LOCK_FILE" + fi +fi diff --git a/home/.config/bspwm/scripts/pipewire-microphone.sh b/home/.config/bspwm/scripts/pipewire-microphone.sh new file mode 100755 index 0000000..819d4c5 --- /dev/null +++ b/home/.config/bspwm/scripts/pipewire-microphone.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +get_mic_default() { + pactl info | grep -E "Default Source: " | sed -n -e 's/^.*: //p' +} + +is_mic_muted() { + mic_name="$(get_mic_default)" + + pactl list sources | \ + awk -v mic_name="${mic_name}" '{ + if ($0 ~ "Name: " mic_name) { + matched_mic_name = 1; + } else if (matched_mic_name && /Mute/) { + print $2; + exit; + } + }' +} + +get_mic_status() { + is_muted="$(is_mic_muted)" + mic_name="$(get_mic_default)" + + if [ "${is_muted}" = "yes" ]; then + printf "%s\n" "󰍭" + else + volume=$(pactl get-source-volume "$mic_name" | grep Volume | awk -F/ '{print $2}' | tr -d ' ') + echo "󰍬 "$volume"" + fi +} + +listen() { + get_mic_status + + LANG=EN; pactl subscribe | while read -r event; do + if printf "%s\n" "${event}" | grep --quiet "source" || printf "%s\n" "${event}" | grep --quiet "server"; then + get_mic_status + fi + done +} + +toggle() { + pactl set-source-mute @DEFAULT_SOURCE@ toggle +} + +increase() { + DEFAULT_SOURCE="$(get_mic_default)" + pactl set-source-volume "$DEFAULT_SOURCE" +5% +} + +decrease() { + DEFAULT_SOURCE="$(get_mic_default)" + pactl set-source-volume "$DEFAULT_SOURCE" -5% +} + +case "$1" in + --toggle) + toggle + ;; + --increase) + increase + ;; + --decrease) + decrease + ;; + *) + listen + ;; +esac diff --git a/home/.config/bspwm/scripts/winmask b/home/.config/bspwm/scripts/winmask new file mode 100755 index 0000000..a621153 --- /dev/null +++ b/home/.config/bspwm/scripts/winmask @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +masked=$(bspc query -N -n .hidden -d focused) + +if [ -z "$masked" ]; then + bspc node focused -g hidden=on +else + bspc node "$masked" -g hidden=off +fi