fix argument parsing

This commit is contained in:
Denis Lehmann 2021-04-25 11:26:26 +02:00
parent a2a2973fdb
commit 496a7ff8f3

28
strm
View file

@ -19,7 +19,7 @@ function print_usage {
} }
# Check if mpv is installed # Check if mpv is installed
if ! command -v mpv &> /dev/null if ! command -v mpv &>/dev/null
then then
echo "mpv was not found, please install it" echo "mpv was not found, please install it"
exit 1 exit 1
@ -27,16 +27,21 @@ fi
# Set default values # Set default values
config="$HOME/.config/strm/strm.config" config="$HOME/.config/strm/strm.config"
list=false
shuffle=false shuffle=false
query=""
# Parse arguments # Parse arguments
list=false while (( "$#" )); do
for arg in "$@"; do case "$1" in
case $arg in
-c|--config) -c|--config)
config="$2" if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
shift config="$2"
shift shift 2
else
echo "Argument for $1 is missing"
exit 1
fi
;; ;;
-h|--help) -h|--help)
print_usage print_usage
@ -50,7 +55,7 @@ for arg in "$@"; do
shift shift
;; ;;
*) *)
query+=("$1") query="$query\*$1"
shift shift
;; ;;
esac esac
@ -82,16 +87,13 @@ if [ "$config_valid" == false ]; then
echo "Please check your config file ($config)" echo "Please check your config file ($config)"
exit 1 exit 1
fi fi
if [ "${#query[@]}" == 0 ]; then if [ "$query" == "" ]; then
print_usage print_usage
fi fi
# Build search string from input arguments
query="\*$( IFS=$'*'; echo "${query[*]}" )\*"
# Get search results from remote # Get search results from remote
# Look for paths matching given queries in visible directories, listing only filenames and links # Look for paths matching given queries in visible directories, listing only filenames and links
mapfile -t results < <(ssh "$connection_string" find "$media_directory" -not -path \"*/\.*\" -type l,f -ipath "$query" | sort) mapfile -t results < <(ssh "$connection_string" find "$media_directory" -not -path \"*/\.*\" -type l,f -ipath "$query\*" | sort)
# List files # List files
if [ "$list" == false ]; then if [ "$list" == false ]; then