Forked from professorjamesmoriarty/songlengthtest.sh
Last active
February 6, 2025 18:31
-
-
Save bonelifer/b48b0417b9f60440d9659c2c69386401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# AUTHOR: bonelifer | |
# FILE: songlengthtest.sh | |
# ROLE: Display the current song title with length constraints for better readability. | |
# BASED ON: https://gist.github.com/professorjamesmoriarty/2d4fcea1f587750b7bfc | |
# CREATED: 2015-09-27 06:31:51 | |
# MODIFIED: 2025-02-06 | |
# Function to display the currently playing song's title. | |
mus() { | |
# Fetch the current song details from `mpc` and store in a variable to avoid redundant calls. | |
current_song=$(mpc current -f "[[%artist% - ]%title%]") | |
# Calculate the length of the song's title. | |
size=${#current_song} | |
# Define thresholds for title trimming. | |
local max_length=50 | |
local display_length=30 | |
# Check if the title length exceeds the display threshold. | |
if [ "$size" -gt "$display_length" ]; then | |
# Trim the title to the max allowed length and append '...'. | |
echo "${current_song:0:$max_length}..." | |
# echo "${current_song:0:$max_length}..." > currentsong.txt # Write to file instead of echoing | |
else | |
# Display the title as is. | |
echo "$current_song" | |
# echo "$current_song" > currentsong.txt # Write to file instead of echoing | |
fi | |
} | |
# Call the function to display the song title. | |
mus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment