Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions hooks/_run_all.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# hooks/_run_all.sh
#!/usr/bin/env bash

# Ensure tput has something to work with
export TERM=${TERM:-dumb}

# Script Name: _run_all.sh
# Description: This script will check all scripts in the specified paths.
# It finds all the scripts (not starting with _) in the 'hooks' directory and executes them with '--check' option.
Expand All @@ -12,22 +16,22 @@ paths=(src)
# Status variable to track if any check fails
status=0

# Define color codes
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
# Define color codes (now safe because TERM is set)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
RESET=$(tput sgr0)

# Process each path
for path in "${paths[@]}"; do
# Find all scripts (not starting with _) in 'hooks' directory
for script in $(find hooks -type l -name "[^_]*.sh"); do
echo -e "\nExecuting "$script""
find hooks -type l -name "[^_]*.sh" | while read -r script; do
echo -e "\nExecuting $script"

# Execute the script with '--check' option
if "$script" --check "$path"; then
echo "${GREEN}$script check on $path was successful${RESET}"
else
echo "${RED}$script check on $path failed${RESET}"
echo "${GREEN}${script} check on ${path} was successful${RESET}"
else
echo "${RED}${script} check on ${path} failed${RESET}"
status=1
fi
done
Expand All @@ -37,4 +41,3 @@ done
if [[ $status -eq 1 ]]; then
exit 1
fi

87 changes: 44 additions & 43 deletions src/adjust_volume.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

# Script Name: adjust_volume.sh
# Description: Adjusts the volume for all available PulseAudio sinks.
# The adjustment can be a percentage increase or decrease (e.g., +5%, -10%)
# Description: Adjusts the volume for all available PulseAudio sinks.
# The adjustment can be a percentage increase or decrease (e.g., +5%, -10%)
# or a predefined mode (e.g., "full", "mute", "unmute", "reset").
# Usage: ./adjust_volume.sh -v [VALUE]
# ./adjust_volume.sh -h
Expand All @@ -16,69 +16,70 @@ VALID_STRINGS=("full" "mute" "unmute" "reset")

# Function to display help/usage information
display_help() {
echo "Usage: $0 [OPTION] [VALUE]"
echo
echo "Options:"
echo " -v [VALUE] Adjust volume by a specific amount (e.g., +5%, -10%) or set to a specific mode"
echo " Valid modes: ${VALID_STRINGS[*]}"
echo " -h Display this help message and exit"
echo
exit 0
echo "Usage: $0 [OPTION] [VALUE]"
echo
echo "Options:"
echo " -v [VALUE] Adjust volume by a specific amount (e.g., +5%, -10%) or set to a specific mode"
echo " Valid modes: ${VALID_STRINGS[*]}"
echo " -h Display this help message and exit"
echo
exit 0
}

# Function to validate volume adjustment input
validate_input() {
local input="$1"
local input="$1"

# Check if input is a valid string from the list
for str in "${VALID_STRINGS[@]}"; do
if [[ "$input" == "$str" ]]; then
return 0
fi
done
# Check if input is a valid string from the list
for str in "${VALID_STRINGS[@]}"; do
if [[ "$input" == "$str" ]]; then
return 0
fi
done

# Check if input is a number with + or - and within the range of -100 to +100
if [[ "$input" =~ ^[+-]?[0-9]+%?$ ]]; then
local value="${input%?}" # Remove % if present
if ((value >= -100 && value <= 100)); then
return 0
# Check if input is a number with + or - and within the range of -100 to +100
if [[ "$input" =~ ^[+-]?[0-9]+%?$ ]]; then
local value="${input%?}" # Remove % if present
if ((value >= -100 && value <= 100)); then
return 0
fi
fi
fi

return 1
return 1
}

# Parse command-line arguments
while getopts ":v:h" opt; do
case ${opt} in
v)
input_value="$OPTARG"
;;
h)
display_help
;;
\?)
echo "Invalid option: -$OPTARG" >&2
display_help
;;
:)
echo "Option -$OPTARG requires an argument." >&2
display_help
;;
esac
case ${opt} in
v)
input_value="$OPTARG"
;;
h)
display_help
;;
\?)
echo "Invalid option: -$OPTARG" >&2
display_help
;;
:)
echo "Option -$OPTARG requires an argument." >&2
display_help
;;
esac
done

# Validate the input
if ! validate_input "$input_value"; then
echo "Invalid input: '$input_value'. Use -h for help." >&2
exit 1
echo "Invalid input: '$input_value'. Use -h for help." >&2
exit 1
fi

# Apply the volume adjustment to all sinks
for sink in $(pactl list short sinks | cut -f1); do
pactl set-sink-volume "$sink" "$input_value"
pactl set-sink-volume "$sink" "$input_value"
done

echo "Volume adjusted by $input_value for all sinks."

exit 0

1 change: 1 addition & 0 deletions src/alias_all_the_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ main() {
}

main "$@"

Loading