diff --git a/scripts/dm-eq-profiles b/scripts/dm-eq-profiles new file mode 100755 index 0000000000000000000000000000000000000000..9cc108721a47115bc0ba7467b5706c8116a1f482 --- /dev/null +++ b/scripts/dm-eq-profiles @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# +# Script name: dm-eq-profiles +# Description: A dmenu script allowing you to switch between predefined equalizer profiles easily. +# Dependencies: dmenu, easyeffects +# GitLab: https://www.gitlab.com/dwt1/dmscripts +# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE +# Contributors: Allen (aaw3_) + +# Note: Avoid using commas in preset names otherwise it will cause errors when trying to parse the presets list + +# Set with the flags "-e", "-u","-o pipefail" cause the script to fail +# if certain things happen, which is a good thing. Otherwise, we can +# get hidden bugs that are hard to discover. +set -euo pipefail + +_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo ".")")" && pwd)" +if [[ -f "${_path}/_dm-helper.sh" ]]; then + # shellcheck disable=SC1090,SC1091 + source "${_path}/_dm-helper.sh" +else + shellcheck disable=SC1090 + echo "No helper-script found" +fi + +# script will not hit this if there is no config-file to load +# shellcheck disable=SC1090 +source "$(get_config)" + +main() { + # shellcheck disable=SC2154 + + #Retrieve profiles form easyeffects + AllProfiles=$(easyeffects -p) + + #Separate profiles + OutputProfiles=$(echo "${AllProfiles}" | head -1) + InputProfiles=$(echo "${AllProfiles}" | tail -1) + + #Trim the beginning of I/O profiles + OutputProfiles="${OutputProfiles:16}" + InputProfiles="${InputProfiles:15}" + + IFS=',' read -r -a OutputArray <<< "${OutputProfiles}" + IFS=',' read -r -a InputArray <<< "${InputProfiles}" + + declare -a eq_profiles + + for element in "${OutputArray[@]}" + do + eq_profiles+=( "O: ${element}" ) + done + + for element in "${InputArray[@]}" + do + eq_profiles+=( "I: ${element}" ) + done + + eq_profiles+=( "Quit" ) + + #echo $OutputProfiles + #echo $InputProfiles + + + _profile=$(printf '%s\n' "${eq_profiles[@]}" | ${DMENU} "Choose a profile:" "$@") || exit 1 + + if [[ $_profile == "Quit" ]]; then echo "Program Terminated" && exit 0; fi + + easyeffects -l "${_profile:3}" +} + +[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main "$@"