From 68fb17abfd6617150914ae68d479554bb9b47981 Mon Sep 17 00:00:00 2001 From: edwark43 <97860398+edwark43@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:51:36 +0000 Subject: [PATCH] Shortened some shell scripts --- misc/bin/brightness | 9 +- misc/bin/hidebar | 16 +--- misc/bin/mediacontrol | 188 ++++++++++++++---------------------------- 3 files changed, 66 insertions(+), 147 deletions(-) diff --git a/misc/bin/brightness b/misc/bin/brightness index 2a1585d..3e24e3d 100755 --- a/misc/bin/brightness +++ b/misc/bin/brightness @@ -1,16 +1,11 @@ #!/usr/bin/env bash # Originally created by - https://github.com/rxyhn -DIR="$HOME/.local/share/assets" BRIGHTNESS_STEPS=5 -function get_brightness { - brightnessctl i | grep -oP '\(\K[^%\)]+' -} - function send_notification { - icon="$DIR/brightness.svg" - brightness=$(get_brightness) + icon="$HOME/.local/share/assets/brightness.svg" + brightness=$(brightnessctl i | grep -oP '\(\K[^%\)]+') bar=$(seq -s "─" 0 $((brightness / 5)) | sed 's/[0-9]//g') dunstify "Brightness $brightness%" -i $icon -r 5555 -u normal -h int:value:$(($brightness)) } diff --git a/misc/bin/hidebar b/misc/bin/hidebar index d73e1bf..545c4ac 100755 --- a/misc/bin/hidebar +++ b/misc/bin/hidebar @@ -1,22 +1,12 @@ #!/usr/bin/env bash -# Originally created by - https://github.com/gh0stzk - -function hide() { -polybar-msg cmd hide | bspc config top_padding 2 | bspc config bottom_padding 2 -} - -function unhide() { -polybar-msg cmd show | bspc config top_padding 48 | bspc config bottom_padding 48 -} - case $1 in -h | --hide | hide) - hide + polybar-msg cmd hide | bspc config top_padding 2 | bspc config bottom_padding 2 exit;; -u | --unhide | unhide) - unhide + polybar-msg cmd show | bspc config top_padding 48 | bspc config bottom_padding 48 exit;; *) - echo "Error: Invalid option" + echo "Invalid option" exit;; esac \ No newline at end of file diff --git a/misc/bin/mediacontrol b/misc/bin/mediacontrol index ec52b90..96499c6 100755 --- a/misc/bin/mediacontrol +++ b/misc/bin/mediacontrol @@ -1,133 +1,67 @@ #!/usr/bin/env bash -# Originally created by - https://github.com/gh0stzk - -# Set the player -[ -n "$(pgrep spotify)" ] && Control="spotify" || Control="MPD" Cover=/tmp/cover.png bkpCover=~/.local/share/assets/fallback.webp mpddir=~/music -case $Control in - MPD) - case $1 in - --next) - mpc -q next - ;; - --previous) - mpc -q prev - ;; - --toggle) - mpc -q toggle - ;; - --stop) - mpc -q stop - ;; - --title) - title=$(mpc -f %title% current) - echo "${title:-Play Something}" - ;; - --artist) - artist=$(mpc -f %artist% current) - echo "${artist:-No Artist}" - ;; - --status) - status=$(mpc status | head -2 | tail -1 | cut -c2-8 | sed 's/]//g' | sed 's/./\U&/') - echo "${status:-Stopped}" - ;; - --player) - echo "$Control" - ;; - --cover) - ffmpeg -i "$mpddir"/"$(mpc current -f %file%)" "${Cover}" -y &> /dev/null || cp $bkpCover $Cover - echo "$Cover" - ;; - nccover) - ffmpeg -i "$mpddir"/"$(mpc current -f %file%)" "${Cover}" -y &> /dev/null || cp $bkpCover $Cover - ;; - --position) - position=$(mpc status %currenttime%) - echo "${position:-0:00}" - ;; - --positions) - positions=$(mpc status %currenttime% | awk -F: '{print ($1 * 60) + $2}') - echo "${positions:-0}" - ;; - --length) - length=$(mpc status %totaltime%) - echo "${length:-0:00}" - ;; - --lengths) - lengths=$(mpc status %totaltime% | awk -F: '{print ($1 * 60) + $2}') - echo "${lengths:-0}" - ;; - --shuffle) - shuffle=$(mpc status | sed -n '3s/.*random: \([^ ]*\).*/\1/p' | sed 's/.*/\u&/') - echo "${shuffle:-Off}" - ;; - --loop) - loop=$(mpc status | sed -n '3s/.*repeat: \([^ ]*\).*/\1/p' | sed 's/.*/\u&/') - echo "${loop:-Off}" - ;; - 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=$(playerctl --player=$Control metadata --format {{title}}) - echo "${title:-Play Something}" - ;; - --artist) - artist=$(playerctl --player=$Control metadata --format {{artist}}) - echo "${artist:-No Artist}" - ;; - --status) - status=$(playerctl --player=$Control status) - echo "${status:-Stopped}" - ;; - --player) - echo "$Control" - ;; - --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" - ;; - --position) - position=$(playerctl --player=$Control position --format "{{ duration(position) }}") - echo "${position:-0:00}" - ;; - --positions) - positions=$(playerctl --player=$Control position | sed 's/..\{6\}$//') - echo "${positions:-0}" - ;; - --length) - length=$(playerctl --player=$Control metadata --format "{{ duration(mpris:length) }}") - echo "${length:-0:00}" - ;; - --lengths) - lengths=$(playerctl --player=$Control metadata mpris:length | sed 's/.\{6\}$//') - echo "${lengths:-0}" - ;; - --shuffle) - shuffle=$(playerctl --player=$Control shuffle) - echo "${shuffle:-Off}" - ;; - --loop) - loop=$(playerctl --player=$Control loop) - echo "${loop:-None}" - ;; - esac -esac 2>/dev/null \ No newline at end of file + +case $1 in + --next) + mpc -q next + ;; + --previous) + mpc -q prev + ;; + --toggle) + mpc -q toggle + ;; + --stop) + mpc -q stop + ;; + --title) + title=$(mpc -f %title% current) + echo "${title:-Play Something}" + ;; + --artist) + artist=$(mpc -f %artist% current) + echo "${artist:-No Artist}" + ;; + --status) + status=$(mpc status | head -2 | tail -1 | cut -c2-8 | sed 's/]//g' | sed 's/./\U&/') + echo "${status:-Stopped}" + ;; + --player) + echo "$Control" + ;; + --cover) + ffmpeg -i "$mpddir"/"$(mpc current -f %file%)" "${Cover}" -y &> /dev/null || cp $bkpCover $Cover + echo "$Cover" + ;; + nccover) + ffmpeg -i "$mpddir"/"$(mpc current -f %file%)" "${Cover}" -y &> /dev/null || cp $bkpCover $Cover + ;; + --position) + position=$(mpc status %currenttime%) + echo "${position:-0:00}" + ;; + --positions) + positions=$(mpc status %currenttime% | awk -F: '{print ($1 * 60) + $2}') + echo "${positions:-0}" + ;; + --length) + length=$(mpc status %totaltime%) + echo "${length:-0:00}" + ;; + --lengths) + lengths=$(mpc status %totaltime% | awk -F: '{print ($1 * 60) + $2}') + echo "${lengths:-0}" + ;; + --shuffle) + shuffle=$(mpc status | sed -n '3s/.*random: \([^ ]*\).*/\1/p' | sed 's/.*/\u&/') + echo "${shuffle:-Off}" + ;; + --loop) + loop=$(mpc status | sed -n '3s/.*repeat: \([^ ]*\).*/\1/p' | sed 's/.*/\u&/') + echo "${loop:-Off}" + ;; +esac \ No newline at end of file