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

View File

@ -9,18 +9,25 @@ verbose=0
# Check if any argument is passed # Check if any argument is passed
if [ "$#" -ne 0 ]; then if [ "$#" -ne 0 ]; then
arg="$1" arg="$1"
if [ "$arg" == "play" ]; then if [ "$arg" == "p" ]; then
playerctl play-pause
exit 0
elif [ "$arg" == "play" ]; then
playerctl play playerctl play
exit 0
elif [ "$arg" == "pause" ]; then elif [ "$arg" == "pause" ]; then
playerctl pause playerctl pause
exit 0
elif [ "$arg" == "next" ]; then elif [ "$arg" == "next" ]; then
playerctl next playerctl next
exit 0
elif [ "$arg" == "prev" ]; then elif [ "$arg" == "prev" ]; then
playerctl previous playerctl previous
exit 0
elif [ "$arg" == "verbose" ]; then elif [ "$arg" == "verbose" ]; then
verbose=1 verbose=1
else 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 exit 0
fi fi
if [ "$#" -eq 2 ]; then if [ "$#" -eq 2 ]; then
@ -30,7 +37,6 @@ if [ "$#" -ne 0 ]; then
fi fi
fi fi
# Check if playerctl is available # 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." echo "playerctl is not installed. Please install it to use this script."
@ -47,8 +53,10 @@ for player in $players; do
status=$(playerctl -p "$player" status 2>/dev/null) status=$(playerctl -p "$player" status 2>/dev/null)
# Check if player name contains brave # Check if player name contains brave
if [[ "$player" == *"brave"* ]]; then if [[ "$player" == *"brave"* ]]; then
if [ "$verbose" -eq 1 ]; then
echo "Brave found"
fi
brave=$player brave=$player
continue
fi fi
if [[ "$status" == "Playing" || "$status" == "Paused" ]]; then if [[ "$status" == "Playing" || "$status" == "Paused" ]]; then
@ -115,11 +123,13 @@ elif [ "$active_count" -gt 1 ]; then
truncated_artist=$(truncate_string "$artist" $MAX_ARTIST_LENGTH) truncated_artist=$(truncate_string "$artist" $MAX_ARTIST_LENGTH)
output+="🎵 $truncated_title [$truncated_artist]" output+="🎵 $truncated_title [$truncated_artist]"
fi fi
fi fi
done done
if [ "$playing_count" -eq 1 ]; then if [ "$playing_count" -eq 1 ]; then
echo "$output" echo "$output"
else else
if [ -z "$brave" ]; then
echo "Multiple players playing" echo "Multiple players playing"
if [ "$verbose" -eq 1 ]; then if [ "$verbose" -eq 1 ]; then
for player in "${active_players[@]}"; do for player in "${active_players[@]}"; do
@ -130,6 +140,77 @@ elif [ "$active_count" -gt 1 ]; then
echo "Status: $status" echo "Status: $status"
done done
fi 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 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