Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- desktop-files() {
- filetype="$1"
- default="$2"
- apps=$(mimeo -d "$filetype" --show-all | sed "1d;/${default}/d")
- echo -e "$apps"
- }
- get-command() {
- app="$1"
- file=$(echo "${*:2}" | sed 's=\/=\\\/=g;s=\ =\\ =g')
- exe=$(mimeo --desk2field "Exec" | grep -A 1 "$app" | sed 1d)
- # TODO catch more cases than %U, %u, %f, %F ?
- if [[ "$exe" =~ ^.*\%U.*$ ]]; then
- exe=${exe//\%U/${file}}
- elif [[ "$exe" =~ ^.*\%u.*$ ]]; then
- exe=${exe//\%u/${file}}
- elif [[ "$exe" =~ ^.*\%f.*$ ]]; then
- exe=${exe//\%f/${file}}
- elif [[ "$exe" =~ ^.*\%F.*$ ]]; then
- exe=${exe//\%F/${file}}
- else
- exe="${exe} $file"
- fi
- echo "$exe"
- }
- open-with() {
- file="$1"
- filetype=$(xdg-mime query filetype "$file")
- default_app=$(xdg-mime query default "$filetype")
- other_apps=$(desktop-files "$filetype" "$default_app")
- binaries=$(print -rl -- "${(ko)commands}")
- if [ ! "" = "$other_apps" ]; then
- selection="${default_app} ${other_apps} ${binaries}"
- else
- selection="${default_app} ${binaries}"
- fi
- choice=$(echo -e "$selection" \
- | tr ' ' '\n' \
- | sed '/^$/d' \
- | rofi -dmenu \
- -mesg "open ${file//\/\//\/}")
- if [ ! "$?" = "0" ]; then
- exit 1
- fi
- cmd=$(get-command "$choice" "$file")
- eval "$cmd"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement