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
|
||||
|
||||
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.
|
||||
If every argument matches any filepath in the configured media directories, the matched filepaths are interpreted as result.
|
||||
The query arguments are interpreted as [[https://en.wikipedia.org/wiki/Glob_(programming)][glob patterns]], additionally surrounded by wildcards (=*=).
|
||||
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:
|
||||
|
||||
#+begin_src sh
|
||||
|
|
@ -76,15 +79,16 @@
|
|||
|
||||
OPTIONS
|
||||
-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
|
||||
-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
|
||||
|
||||
EXAMPLES
|
||||
strm -l . # List all available files
|
||||
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
|
||||
|
||||
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 "OPTIONS"
|
||||
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 " -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
|
||||
echo "EXAMPLES"
|
||||
echo " strm -l . # List all available files"
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +42,7 @@ fi
|
|||
# Set default values
|
||||
config="$HOME/.config/strm/strm.config"
|
||||
list=false
|
||||
or=false
|
||||
shuffle=false
|
||||
query=()
|
||||
media_directories=""
|
||||
|
|
@ -71,6 +73,10 @@ while (( "$#" )); do
|
|||
error "Argument for $1 is missing"
|
||||
fi
|
||||
;;
|
||||
-o|--or)
|
||||
or=true
|
||||
shift
|
||||
;;
|
||||
-s|--shuffle)
|
||||
shuffle=true
|
||||
shift
|
||||
|
|
@ -113,17 +119,17 @@ media_directories=${media_directories//[[:blank:]]/}
|
|||
IFS="," read -a media_directories <<< "$media_directories"
|
||||
|
||||
# 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
|
||||
|
||||
# If more than one query is given add a logical AND
|
||||
if [ "$i" -ge 1 ]; then
|
||||
find_arguments+=("-a")
|
||||
# If -o flag is set and more than one query is given, add a logical OR
|
||||
if [ "$or" == true ] && [ "$i" -ge 1 ]; then
|
||||
find_arguments+=("-o" "-not" "-path" "'*/\.*'" "-type" "f,l")
|
||||
fi
|
||||
|
||||
# Use the ipath argument to search case-insensitive
|
||||
find_arguments+=("-ipath")
|
||||
find_arguments+=("'*${query[$i]}*'")
|
||||
# Use the ipath argument to search case-insensitive and surround query with wildcards
|
||||
find_arguments+=("-ipath" "'*${query[$i]}*'")
|
||||
done
|
||||
|
||||
# Initialize result arrays
|
||||
|
|
@ -147,7 +153,7 @@ for media_directory in "${media_directories[@]}"; do
|
|||
|
||||
# Get search results from remote
|
||||
# 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
|
||||
for i in "${!tmp_results[@]}"; do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue