install.fairie/dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_opener
Brian Zalewski 7bd467cb73 Update dotfiles/.local/share/chezmoi/home/Library/Application Support/tabby/plugins/symlink_package-lock.json, dotfiles/.local/share/chezmoi/home/Library/Developer/Xcode/UserData/FontAndColorThemes/Betelgeuse Dark.dvtcolortheme, dotfiles/.local/share/chezmoi/home/Library/Developer/Xcode/UserData/FontAndColorThemes/Betelgeuse Light.dvtcolortheme, dotfiles/.local/share/chezmoi/home/Library/Preferences/com.apple.Terminal.plist, dotfiles/.local/share/chezmoi/home/run_update, dotfiles/.local/share/chezmoi/home/AppData/Local/clink/oh-my-posh.lua, dotfiles/.local/share/chezmoi/home/.chezmoitemplates/chassis-info, dotfiles/.local/share/chezmoi/home/.chezmoitemplates/cpu-info, dotfiles/.local/share/chezmoi/home/.chezmoitemplates/profile.sh, dotfiles/.local/share/chezmoi/home/dot_cache/zsh/.gitkeep, dotfiles/.local/share/chezmoi/home/dot_local/assets/Betelgeuse.macOS.terminal, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_bwc, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_chrome-profile-export, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_chrome-profile-import, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_firefox-profile-export, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_firefox-profile-import, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_fonttest, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_install-dotfiles, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_install-terminal-theme, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_ksetwallpaper, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_logg, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_opener, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_provision, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_quickstart, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_ramqube, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_run, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_slack, dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_squash-symlink, dotfiles/.local/share/chezmoi/home/dot_local/konsole/Default.profile, dotfiles/.local/share/chezmoi/home/dot_local/scripts/macos.bash, dotfiles/.local/share/chezmoi/home/dot_local/scripts/motd.bash, dotfiles/.local/share/chezmoi/home/dot_local/scripts/p10k.zsh, dotfiles/.local/share/chezmoi/home/dot_local/share/fonts/FontAwesome.ttf, dotfiles/.local/share/chezmoi/home/dot_local/share/fonts/Weather-Icons.ttf, dotfiles/.local/share/chezmoi/home/dot_local/share/git-core/templates/hooks/post-commit, dotfiles/.local/share/chezmoi/home/dot_local/state/bash/.gitkeep, dotfiles/.local/share/chezmoi/home/dot_local/state/zsh/.gitkeep, dotfiles/.local/share/chezmoi/home/dot_ssh/authorized_keys.github.tmpl, dotfiles/.local/share/chezmoi/home/dot_ssh/id_rsa.pub, dotfiles/.local/share/chezmoi/home/dot_ssh/private_config.tmpl, dotfiles/.local/share/chezmoi/home/dot_ssh/private_id_rsa.tmpl, dotfiles/.local/share/chezmoi/home/dot_vim/autoload/lightline/colorscheme/Betelgeuse.vim, dotfiles/.local/share/chezmoi/home/dot_vim/colors/Betelgeuse.vim, dotfiles/.local/share/chezmoi/home/dot_vim/vimrc, dotfiles/.local/share/chezmoi/home/private_dot_config/Kvantum/kvantum.config, dotfiles/.local/share/chezmoi/home/private_dot_config/alacritty/alacritty.yml, dotfiles/.local/share/chezmoi/home/private_dot_config/asdf/asdfrc.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/asdf/default-cargo-pkgs.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/asdf/default-golang-pkgs.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/asdf/default-npm-packages, dotfiles/.local/share/chezmoi/home/private_dot_config/asdf/default-python-pkgs.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/asdf/default-ruby-pkgs.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/bashtop/bashtop.cfg, dotfiles/.local/share/chezmoi/home/private_dot_config/bat/config, dotfiles/.local/share/chezmoi/home/private_dot_config/brew/Brewfile.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/brew/whalebrew, dotfiles/.local/share/chezmoi/home/private_dot_config/crontab/config, dotfiles/.local/share/chezmoi/home/private_dot_config/direnv/direnv.toml, dotfiles/.local/share/chezmoi/home/private_dot_config/fd/ignore, dotfiles/.local/share/chezmoi/home/private_dot_config/firejail/bitwarden.local, dotfiles/.local/share/chezmoi/home/private_dot_config/firejail/chromium.local, dotfiles/.local/share/chezmoi/home/private_dot_config/firejail/code.local, dotfiles/.local/share/chezmoi/home/private_dot_config/firejail/gcloud.local, dotfiles/.local/share/chezmoi/home/private_dot_config/firejail/google-chrome-stable.local, dotfiles/.local/share/chezmoi/home/private_dot_config/firejail/slack.local, dotfiles/.local/share/chezmoi/home/private_dot_config/firejail/thunderbird.local, dotfiles/.local/share/chezmoi/home/private_dot_config/fontconfig/fonts.conf, dotfiles/.local/share/chezmoi/home/private_dot_config/ghorg/conf.yaml.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/git/attributes, dotfiles/.local/share/chezmoi/home/private_dot_config/git/commit-template, dotfiles/.local/share/chezmoi/home/private_dot_config/git/config.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/git/ignore, dotfiles/.local/share/chezmoi/home/private_dot_config/gtk-1.0/.gitkeep, dotfiles/.local/share/chezmoi/home/private_dot_config/gtk-2.0/gtkrc, dotfiles/.local/share/chezmoi/home/private_dot_config/gtk-3.0/settings.ini, dotfiles/.local/share/chezmoi/home/private_dot_config/himalaya/config.toml.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/k9s/plugin.yml, dotfiles/.local/share/chezmoi/home/private_dot_config/kitty/Betelgeuse-dark.conf, dotfiles/.local/share/chezmoi/home/private_dot_config/kitty/Betelgeuse-light.conf, dotfiles/.local/share/chezmoi/home/private_dot_config/kitty/kitty.conf, dotfiles/.local/share/chezmoi/home/private_dot_config/ngrok/ngrok.yml.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/npm/npmrc.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/oh-my-posh/Betelgeuse-minimal.omp.json, dotfiles/.local/share/chezmoi/home/private_dot_config/oh-my-posh/Betelgeuse.omp.json, dotfiles/.local/share/chezmoi/home/private_dot_config/pg/.gitkeep, dotfiles/.local/share/chezmoi/home/private_dot_config/pgcli/config, dotfiles/.local/share/chezmoi/home/private_dot_config/powershell/user_profile.ps1, dotfiles/.local/share/chezmoi/home/private_dot_config/private_Code/User/extensions/theme-betelgeuse-vscode/themes/themer-dark-color-theme.json, dotfiles/.local/share/chezmoi/home/private_dot_config/private_Code/User/extensions/theme-betelgeuse-vscode/themes/themer-light-color-theme.json, dotfiles/.local/share/chezmoi/home/private_dot_config/private_Code/User/extensions/theme-betelgeuse-vscode/README.md, dotfiles/.local/share/chezmoi/home/private_dot_config/private_Code/User/extensions/theme-betelgeuse-vscode/icon.svg, dotfiles/.local/share/chezmoi/home/private_dot_config/private_Code/User/extensions/theme-betelgeuse-vscode/package.json, dotfiles/.local/share/chezmoi/home/private_dot_config/private_Code/User/extensions.json, dotfiles/.local/share/chezmoi/home/private_dot_config/private_Code/User/keybindings.json, dotfiles/.local/share/chezmoi/home/private_dot_config/private_Code/User/settings.json, dotfiles/.local/share/chezmoi/home/private_dot_config/putty/.gitkeep, dotfiles/.local/share/chezmoi/home/private_dot_config/readline/inputrc, dotfiles/.local/share/chezmoi/home/private_dot_config/ripgrep/config, dotfiles/.local/share/chezmoi/home/private_dot_config/rofi/config.rasi.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/aliases.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/exports, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/functions, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/motd, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/profile, dotfiles/.local/share/chezmoi/home/private_dot_config/slack-term/config.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/tabby/config.yaml.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/tabby/package-lock.json, dotfiles/.local/share/chezmoi/home/private_dot_config/terminator/config, dotfiles/.local/share/chezmoi/home/private_dot_config/tmux/.gitkeep, dotfiles/.local/share/chezmoi/home/private_dot_config/wget/wgetrc, dotfiles/.local/share/chezmoi/home/private_dot_config/xfce4/terminal/terminalrc, dotfiles/.local/share/chezmoi/home/private_dot_config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml, dotfiles/.local/share/chezmoi/home/private_dot_config/xsettingsd/xsettingsd.conf, dotfiles/.local/share/chezmoi/home/private_dot_config/chromium-flags.conf, dotfiles/.local/share/chezmoi/home/private_dot_config/gtkrc, dotfiles/.local/share/chezmoi/home/private_dot_config/kcminputrc, dotfiles/.local/share/chezmoi/home/private_dot_config/kdeglobals, dotfiles/.local/share/chezmoi/home/private_dot_config/konsolerc, dotfiles/.local/share/chezmoi/home/private_dot_config/ksplashrc, dotfiles/.local/share/chezmoi/home/private_dot_config/ktimezonedrc, dotfiles/.local/share/chezmoi/home/private_dot_config/kwinrc, dotfiles/.local/share/chezmoi/home/private_dot_config/mimeapps.list, dotfiles/.local/share/chezmoi/home/private_dot_config/plasma-localerc, dotfiles/.local/share/chezmoi/home/private_dot_config/plasmarc, dotfiles/.local/share/chezmoi/home/dot_Xresources, dotfiles/.local/share/chezmoi/home/dot_bash_logout, dotfiles/.local/share/chezmoi/home/dot_bash_profile, dotfiles/.local/share/chezmoi/home/dot_bashrc, dotfiles/.local/share/chezmoi/home/dot_editorconfig, dotfiles/.local/share/chezmoi/home/dot_zshrc, dotfiles/.local/share/chezmoi/home/run_once_before_install-software.sh.tmpl, dotfiles/.local/share/chezmoi/home/run_onchange_after_bash-completions, dotfiles/.local/share/chezmoi/home/run_onchange_after_crontab.tmpl, dotfiles/.local/share/chezmoi/.chezmoiroot
2022-11-22 19:59:10 +00:00

