feat: Add new scripts

This commit is contained in:
Nathan Woodburn 2024-10-14 12:04:47 +11:00
parent c7ee0658a7
commit 4b46755c22
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
7 changed files with 178 additions and 21 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
powertop/
libtracefs/
libtraceevent/

0
copy → copy.sh Normal file → Executable file
View File

123
music.sh
View File

@ -9,30 +9,36 @@ verbose=0
# Check if any argument is passed
if [ "$#" -ne 0 ]; then
arg="$1"
if [ "$arg" == "play" ]; then
if [ "$arg" == "p" ]; then
playerctl play-pause
exit 0
elif [ "$arg" == "play" ]; then
playerctl play
exit 0
elif [ "$arg" == "pause" ]; then
playerctl pause
exit 0
elif [ "$arg" == "next" ]; then
playerctl next
exit 0
elif [ "$arg" == "prev" ]; then
playerctl previous
exit 0
elif [ "$arg" == "verbose" ]; then
verbose=1
else
echo "Invalid argument. Please use one of the following: play, pause, next, prev"
echo "Invalid argument. Please use one of the following: p (play/pause), play, pause, next, prev"
exit 0
fi
if [ "$#" -eq 2 ]; then
if [ "$2" == "verbose" ]; then
verbose=1
fi
fi
fi
fi
# Check if playerctl is available
if ! command -v playerctl &> /dev/null; then
if ! command -v playerctl &>/dev/null; then
echo "playerctl is not installed. Please install it to use this script."
exit 1
fi
@ -47,8 +53,10 @@ for player in $players; do
status=$(playerctl -p "$player" status 2>/dev/null)
# Check if player name contains brave
if [[ "$player" == *"brave"* ]]; then
if [ "$verbose" -eq 1 ]; then
echo "Brave found"
fi
brave=$player
continue
fi
if [[ "$status" == "Playing" || "$status" == "Paused" ]]; then
@ -72,12 +80,12 @@ active_count=${#active_players[@]}
if [ "$active_count" -eq 1 ]; then
# If exactly one player is active, print its metadata
IFS=":" read -r player status <<< "${active_players[0]}"
IFS=":" read -r player status <<<"${active_players[0]}"
title=$(playerctl -p "$player" metadata --format '{{title}}')
# If title == Vilos Player, get the title from the brave player
if [ "$title" == "Vilos" ]; then
title=$(playerctl -p "$brave" metadata --format '{{title}}')
truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH+$MAX_ARTIST_LENGTH)))
truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH + $MAX_ARTIST_LENGTH)))
if [ "$status" == "Paused" ]; then
echo "🎵 $truncated_title (Paused)"
else
@ -94,20 +102,20 @@ if [ "$active_count" -eq 1 ]; then
else
echo "🎵 $truncated_title [$truncated_artist]"
fi
elif [ "$active_count" -gt 1 ]; then
# Count to see how many playing players there are
playing_count=0
output=""
for player in "${active_players[@]}"; do
IFS=":" read -r player status <<< "$player"
IFS=":" read -r player status <<<"$player"
if [ "$status" == "Playing" ]; then
playing_count=$((playing_count + 1))
title=$(playerctl -p "$player" metadata --format '{{title}}')
if [ "$title" == "Vilos" ]; then
title=$(playerctl -p "$brave" metadata --format '{{title}}')
truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH+$MAX_ARTIST_LENGTH)))
truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH + $MAX_ARTIST_LENGTH)))
output+="🎵 $truncated_title"
else
artist=$(playerctl -p "$player" metadata --format '{{artist}}')
@ -115,21 +123,94 @@ elif [ "$active_count" -gt 1 ]; then
truncated_artist=$(truncate_string "$artist" $MAX_ARTIST_LENGTH)
output+="🎵 $truncated_title [$truncated_artist]"
fi
fi
done
if [ "$playing_count" -eq 1 ]; then
echo "$output"
else
echo "Multiple players playing"
if [ "$verbose" -eq 1 ]; then
for player in "${active_players[@]}"; do
IFS=":" read -r player status <<< "$player"
title=$(playerctl -p "$player" metadata --format '{{title}}')
artist=$(playerctl -p "$player" metadata --format '{{artist}}')
echo "$player: $title - $artist"
echo "Status: $status"
done
if [ -z "$brave" ]; then
echo "Multiple players playing"
if [ "$verbose" -eq 1 ]; then
for player in "${active_players[@]}"; do
IFS=":" read -r player status <<<"$player"
title=$(playerctl -p "$player" metadata --format '{{title}}')
artist=$(playerctl -p "$player" metadata --format '{{artist}}')
echo "$player: $title - $artist"
echo "Status: $status"
done
fi
else
brave_status=$(playerctl -p "$brave" status 2>/dev/null)
title=$(playerctl -p "$brave" metadata --format '{{title}}')
artist=$(playerctl -p "$brave" metadata --format '{{artist}}')
# Print the title and artist
if [ "$verbose" -eq 1 ]; then
echo "Brave is playing"
echo "Title: $title"
echo "Artist: $artist"
fi
# Check if artist is empty
if [ -z "$artist" ]; then
truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH + $MAX_ARTIST_LENGTH)))
if [ "$brave_status" == "Playing" ]; then
echo "🎵 $truncated_title"
else
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]"
if [ "$brave_status" == "Playing" ]; then
echo "$output"
else
echo "$output (Paused)"
fi
fi
fi
else
# Check if brave is not empty
if [ -z "$brave" ]; then
exit 0
fi
brave_status=$(playerctl -p "$brave" status 2>/dev/null)
title=$(playerctl -p "$brave" metadata --format '{{title}}')
artist=$(playerctl -p "$brave" metadata --format '{{artist}}')
# Print the title and artist
if [ "$verbose" -eq 1 ]; then
echo "Brave is playing"
echo "Title: $title"
echo "Artist: $artist"
fi
# Check if artist is empty
if [ -z "$artist" ]; then
if [ -z "$title" ]; then
exit 0
fi
truncated_title=$(truncate_string "$title" $(($MAX_TITLE_LENGTH + $MAX_ARTIST_LENGTH)))
if [ "$brave_status" == "Playing" ]; then
echo "🎵 $truncated_title"
else
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]"
if [ "$brave_status" == "Playing" ]; then
echo "$output"
else
echo "$output (Paused)"
fi
fi

