Author: Adam Evyčędo <git@apiote.xyz>
add fun, open, and view
.config/lf/lfrc | 21 +++++++-------------- .config/lf/previewer.sh | 17 +++-------------- .config/sh/functions | 36 ++++++++++++++++++++++++++++++++++++ .local/bin/fun | 10 ++++++++++
diff --git a/.config/lf/lfrc b/.config/lf/lfrc index 3d2c25044378819c8b19bebfbaee8d641f6b59ea..9c5ff0385012853fd26ee68580e3d00506040642 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -1,4 +1,5 @@ # https://github.com/gokcehan/lf/wiki +# https://pkg.go.dev/github.com/gokcehan/lf set shell sh set shellopts '-eu' @@ -7,29 +8,21 @@ set scrolloff 10 set icons set previewer ~/.config/lf/previewer.sh -# execute current file (must be executable) map x $$f map X !$f -map o &xdg-open $f map D delete map gi cd /run/media/adam map gs cd /media/syncthing/adam/Marvin map gn cd /media/nextcloud/me@cloud.apiote.xyz/ map <f-5> reload -map <f-2> rename $f -map <enter> open $f +map <f-2> rename $fx +map <enter> open $fx +map e edit $fx map . set hidden! -cmd open ${{ - case $(file --mime-type $f -b) in - application/pdf) zathura $fx &;; - text/*) hx $fx;; - image/*) setsid feh $fx >/dev/null 2>&1 &;; - audio/*) setsid mpv $fx >/dev/null 2>&1 &;; - video/*) setsid mpv $fx >/dev/null 2>&1 &;; - *) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;; - esac -}} + +cmd edit $fun edit "$fx" +cmd open $fun view "$fx" cmd trash %set -f; mv $fx ~/.local/share/Trash/files/ diff --git a/.config/lf/previewer.sh b/.config/lf/previewer.sh index 4fee333f490ebef10b8b7714e93bd646d68798a0..65d2bd582433740f48143405c0b1d12c79e6adc0 100755 --- a/.config/lf/previewer.sh +++ b/.config/lf/previewer.sh @@ -1,17 +1,6 @@ #!/bin/sh -file="$1" +. ~/.config/sh/variables +. ~/.config/sh/functions -case $(file -Lb --mime-type -- "$file") in - application/zip) - unzip -l "$file" ;; - application/gzip) - tar tvf "$file" ;; - application/x-bzip2) - tar tvf "$file" ;; - application/x-tar) - tar tvf "$file" ;; - *) - cat "$file" -esac - +view "$1" diff --git a/.config/sh/functions b/.config/sh/functions index 8a03c9bbe4ba84b2ff9d0a08a267eb3c22177529..2b2146e8e595b37bfe64711afa84b294eab2eaf1 100644 --- a/.config/sh/functions +++ b/.config/sh/functions @@ -730,6 +730,42 @@ # shellcheck disable=SC2091 $(echo "$result" | sed 's/.*�//') >/dev/null 2>&1 & } +view() { + # TODO add gemini + if beginswith 'http://' "$1" || beginswith 'https://' "$2" + then + luakit "$1" + exit + fi + + # TODO add json, links; 'me.asc: application/pgp-keys; charset=us-ascii' + mime=$(file -i "$1" | cut -d ':' -f2 | cut -d ';' -f1 | tr -d ' ') + case $mime in + text/*) bat -f "$1" ;; + image/*) setsid swayimg "$1" >/dev/null 2>&1 & ;; + video/*) setsid mpv "$1" >/dev/null 2>&1 & ;; + audio/*) setsid mpa "$1" >/dev/null 2>&1 & ;; + application/pdf) setsid zathura "$1" >/dev/null 2>&1 & ;; + application/epub+zip) setsid zathura "$1" >/dev/null 2>&1 & ;; + application/zip) unzip -l "$1" ;; + application/x-bzip2|application/gzip|application/x-tar) tar tvf "$1" ;; + *) hexyl "$1" ;; + esac +} + +edit() { + mime=$(file -i "$1" | cut -d ':' -f2 | cut -d ';' -f1 | tr -d ' ') + case $mime in + text/*) hx "$1" ;; + image/*) setsid gimp "$1" >/dev/null 2>&1 & ;; + video/*) setsid kdenlive "$1" >/dev/null 2>&1 & ;; + audio/*) setsid audacity "$1" >/dev/null 2>&1 & ;; + application/pdf) setsid gimp "$1" >/dev/null 2>&1 & ;; + application/epub+zip) setsid sigil "$1" >/dev/null 2>&1 & ;; + application/zip|application/x-bzip2|application/gzip|application/x-tar) setsid file-roller "$1" >/dev/null 2>&1 & ;; + esac +} + ws() { if stat "$HOME/Pictures/wallpapers/$(hostname)_w$1.webp" >/dev/null 2>&1 then diff --git a/.local/bin/fun b/.local/bin/fun new file mode 100755 index 0000000000000000000000000000000000000000..ff32c420f5a38d6ad1bdf4cec05df1132b204f68 --- /dev/null +++ b/.local/bin/fun @@ -0,0 +1,10 @@ +#!/bin/sh + +. "$HOME/.config/sh/variables.$(hostname)" +. ~/.config/sh/variables +. ~/.config/sh/functions + +fun_name="$1" +shift + +$fun_name "$@" \ No newline at end of file