From c2dafff6221e20d24cf38c57127843d6bd4da5e2 Mon Sep 17 00:00:00 2001 From: rabite Date: Mon, 1 Jul 2019 17:36:18 +0200 Subject: rename action adder --- extra/actions/Add Action?type?name!.sh | 84 ++++++++++++++++++++++++++++++ "extra/actions/Add\\ Action?type?name!.sh" | 84 ------------------------------ 2 files changed, 84 insertions(+), 84 deletions(-) create mode 100755 extra/actions/Add Action?type?name!.sh delete mode 100755 "extra/actions/Add\\ Action?type?name!.sh" diff --git a/extra/actions/Add Action?type?name!.sh b/extra/actions/Add Action?type?name!.sh new file mode 100755 index 0000000..6a322bc --- /dev/null +++ b/extra/actions/Add Action?type?name!.sh @@ -0,0 +1,84 @@ +#!/bin/sh + + +errecho() { + echo ${@} >&2 +} + +check_dir() { + DIR=${1} + + [ -d ${DIR} ] || + mkdir -p ${DIR} || + (echo "Can't create directory: ${DIR}" && exit 1) +} + +populate_file() { + FILE=${1} + + # Don't try to overwrite existing file + test -e ${FILE} && return + + + + cat > ${FILE} << EOF +#!/bin/sh + +# Selected files are stored here +FILES=\${@} + +# You can interate over them one by one +for FILE in \${FILES}; do + echo \$FILE +done + +# Or process them all at once +echo "\${FILES}" +EOF +} + + +## Starting point + +FILE=${1} +MIME=`hunter -m $FILE` +STATUS=$? + + +# MIME detection failed, bail out unless type is base +[ $STATUS != 0 ] && [ $type != "uni" ] && + echo $MIME && + exit 1 + +# Laziy not using XGD here because of OSX +ACTDIR="$HOME/.config/hunter/actions/" + +MIME_BASE=`echo $MIME | cut -d "/" -f 1` +MIME_SUB=`echo $MIME | cut -d "/" -f 2` + + +case $type in + uni) + AFILE="${ACTDIR}/${name}.sh" + check_dir "${ACTDIR}" + populate_file "${AFILE}" + $EDITOR "${AFILE}" + test -e "${AFILE}" && chmod +x "${AFILE}" + ;; + base) + BASEDIR="${ACTDIR}/$MIME_BASE" + AFILE="${BASEDIR}/${name}.sh" + check_dir "${BASEDIR}" + populate_file "${AFILE}" + $EDITOR "${AFILE}" + test -e ${AFILE} && chmod +x "${ACTDIR}/$name" + ;; + sub) + SUBDIR="${ACTDIR}/${MIME_BASE}/${MIME_SUB}" + AFILE="${SUBDIR}/${name}.sh" + check_dir ${SUBDIR} + populate_file "${AFILE}" + $EDITOR "${AFILE}" + test -e ${AFILE} && chmod+ +x ${AFILE} + ;; +esac diff --git "a/extra/actions/Add\\ Action?type?name!.sh" "b/extra/actions/Add\\ Action?type?name!.sh" deleted file mode 100755 index 6a322bc..0000000 --- "a/extra/actions/Add\\ Action?type?name!.sh" +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - - -errecho() { - echo ${@} >&2 -} - -check_dir() { - DIR=${1} - - [ -d ${DIR} ] || - mkdir -p ${DIR} || - (echo "Can't create directory: ${DIR}" && exit 1) -} - -populate_file() { - FILE=${1} - - # Don't try to overwrite existing file - test -e ${FILE} && return - - - - cat > ${FILE} << EOF -#!/bin/sh - -# Selected files are stored here -FILES=\${@} - -# You can interate over them one by one -for FILE in \${FILES}; do - echo \$FILE -done - -# Or process them all at once -echo "\${FILES}" -EOF -} - - -## Starting point - -FILE=${1} -MIME=`hunter -m $FILE` -STATUS=$? - - -# MIME detection failed, bail out unless type is base -[ $STATUS != 0 ] && [ $type != "uni" ] && - echo $MIME && - exit 1 - -# Laziy not using XGD here because of OSX -ACTDIR="$HOME/.config/hunter/actions/" - -MIME_BASE=`echo $MIME | cut -d "/" -f 1` -MIME_SUB=`echo $MIME | cut -d "/" -f 2` - - -case $type in - uni) - AFILE="${ACTDIR}/${name}.sh" - check_dir "${ACTDIR}" - populate_file "${AFILE}" - $EDITOR "${AFILE}" - test -e "${AFILE}" && chmod +x "${AFILE}" - ;; - base) - BASEDIR="${ACTDIR}/$MIME_BASE" - AFILE="${BASEDIR}/${name}.sh" - check_dir "${BASEDIR}" - populate_file "${AFILE}" - $EDITOR "${AFILE}" - test -e ${AFILE} && chmod +x "${ACTDIR}/$name" - ;; - sub) - SUBDIR="${ACTDIR}/${MIME_BASE}/${MIME_SUB}" - AFILE="${SUBDIR}/${name}.sh" - check_dir ${SUBDIR} - populate_file "${AFILE}" - $EDITOR "${AFILE}" - test -e ${AFILE} && chmod+ +x ${AFILE} - ;; -esac -- cgit v1.2.3