4
mute.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# Mute the sound
amixer set Master mute

36
ts.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
# Usage: ts [list|en|en {node}]
# List: Lists all nodes
# EN: Exit node (clear)
# EN {node}: Use node
if [ "$#" -eq 0 ]; then
echo "Usage: ts [list|en|en {node}]"
echo "List: Lists all nodes"
echo "EN: Exit node (clear)"
echo "EN {node}: Use node"
exit 1
fi
if [ "$1" = "list" ]; then
tailscale status
exit 0
fi
if [ "$1" = "en" ]; then
if [ "$#" -eq 1 ]; then
echo "Clearing exit node"
tailscale set --exit-node=
exit 0
fi
echo "Enabling node $2"
tailscale set --exit-node="$2"
exit 0
fi
echo "Usage: ts [list|en|en {node}]"
echo "List: Lists all nodes"
echo "EN: Exit node (clear)"
echo "EN {node}: Use node"
exit 1

0
upload → upload.sh Normal file → Executable file
View File

33
venv.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# This script is used to create a virtual environment for the project
# Check if the virtual environment already exists
if [ -d ".venv" ]; then
# Check if arg exit passed
if [ "$1" = "exit" ]; then
echo "Exiting virtual environment"
deactivate
else
# Check if the virtual environment is active
if [ -n "$VIRTUAL_ENV" ]; then
echo "Virtual environment is active"
else
echo "Activating existing virtual environment"
source .venv/bin/activate
fi
fi
else
# Create the virtual environment
python3 -m venv .venv
# Activate the virtual environment
source .venv/bin/activate
# Install the required packages
if [ -f "requirements.txt" ]; then
echo "Installing required packages"
python3 -m pip install -r requirements.txt
fi
fi