Added keybinds for options for Yazi opener
This commit is contained in:
parent
e42cb28ffc
commit
fb16f8aa70
5 changed files with 106 additions and 42 deletions
|
|
@ -1,18 +1,46 @@
|
|||
#!/usr/bin/env sh
|
||||
# Script for opening a file, intended for use by a terminal file manager.
|
||||
|
||||
function help_exit() {
|
||||
echo "Utility for opening different filetypes.
|
||||
|
||||
Usage:
|
||||
$ opener [-n {num}] {file} # Open the file in the current shell
|
||||
$ opener [-n {num}] detatch {file} # Detatch the program into a new shell
|
||||
|
||||
[num]: which opener to use, in order of precedence. defaults to 1
|
||||
"
|
||||
exit 0
|
||||
}
|
||||
|
||||
num=1
|
||||
[ "$1" = "-n" ] && num=$2 && shift 2
|
||||
|
||||
# Whether to open in a new window
|
||||
detatch=0
|
||||
[ "$1" = "detatch" ] && detatch=1 && shift 1
|
||||
|
||||
list=0
|
||||
[ "$1" = "list" ] && list=1 && shift 1
|
||||
|
||||
# First arg must be a file
|
||||
file="$1"
|
||||
[ ! -f "$file" ] && echo "Not a file: '$file'" && exit 1
|
||||
[ ! -f "$file" ] && echo "Not a file: '$file'" && help_exit
|
||||
while [ -L "$file" ]; do
|
||||
# Resolve symlinks
|
||||
file=$(readlink "$file")
|
||||
done
|
||||
|
||||
function list_exit() {
|
||||
[ "$list" -ne 1 ] && return
|
||||
i=1
|
||||
for arg in "$@"; do
|
||||
echo "$i: $arg"
|
||||
i=$((i + 1))
|
||||
done
|
||||
exit 0
|
||||
}
|
||||
|
||||
function launch_gui() {
|
||||
if [ "$detatch" -eq 0 ]; then
|
||||
[ -n "$WAYLAND_DISPLAY" ] \
|
||||
|
|
@ -52,20 +80,29 @@ case $(file --mime-type "$file" -b) in
|
|||
application/x-subrip|\
|
||||
inode/x-empty|\
|
||||
text/*)
|
||||
case "${1##*.}" in
|
||||
org|typ)
|
||||
# Any "document" like file ought to be in emacs
|
||||
launch_gui emacsclient -c "$file"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
list_exit \
|
||||
"Neovim" \
|
||||
"Emacs GUI" \
|
||||
"Emacs TUI"
|
||||
|
||||
launch_term nvim "$file"
|
||||
if [ "$num" -eq 2 ]; then
|
||||
launch_gui emacsclient -c -a emacs "$file"
|
||||
elif [ "$num" -eq 3 ]; then
|
||||
launch_term emacsclient -nw -a 'emacs -nw' "$file"
|
||||
else
|
||||
launch_term nvim "$file"
|
||||
fi
|
||||
;;
|
||||
image/*)
|
||||
list_exit \
|
||||
"nsxiv"
|
||||
launch_gui nsxiv "$file"
|
||||
;;
|
||||
video/*)
|
||||
list_exit \
|
||||
"Neovim" \
|
||||
"Emacs GUI" \
|
||||
"Emacs TUI"
|
||||
launch_gui mpv -quiet "$file"
|
||||
;;
|
||||
application/epub*|\
|
||||
|
|
@ -74,10 +111,15 @@ case $(file --mime-type "$file" -b) in
|
|||
application/postscript|\
|
||||
application/vnd.djvu|\
|
||||
image/vnd.djvu)
|
||||
list_exit \
|
||||
"Zathura"
|
||||
launch_gui zathura "$file"
|
||||
;;
|
||||
audio/*|\
|
||||
video/x-ms-asf)
|
||||
list_exit \
|
||||
"MPV"
|
||||
# If it has an album cover, launch graphical mpv
|
||||
[ -z "$(mediainfo "$1" | grep "Cover\s*: Yes")" ] \
|
||||
&& (launch_term mpv --audio-display=no "$file") \
|
||||
|| (launch_gui mpv "$file")
|
||||
|
|
@ -97,9 +139,12 @@ case $(file --mime-type "$file" -b) in
|
|||
application/vnd.openxmlformats-officedocument.presentationml.presentation|\
|
||||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet|\
|
||||
application/vnd.openxmlformats-officedocument.wordprocessingml.document)
|
||||
list_exit \
|
||||
"LibreOffice"
|
||||
launch_gui libreoffice "$file"
|
||||
;;
|
||||
*)
|
||||
echo "No program defined for this filetype."
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue