summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmanyplayer78
1 files changed, 65 insertions, 13 deletions
diff --git a/manyplayer b/manyplayer
index 618b530..982f144 100755
--- a/manyplayer
+++ b/manyplayer
@@ -1,18 +1,24 @@
#!/bin/bash
-# This executable does nothing by itself. Setup links with:
+# This executable does little by itself. Setup links with:
# ln -s manyplayer next
# ln -s manyplayer same
-# ln -s manyplayer guessfile
-if [ "x${MANYPLAYER_DIR}" == "x" ] ; then
- MANYPLAYER_DIR=~/.manyplayer
+if [ "x${MANYPLAYER_BASE_DIR}" == "x" ] ; then
+ MANYPLAYER_BASE_DIR=~/.manyplayer
fi
+THIS_DIR=${PWD//\//_}
+MANYPLAYER_DIR=${MANYPLAYER_BASE_DIR}/${THIS_DIR}
+
exe=$(basename $0)
function check {
- if [ ! -f ${MANYPLAYER_DIR}/cmd ] ; then
+ if [ ! -d ${MANYPLAYER_DIR} ] ; then
+ echo "Manyplayer has not been set up for this directory (${MANYPLAYER_DIR})."
+ exit 1
+ fi
+ if [ ! -f ${MANYPLAYER_DIR}/cmd -a ! -f ${MANYPLAYER_BASE_DIR}/cmd ] ; then
echo "No command in manyplayer config (${MANYPLAYER_DIR}/cmd)."
exit 1
fi
@@ -27,7 +33,12 @@ function check {
}
function play_last_file {
- local comm=$(<${MANYPLAYER_DIR}/cmd)
+ if [ -f ${MANYPLAYER_DIR}/cmd ] ; then
+ local comm=$(<${MANYPLAYER_DIR}/cmd)
+ else
+ echo "INFO === Manyplayer using default command"
+ local comm=$(<${MANYPLAYER_BASE_DIR}/cmd)
+ fi
local this=$(<${MANYPLAYER_DIR}/last)
local filename=$(<${MANYPLAYER_DIR}/filename)
exec $comm "${filename/!/$this}"
@@ -40,7 +51,7 @@ function play_next_file {
play_last_file
}
-function guess_filename {
+function setup {
local guess=$(echo *$1*)
local name=${guess/$1/!}
echo -n $name > ${MANYPLAYER_DIR}/filename
@@ -52,18 +63,59 @@ function guess_filename {
fi
}
+function set_cmd {
+ echo -n $1 > ${MANYPLAYER_DIR}/cmd
+}
+
+function set_position {
+ echo -n $1 > ${MANYPLAYER_DIR}/last
+}
+
+function usage {
+cat <<EOT
+Manyplayer version 0.5
+Usage:
+ next Watch next episode
+ same Watch the last episode again
+ manyplayer setup <guess> Setup manyplayer for this directory
+ manyplayer cmd <cmd> Set the command for this directory
+ manyplayer pos <pos> Set the position for this directory
+ manyplayer help Show this pretty useless help
+EOT
+}
+
if [ "x$exe" == "xnext" ] ; then
check
play_next_file
elif [ "x$exe" == "xsame" ] ; then
check
play_last_file
-elif [ "x$exe" == "xguessfile" ] ; then
- if [ "x$1" == "x" ] ; then
- echo "Need a guess statement, try '01'."
- exit 1
- else
- guess_filename $1 $2
+elif [ "x$exe" == "xmanyplayer" ] ; then
+ if [ "x$1" == "xsetup" ] ; then
+ if [ "x$2" == "x" ] ; then
+ echo "Need a guess statement, try '01'."
+ exit 1
+ else
+ setup $2 $3
+ fi
+ elif [ "x$1" == "xcmd" ] ; then
+ check
+ if [ "x$2" == "x" ] ; then
+ echo "Need a command statement, try 'mplayer'."
+ exit 1
+ else
+ set_cmd $2
+ fi
+ elif [ "x$1" == "xpos" ] ; then
+ check
+ if [ "x$2" == "x" ] ; then
+ echo "Need a last position statement, try '01'."
+ exit 1
+ else
+ set_position $2
+ fi
+ elif [ "x$1" == "xhelp" ] ; then
+ usage
fi
else
echo "'$exe' doesn't look like a manyplayer command..."