add --or flag
This commit is contained in:
parent
200f36f937
commit
b0f96db530
2 changed files with 24 additions and 14 deletions
12
README.org
12
README.org
|
|
@ -23,8 +23,11 @@
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Every argument which is not assigned to a flag is interpreted as part of the query.
|
Every argument which is not assigned to a flag is interpreted as part of the query.
|
||||||
The query arguments are then surrounded by wildcards (=*=) and the case gets ignored.
|
The query arguments are interpreted as [[https://en.wikipedia.org/wiki/Glob_(programming)][glob patterns]], additionally surrounded by wildcards (=*=).
|
||||||
If every argument matches any filepath in the configured media directories, the matched filepaths are interpreted as result.
|
If every pattern matches any filepath in the configured media directories, the matched filepaths are interpreted as result.
|
||||||
|
The =--or= flag can be set to get results which match at least one pattern.
|
||||||
|
Matchings are always done case-insensitive.
|
||||||
|
|
||||||
The shortfilm from the example above could have also been played with one of the following commands:
|
The shortfilm from the example above could have also been played with one of the following commands:
|
||||||
|
|
||||||
#+begin_src sh
|
#+begin_src sh
|
||||||
|
|
@ -76,15 +79,16 @@
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
-c, --config CONFIG_FILE Path to config file
|
-c, --config CONFIG_FILE Path to config file (default: ~/.config/strm/strm.config)
|
||||||
-l, --list List files instead of playing
|
-l, --list List files instead of playing
|
||||||
-m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored
|
-m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored
|
||||||
|
-o, --or Use a logical OR for queries (default: AND)
|
||||||
-s, --shuffle Play files in random order
|
-s, --shuffle Play files in random order
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
strm -l . # List all available files
|
strm -l . # List all available files
|
||||||
strm Elephants Dream # Play files whose path contain 'elephants' and 'dream'
|
strm Elephants Dream # Play files whose path contain 'elephants' and 'dream'
|
||||||
strm e*phants # Play files whose path matches the wildcard 'e*phants'
|
strm e*phants # Play files whose path matches the glob pattern 'e*phants'
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
The usual [[https://mpv.io/manual/master/#interactive-control][mpv controls]] are available while playback.
|
The usual [[https://mpv.io/manual/master/#interactive-control][mpv controls]] are available while playback.
|
||||||
|
|
|
||||||
26
strm
26
strm
|
|
@ -11,15 +11,16 @@ function print_usage {
|
||||||
echo
|
echo
|
||||||
echo "OPTIONS"
|
echo "OPTIONS"
|
||||||
echo " -h, --help Show this help message"
|
echo " -h, --help Show this help message"
|
||||||
echo " -c, --config CONFIG_FILE Path to config file"
|
echo " -c, --config CONFIG_FILE Path to config file (default: ~/.config/strm/strm.config)"
|
||||||
echo " -l, --list List files instead of playing"
|
echo " -l, --list List files instead of playing"
|
||||||
echo " -m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored"
|
echo " -m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored"
|
||||||
|
echo " -o, --or Use a logical OR for queries (default: AND)"
|
||||||
echo " -s, --shuffle Play files in random order"
|
echo " -s, --shuffle Play files in random order"
|
||||||
echo
|
echo
|
||||||
echo "EXAMPLES"
|
echo "EXAMPLES"
|
||||||
echo " strm -l . # List all available files"
|
echo " strm -l . # List all available files"
|
||||||
echo " strm Elephants Dream # Play files whose path contain 'elephants' and 'dream'"
|
echo " strm Elephants Dream # Play files whose path contain 'elephants' and 'dream'"
|
||||||
echo " strm e*phants # Play files whose path matches the wildcard 'e*phants'"
|
echo " strm e*phants # Play files whose path matches the glob pattern 'e*phants'"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,6 +42,7 @@ fi
|
||||||
# Set default values
|
# Set default values
|
||||||
config="$HOME/.config/strm/strm.config"
|
config="$HOME/.config/strm/strm.config"
|
||||||
list=false
|
list=false
|
||||||
|
or=false
|
||||||
shuffle=false
|
shuffle=false
|
||||||
query=()
|
query=()
|
||||||
media_directories=""
|
media_directories=""
|
||||||
|
|
@ -71,6 +73,10 @@ while (( "$#" )); do
|
||||||
error "Argument for $1 is missing"
|
error "Argument for $1 is missing"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
-o|--or)
|
||||||
|
or=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-s|--shuffle)
|
-s|--shuffle)
|
||||||
shuffle=true
|
shuffle=true
|
||||||
shift
|
shift
|
||||||
|
|
@ -113,17 +119,17 @@ media_directories=${media_directories//[[:blank:]]/}
|
||||||
IFS="," read -a media_directories <<< "$media_directories"
|
IFS="," read -a media_directories <<< "$media_directories"
|
||||||
|
|
||||||
# Construct find argument array
|
# Construct find argument array
|
||||||
find_arguments=()
|
# Ignore hidden files and directories and list only files and symlinks
|
||||||
|
find_arguments=("-not" "-path" "'*/\.*'" "-type" "f,l")
|
||||||
for i in "${!query[@]}"; do
|
for i in "${!query[@]}"; do
|
||||||
|
|
||||||
# If more than one query is given add a logical AND
|
# If -o flag is set and more than one query is given, add a logical OR
|
||||||
if [ "$i" -ge 1 ]; then
|
if [ "$or" == true ] && [ "$i" -ge 1 ]; then
|
||||||
find_arguments+=("-a")
|
find_arguments+=("-o" "-not" "-path" "'*/\.*'" "-type" "f,l")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use the ipath argument to search case-insensitive
|
# Use the ipath argument to search case-insensitive and surround query with wildcards
|
||||||
find_arguments+=("-ipath")
|
find_arguments+=("-ipath" "'*${query[$i]}*'")
|
||||||
find_arguments+=("'*${query[$i]}*'")
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Initialize result arrays
|
# Initialize result arrays
|
||||||
|
|
@ -147,7 +153,7 @@ for media_directory in "${media_directories[@]}"; do
|
||||||
|
|
||||||
# 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 tmp_results < <(ssh -o ConnectTimeout=10 "$connection_string" find "$directory" -not -path \"*/\.*\" -type l,f "${find_arguments[@]}" | sort)
|
mapfile -t tmp_results < <(ssh -o ConnectTimeout=10 "$connection_string" find "$directory" "${find_arguments[@]}" | sort)
|
||||||
|
|
||||||
# Build SFTP strings and printable strings
|
# Build SFTP strings and printable strings
|
||||||
for i in "${!tmp_results[@]}"; do
|
for i in "${!tmp_results[@]}"; do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue