From c6f72095cb25dcc9a9f08692bfb8d8fcf7ba3217 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 16 Oct 2024 17:46:26 +1100 Subject: [PATCH] feat: Add a few more scripts --- .gitignore | 1 + close_window.sh | 5 +++++ music.sh | 32 +++++++++++++++------------ storage.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ zellij.sh | 23 +++++++++++++++++++ 5 files changed, 106 insertions(+), 14 deletions(-) create mode 100755 close_window.sh create mode 100755 storage.sh create mode 100755 zellij.sh diff --git a/.gitignore b/.gitignore index e08fc85..858dd42 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ powertop/ libtracefs/ libtraceevent/ +weather.sh diff --git a/close_window.sh b/close_window.sh new file mode 100755 index 0000000..70ce290 --- /dev/null +++ b/close_window.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +window_id=$(xdotool getwindowfocus) +# xdotool windowclose $window_id +xdotool windowactivate --sync $window_id key --clearmodifiers --delay 100 alt+F4 \ No newline at end of file diff --git a/music.sh b/music.sh index f75bb1e..0263fab 100755 --- a/music.sh +++ b/music.sh @@ -97,9 +97,9 @@ if [ "$active_count" -eq 1 ]; then title=$(playerctl -p "$brave" metadata --format '{{title}}') truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH + $MAX_ARTIST_LENGTH))) if [ "$status" == "Paused" ]; then - echo "🎵 $truncated_title (Paused)" + echo "󰝚 $truncated_title (Paused)" else - echo "🎵 $truncated_title" + echo "󰝚 $truncated_title" fi exit 0 fi @@ -108,9 +108,9 @@ if [ "$active_count" -eq 1 ]; then truncated_artist=$(truncate_string "$artist" $MAX_ARTIST_LENGTH) if [ "$status" == "Paused" ]; then - echo "🎵 $truncated_title [$truncated_artist] (Paused)" + echo "󰝚 $truncated_title [$truncated_artist] (Paused)" else - echo "🎵 $truncated_title [$truncated_artist]" + echo "󰝚 $truncated_title [$truncated_artist]" fi elif [ "$active_count" -gt 1 ]; then @@ -126,12 +126,12 @@ elif [ "$active_count" -gt 1 ]; then if [ "$title" == "Vilos" ]; then title=$(playerctl -p "$brave" metadata --format '{{title}}') truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH + $MAX_ARTIST_LENGTH))) - output+="🎵 $truncated_title" + output+="󰝚 $truncated_title" else artist=$(playerctl -p "$player" metadata --format '{{artist}}') truncated_title=$(truncate_string "$title" $MAX_TITLE_LENGTH) truncated_artist=$(truncate_string "$artist" $MAX_ARTIST_LENGTH) - output+="🎵 $truncated_title [$truncated_artist]" + output+="󰝚 $truncated_title [$truncated_artist]" fi if [ "$verbose" -eq 1 ]; then echo "Player $player: $title - $artist" @@ -173,16 +173,16 @@ elif [ "$active_count" -gt 1 ]; then truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH + $MAX_ARTIST_LENGTH))) if [ "$brave_status" == "Playing" ]; then - echo "🎵 $truncated_title" + echo "󰝚 $truncated_title" else - echo "🎵 $truncated_title (Paused)" + echo "󰝚 $truncated_title (Paused)" fi exit 0 fi truncated_title=$(truncate_string "$title" $MAX_TITLE_LENGTH) truncated_artist=$(truncate_string "$artist" $MAX_ARTIST_LENGTH) - output="🎵 $truncated_title [$truncated_artist]" + output="󰝚 $truncated_title [$truncated_artist]" if [ "$brave_status" == "Playing" ]; then echo "$output" else @@ -199,8 +199,8 @@ else fi brave_status=$(playerctl -p "$brave" status 2>/dev/null) - title=$(playerctl -p "$brave" metadata --format '{{title}}') - artist=$(playerctl -p "$brave" metadata --format '{{artist}}') + title=$(playerctl -p "$brave" metadata --format '{{title}}' 2>/dev/null) + artist=$(playerctl -p "$brave" metadata --format '{{artist}}' 2>/dev/null) # Print the title and artist if [ "$verbose" -eq 1 ]; then echo "Brave is playing" @@ -211,21 +211,25 @@ else # Check if artist is empty if [ -z "$artist" ]; then if [ -z "$title" ]; then + if [ "$verbose" -eq 1 ]; then + echo "No metadata found" + fi + echo "" exit 0 fi truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH + $MAX_ARTIST_LENGTH))) if [ "$brave_status" == "Playing" ]; then - echo "🎵 $truncated_title" + echo "󰝚 $truncated_title" else - echo "🎵 $truncated_title (Paused)" + echo "󰝚 $truncated_title (Paused)" fi exit 0 fi truncated_title=$(truncate_string "$title" $MAX_TITLE_LENGTH) truncated_artist=$(truncate_string "$artist" $MAX_ARTIST_LENGTH) - output="🎵 $truncated_title [$truncated_artist]" + output="󰝚 $truncated_title [$truncated_artist]" if [ "$brave_status" == "Playing" ]; then echo "$output" else diff --git a/storage.sh b/storage.sh new file mode 100755 index 0000000..2862b64 --- /dev/null +++ b/storage.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Storage locations to check +locations=( + "/home/nathan" + "/home/nathan/Nextcloud" +) + +icons=( + "󰋜" + "" +) + +# Check for first arg +if [ -z "$1" ]; then + RED='\033[0;31m' + GREEN='\033[0;32m' + YELLOW='\033[0;33m' + BLUE='\033[0;34m' + NC='\033[0m' # No Color + + # Check if storage is full + for i in "${!locations[@]}"; do + # Check if the location exists + location=${locations[$i]} + if [ -d "$location" ]; then + # Get icon for location + icon=${icons[$i]} + + # Get the current usage + size=$(du -hs "$location" | awk '{print $1}') + echo -en "${YELLOW}${icon} ${NC}${size} " + + fi + done + echo "" + +else + RED='%{F#ff0000}' + GREEN='%{F#ff60d090}' + YELLOW='%{F#F0C674}' + BLUE='%{F#0000ff}' + NC='%{F-}' + + # Check if storage is full + for i in "${!locations[@]}"; do + # Check if the location exists + location=${locations[$i]} + if [ -d "$location" ]; then + # Get icon for location + icon=${icons[$i]} + + # Get the current usage (discard error output) + size=$(du -hs "$location" 2>/dev/null | awk '{print $1}') + echo -en "%{A1:/home/nathan/scripts/zellij.sh --cwd $location zsh:}${YELLOW}${icon} ${NC}${size}%{A} " + fi + done + echo "" +fi diff --git a/zellij.sh b/zellij.sh new file mode 100755 index 0000000..27971d5 --- /dev/null +++ b/zellij.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Check if focus on zellig window worked wmctrl -a zellij +if [ -z "$(wmctrl -l | grep Zellij)" ]; then + echo "No terminal running" > /tmp/message + polybar-msg action message hook 0 +else + wmctrl -a Zellij +fi + +# Get arguments and run in new zellij pane +if [ "$#" -ne 0 ]; +then + # Check if --cwd flag is passed + if [ "$1" == "--cwd" ]; + then + zellij run -fc --cwd "$2" -- "${@:3}" + else + zellij run -fc -- "$@" + fi +else + echo "Usage: zelij.sh " +fi \ No newline at end of file