summaryrefslogtreecommitdiff
path: root/misc/mime
diff options
context:
space:
mode:
Diffstat (limited to 'misc/mime')
-rwxr-xr-xmisc/mime42
1 files changed, 28 insertions, 14 deletions
diff --git a/misc/mime b/misc/mime
index 5951b14..376506b 100755
--- a/misc/mime
+++ b/misc/mime
@@ -2,7 +2,7 @@
# Media type csv caching
cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/mimewiz"
mtypesrc="https://www.iana.org/assignments/media-types"
-mtypes="`grep -v '#'`"<< TYPES
+mtypes="`grep -v '#'`" << TYPES
#application
audio
font
@@ -14,6 +14,14 @@ image
text
video
TYPES
+nmtypes="`cat`" << TYPES
+pdf,
+spreadsheet ms-excel,
+wordprocessing ms-word,
+presentation ms-powerpoint,
+drawing,
+zip gzip,
+TYPES
dlcsv() { curl -sS -C - -o "$2" "$1" || exit; }
@@ -22,17 +30,21 @@ mkdir -p "$cachedir"
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
-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
+interactiveopt() {
+ # Usage: interactiveopt "options" "prompt" "maxopts (if unset than equal to inf)" "col"
+ # Purpose: give the user a numbered list of options. User can specify multiple choices. User can specify either the number or the name of the option.
+ # Output: saved in variable "opt"
+ unset opt # This won't be set if using recursion, do it in a while loop instead
while [ -z $opt ] 2>/dev/null; do
+ # Column option
[ -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 ) )
+ # Parse user input
+ read -p "$2" choices \
+ && choices="$(echo $choices | cut -d' ' -f1-$3)"
for choice in $choices; do
case "$choice" in
[0-9]*) opt="$(echo "$1" | head -"$(echo $choice | tr -cd '[:digit:]')" | tail -1) $opt" ;;
@@ -44,23 +56,25 @@ interactiveopt() { # Usage: interactiveopt "options" "prompt" "maxopts" "col"
# Choose mimetype:
-mtypes="$mtypes\npdf\nspreadsheet ms-excel\nwordprocessing ms-word\npresentation ms-powerpoint\ndrawing\nzip gzip"
-interactiveopt "$mtypes" "Choose Mimetype: "
-mtype="$opt"
+mtypes="$mtypes\n$(echo "$nmtypes" | cut -d',' -f1)"
+interactiveopt "$mtypes" "Choose mimetype: " 1
+mtype="$(echo "$opt" | cut -d' ' -f1)"
echo "$mtype"
+echo
# Choose subtype
-#cut -d',' -f1 "$cachedir/application.csv" | grep drawing | nl -s': ' | column
+mtypefile="$cachedir/$mtype.csv"
+[ -e "$mtypefile" ] && interactiveopt "all\n$(cut -d',' -f1 "$mtypefile" | tail -n +2)" "Choose $mtype subtype: " "" col
+echo
# Choose program
-interactiveopt "$(ls /usr/share/applications | sed 's/\.desktop//')" "Choose program to open with: " col
+interactiveopt "$(ls /usr/share/applications | sed 's/\.desktop//')" "Choose program to open with: " "" col
program="$opt"
echo "$program"
+echo
+# Xdg-mime commands
#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