fix argument parsing
This commit is contained in:
parent
a2a2973fdb
commit
496a7ff8f3
1 changed files with 15 additions and 13 deletions
24
strm
24
strm
|
|
@ -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)
|
||||||
|
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
|
||||||
config="$2"
|
config="$2"
|
||||||
shift
|
shift 2
|
||||||
shift
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue