summaryrefslogtreecommitdiff
path: root/misc/mime
diff options
context:
space:
mode:
Diffstat (limited to 'misc/mime')
-rwxr-xr-xmisc/mime51
1 files changed, 35 insertions, 16 deletions
diff --git a/misc/mime b/misc/mime
index 2070376..5951b14 100755
--- a/misc/mime
+++ b/misc/mime
@@ -1,7 +1,9 @@
#!/bin/sh
+# Media type csv caching
cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/mimewiz"
-types="`grep -v '#'`"<< TYPES
-application
+mtypesrc="https://www.iana.org/assignments/media-types"
+mtypes="`grep -v '#'`"<< TYPES
+#application
audio
font
#example
@@ -12,36 +14,53 @@ image
text
video
TYPES
-typesrc="https://www.iana.org/assignments/media-types"
-#dlcsv() { curl -sS -C - -e "$typesrc" "$typesrc" > "$typefile" || exit; }
dlcsv() { curl -sS -C - -o "$2" "$1" || exit; }
# Download all media type csv's if they're not avaliable
mkdir -p "$cachedir"
-for type in $types; do
- typefile="$cachedir/$type.csv"
- [ -e "$typefile" ] || dlcsv "$typesrc/$type.csv" "$typefile"
+for mtype in $mtypes; do
+ mtypefile="$cachedir/$mtype.csv"
+ [ -e "$mtypefile" ] || dlcsv "$mtypesrc/$mtype.csv" "$mtypefile"
#[ "$2" = "$type" ] && mimetype="`cut -d',' -f2 $typefile`" && break
done
-#[ -n "$mimetype" ] && xdg-mime default $application.desktop $mimetype
+interactiveopt() { # Usage: interactiveopt "options" "prompt" "maxopts" "col"
+ unset opt # This won't be set if we choose to use recursion, so do it in a while loop instead
+ while [ -z $opt ] 2>/dev/null; do
+ [ -n "$4" ] && [ "$4" = "col" ] \
+ && echo "$1" | nl -s': ' | column \
+ || echo "$1" | nl -s': '
+ read -p "$2" choices \
+ && [ -n "$3" ] && ( choices="$(echo $choices | cut -d' ' -f1-$3)" || ( echo "Invalid entry" && unset choices ) )
+ for choice in $choices; do
+ case "$choice" in
+ [0-9]*) opt="$(echo "$1" | head -"$(echo $choice | tr -cd '[:digit:]')" | tail -1) $opt" ;;
+ *) opt="$(echo "$1" | grep "^$choice$" 2>/dev/null) $opt" ;;
+ esac || ( echo "Invalid option \"$choice\"" && undet opt && break ) # Why wont this unset opt or break???????
+ done
+ done
+}
-# Choose mimetype:
-types="$types\npdf\nspreadsheet ms-excel\nwordprocessing ms-word\npresentation ms-powerpoint\ndrawing\nzip gzip"
-echo "$types" | nl -s': '
-echo "$types" | head -7 | tail -1
+# Choose mimetype:
+mtypes="$mtypes\npdf\nspreadsheet ms-excel\nwordprocessing ms-word\npresentation ms-powerpoint\ndrawing\nzip gzip"
+interactiveopt "$mtypes" "Choose Mimetype: "
+mtype="$opt"
+echo "$mtype"
# Choose subtype
#cut -d',' -f1 "$cachedir/application.csv" | grep drawing | nl -s': ' | column
# Choose program
-ls /usr/share/applications | sed 's/\.desktop//' | nl -s': ' | column
+interactiveopt "$(ls /usr/share/applications | sed 's/\.desktop//')" "Choose program to open with: " col
+program="$opt"
+echo "$program"
-
-#cut -d',' -f1 "$cachedir/image.csv" | nl -s': ' | column
-cut -d',' -f2 "$cachedir/image.csv"
+#echo "All $mtype Types\n$(cut -d',' -f1 "$cachedir/image.csv" | tail -n +2)"
+#cut -d',' -f2 "$cachedir/image.csv"
#jcho "$types" | while read type; do
#done
+
+#[ -n "$mimetype" ] && xdg-mime default $application.desktop $mimetype