259 lines
7.3 KiB
Bash

#!/usr/bin/env bash
# @file /usr/bin/opener
# @brief Opens a file type with the appropriate program based on the mime-type
# @description
# This script heavily borrows from [opener](https://github.com/Docbroke/shell_tools/blob/main/opener).
# It makes some minor tweaks including linting fixes. It is configured
# to properly work with [Gas Station](https://github.com/megabyte-labs/Gas-Station).
# It is used to handle cross-VM links when Gas Station is used to provision [Qubes](https://www.qubes-os.org/).
# When called with -d, the default program is used.
# shellcheck disable=SC2124
getopts d: name
case $name in
d) file=$OPTARG
default=true ;;
*) file="$@" ;;
esac
[[ -z $file || ! -e $file ]] &&
exit 1
## mimetype from perl-file-mimeinfo gives better results compared to file
type mimetype &> /dev/null && mime_type="$(mimetype -b "$file")" || \
mime_type="$(file -b --mime-type "$file")"
## create some lists
XBROWSERS=("firefox" "chromium" "vimb" "qutebrowser" "weaver" "vivaldi")
TBROWSERS=("w3m" "links" "lynx" "elinks")
XEDITORS=("gvim" "geany" "leafpad" "mousepad")
TEDITORS=("cat" "less" "vim" "vis" "nano" "micro")
XFMS=("pcmanfm" "nautilus" "rof" "thunar")
TFMS=("ncdu" "du -h" "vifm" "ranger" "mc" "fff" "nnn" "clifm")
PDFVIEWERS=("llpp" "xournalpp" "mupdf" "qpdfview")
DOCVIEWERS=("llpp" "foliate" "mupdf" "qpdfview")
CHMVIEWERS=("kchmviewer" "xchm" "chmopen")
BOOKVIEWERS=("$TERMINAL --geometry=1920x1050 -p Large -x epy.py" "foliate" "llpp" "mupdf")
ARCHIVERS=("als" "lsar" "unar" "aunpack -D")
VIEWERS=("feh" "sxiv" "gifview -a" "display" "mtpaint" "gimp" "viewnoir" "fbi" "lp")
VPLAYERS=("mpv --player-operation-mode=pseudo-gui" "vlc" "cvlc" "ffplay" "ffprobe" "mediainfo")
APLAYERS=("mpv --player-operation-mode=pseudo-gui" "vlc" "cvlc" "ffplay" "ffprobe" "mediainfo" "soxi" "mpg123")
## some defaults
if [[ -n "$DISPLAY" ]]; then
PLAYER="mpv --player-operation-mode=pseudo-gui"
else
PLAYER="mpv --vo=drm"
fi
if [[ -n "$DISPLAY" ]]; then
VIEWER="sxiv -fbq $file $PWD"
else
VIEWER=fbi
fi
TERMINAL=terminator
EDITOR=vis
BROWSER=weaver
PDFVIEWER=llpp
DOCVIEWER=llpp
CHMVIEWER=kchmviewer
BOOKVIEWER="$TERMINAL --geometry=1920x1050 -p Large -x epy.py"
case "$mime_type" in
text/html|text/xml|application/x-mimearchive|message/rfc822)
if [[ $default == true ]]; then
$BROWSER "$file" && exit
elif [[ $TERM = linux && -n $DISPLAY ]]; then
select ops in exit "${XBROWSERS[@]}" "${TBROWSERS[@]}" $EDITOR; do
[[ $ops = exit ]] && exit
[[ $ops = w3m || $ops = links || $ops = elinks || $EDITOR ]] && $TERMINAL -x "$ops" "$file" &
"$ops" "$file" &> /dev/null &
done
elif [[ $TERM != linux && -n $DISPLAY ]]; then
select ops in exit "${XBROWSERS[@]}" "${TBROWSERS[@]}" $EDITOR; do
[[ $ops = exit ]] && exit
"$ops" "$file"
done
else
select ops in exit "${TBROWSERS[@]}" $EDITOR; do
[[ $ops = exit ]] && exit
"$ops" "$file"
done
fi
;;
text/*|*/xml|application/x-httpd-php3|application/x-httpd-php4|application/x-httpd-php5|application/x-shellscript)
[[ $default == true ]] && \
if [[ $TERM = linux && -n $DISPLAY ]]; then
$TERMINAL -x "${VISUAL:-${EDITOR:-vis}}" "$file"
else
"${VISUAL:-${EDITOR:-vis}}" "$file"
fi && exit
select ops in exit "${XEDITORS[@]}" "${TEDITORS[@]}"; do
[[ $ops = exit ]] && exit
"$ops" "$file"
done
;;
image/*)
[[ $default == true ]] && $VIEWER "$file" && exit
select ops in exit "${VIEWERS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file" &> /dev/null &
done
;;
video/*|application/x-matroska)
[[ $default == true ]] && $PLAYER "$file" && exit
if [[ -n $DISPLAY ]]; then
select ops in exit "${VPLAYERS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file" &
done
else
mpv --vo=drm -- "$file"
fi
;;
audio/*| application/ogg|application/x-ogg|application/mxf|application/sdp|application/smil|application/x-smil|application/streamingmedia|application/x-streamingmedia|application/vnd.rn-realmedia|application/vnd.rn-realmedia-vbr)
[[ $default == true ]] && $PLAYER "$file" && exit
select ops in exit "${APLAYERS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file" &
done
;;
application/pdf|application/x-pdf)
[[ $default == true ]] && $PDFVIEWER "$file" && exit
if [[ -n $DISPLAY ]]; then
select ops in exit "${PDFVIEWERS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file" &> /dev/null &
done
else
fbgs "$file"
fi
;;
application/x-cbz|applilcation/oxps|application/vnd.ms-xpsdocument)
[[ $default == true ]] && $DOCVIEWER "$file" && exit
select ops in exit "${DOCVIEWERS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file" &> /dev/null &
done
;;
application/octet-stream)
case "$file" in
*.chm|*.CHM)
[[ $default == true ]] && $CHMVIEWER "$file" && exit
select ops in exit "${CHMVIEWERS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file" &
done
;;
*.gpg)
gpg -d "$file"
;;
*.mobi)
[[ $default == true ]] && $BOOKVIEWER "$file" && exit
select ops in exit "${BOOKVIEWERS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file" &> /dev/null &
done
;;
*)
echo "unknow filetype, probably binary"
;;
esac
;;
application/vnd.ms-htmlhelp)
[[ $default == true ]] && $CHMVIEWER "$file" && exit
select ops in exit "${CHMVIEWERS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file" &
done
;;
application/vnd.comicbook*)
select ops in exit llpp mupdf foliate; do
[[ $ops = exit ]] && break
$ops "$file" &
done
;;
application/epub+zip|application/x-mobipocket-ebook)
[[ $default == true ]] && $BOOKVIEWER "$file" && exit
select ops in exit "${BOOKVIEWERS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file" &> /dev/null &
done
;;
application/pgp-encrypted)
gpg -d "$file"
;;
application/*zip*|application/x-?ar|application/x-?z*|application/x-compressed*|application/vnd.rar|application/x-*-image|application/x-msi)
case "$file" in
*.xoj|*.xopp) xournalpp "$file" &> /dev/null ;;
*.cb?)
select ops in exit llpp mupdf foliate als unar; do
[[ $ops = exit ]] && break
[[ $ops = als || $ops = unar ]] && "$ops" "$file"
"$ops" "$file" &> /dev/null &
done
;;
*)
if [[ $default == true ]]; then
mkdir "$file.tmp"
archivemount "$file" "$file.tmp"
echo -e "$file mounted at $file.tmp directory\n remove with fusermount -u $file.tmp"
else
select ops in exit "${ARCHIVERS[@]}" ; do
[[ $ops = exit ]] && break
# [[ $ops = aunpack ]] && aunpack -D "$file"
$ops "$file"
done
fi
;;
esac
;;
*opendocument*|*openxmlformats*|*msword|*ms-excel|*ms-powerpoint|*abiword|*write*)
[[ -n $DISPLAY ]] && libreoffice "$file" --norestore &> /dev/null
[[ -z $DISPLAY ]] && \
case "$file" in
*.odt|*.odp|*.ods|*.sxw) odt2txt "$file" ;;
*.doc) antiword "$file" ;;
*.docx) docx2txt "$file" - | $PAGER ;;
*) echo "unable to open" ;;
esac
;;
inode/directory)
select ops in exit "${TFMS[@]}" "${XFMS[@]}"; do
[[ $ops = exit ]] && break
$ops "$file"
done
;;
inode/x-empty)
echo "empty file"
rm -i "$file"
;;
inode/mount-point)
## unmount by default
# select ops in exit unmount; do
# [[ $ops = exit ]] && break
# [[ $ops = unmount ]] && fusermount -zu "$file" && rmdir "$file"
fusermount -zu "$file" && rmdir "$file" && echo "$file unmounted and removed"
# done
;;
*)
case "$file" in
*) echo "no filetype association for $file" ;;
esac
;;
esac