aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/sway/.local/bin/sway-mpv
diff options
context:
space:
mode:
Diffstat (limited to 'sway/.local/bin/sway-mpv')
-rwxr-xr-xsway/.local/bin/sway-mpv16
1 files changed, 12 insertions, 4 deletions
diff --git a/sway/.local/bin/sway-mpv b/sway/.local/bin/sway-mpv
index 67ec133..a586cb0 100755
--- a/sway/.local/bin/sway-mpv
+++ b/sway/.local/bin/sway-mpv
@@ -1,14 +1,22 @@
#!/bin/sh
+# shellcheck disable=SC2011,SC2012,SC2016
if [ ! -t 0 ]; then
set -- "$@" "$(cat)"
elif [ $# -eq 0 ]; then
- grep -Po '# title: \K.*' "$XDG_STATE_HOME"/mpv/watch_later/* | while IFS=: read -r file match; do
- grep -Pom1 '# \K.*' "$file" | tr -d '\n'
- printf ': %s\n' "$match"
+ ls -t -1 "$XDG_STATE_HOME"/mpv/watch_later/* | while read -r file; do
+ awk -f - "$file" <<-"EOF"
+ NR == 1 && /^# / && !/^# redirect entry/ { url = $0 }
+ END {
+ if (NR > 1 && sub(/^# /, "", url) && sub(/^# title: /, "")) {
+ printf "%s: %s\n", url, $0
+ }
+ }
+ EOF
done
+
exit 0
fi
# shellcheck disable=SC2068
-swaymsg exec -- mpv --msg-level=all=no "${1%*:*}"
+swaymsg exec -- mpv --msg-level=all=no "${1%: *}"