lf cleanup
This commit is contained in:
parent
946ca414bc
commit
7863de577f
|
@ -45,8 +45,6 @@ cmd lazygit %{{
|
|||
lf -remote "send $id \$cd '$dir' && lazygit"
|
||||
}}
|
||||
|
||||
# y (select for copy) and P to paste soft-link
|
||||
# d (select for cut) and P to paste hard-link
|
||||
cmd link &{{
|
||||
set -- $(cat ~/.local/share/lf/files)
|
||||
mode="$1"
|
||||
|
@ -56,9 +54,7 @@ cmd link &{{
|
|||
exit 0
|
||||
fi
|
||||
case "$mode" in
|
||||
# symbolically copy mode is indicating a soft link
|
||||
copy) ln -sr -t . -- "$@";;
|
||||
# while a move mode is indicating a hard link
|
||||
move) ln -t . -- "$@";;
|
||||
esac
|
||||
rm ~/.local/share/lf/files
|
||||
|
@ -108,8 +104,6 @@ cmd dupe &{{
|
|||
done
|
||||
}}
|
||||
|
||||
# cmd share $curl -F"file=@$fx" https://0x0.snaile.de | xclip -r -selection c
|
||||
|
||||
cmd fzf ${{
|
||||
name="$1" input="$2" delimiter="$3" field="$4" path_field="$5" width="$6" query="${7:-}"
|
||||
histfile="$XDG_DATA_HOME/lf/$(echo $name | tr '[:upper:]' '[:lower:]')_history"
|
||||
|
@ -191,8 +185,6 @@ cmd find_project ${{
|
|||
[ -d "$file" ] && lf -remote "send $id cd $file"
|
||||
[ -f "$file" ] && lf -remote "send $id select $file"
|
||||
return 0
|
||||
|
||||
|
||||
}}
|
||||
|
||||
cmd extract ${{
|
||||
|
@ -201,45 +193,12 @@ cmd extract ${{
|
|||
done
|
||||
}}
|
||||
|
||||
# cmd set_previewer &{{
|
||||
# if [ "${1}" = "sixel" ]; then
|
||||
# lf -remote "send $id :set sixel; set previewer ~/.config/lf/preview/sixel"
|
||||
# # echo 'Previewer set to sixel'
|
||||
# elif [ "${1}" = "ueberzug" ]; then
|
||||
# lf -remote "send $id :set cleaner ~/.config/lf/preview/clean; set previewer ~/.config/lf/preview/ueberzug"
|
||||
# # echo 'Previewer set to ueberzug'
|
||||
# else
|
||||
# lf -remote "send $id :set previewer ~/.config/lf/preview/chafa"
|
||||
# # echo 'Previewer set to chafa'
|
||||
# fi
|
||||
# }}
|
||||
|
||||
# HACK: This is a dirty hack to have an lf terminal that I can "exit" out of into a shell
|
||||
cmd new_lf_term &{{
|
||||
mapcmd='map q $sh -c "tmux; kill $id"'
|
||||
# previewercmd="set_previewer $(basename "$lf_previewer")"
|
||||
# $TERMINAL -e lfX -command "${previewercmd}; ${mapcmd}"
|
||||
$TERMINAL -e lfX -command "$mapcmd"
|
||||
}}
|
||||
|
||||
# Setup
|
||||
|
||||
# &{{
|
||||
# set +u
|
||||
# previewer=ueberzug
|
||||
# [ -n "$TMUX" ] && previewer=ueberzug
|
||||
# [ -n "$VIM" ] && previewer=chafa
|
||||
# lf -remote "send $id set_previewer $previewer"
|
||||
#
|
||||
# # Clean up tags that don't exist anymore
|
||||
# # BUG: causes an obscure lf crash when tags are empty
|
||||
# echo "$(
|
||||
# while read -r l; do
|
||||
# file=$(echo "$l" | cut -d ':' -f 1)
|
||||
# [ -e "$file" ] && echo "$l"
|
||||
# done <"${XDG_DATA_HOME}/lf/tags"
|
||||
# )\n" >"${XDG_DATA_HOME}/lf/tags"
|
||||
# }}
|
||||
on-cd
|
||||
|
||||
# Basic vars
|
||||
|
@ -253,7 +212,8 @@ set wrapscroll
|
|||
set period 1
|
||||
set cursorpreviewfmt "\033[7;90m"
|
||||
set promptfmt # this is set in a function later
|
||||
set previewer ~/.config/lf/preview/ueberzug
|
||||
set sixel
|
||||
set previewer ~/.config/lf/preview/preview
|
||||
set cleaner ~/.config/lf/preview/clean
|
||||
|
||||
# Bindings
|
||||
|
@ -263,7 +223,6 @@ map <esc> quit
|
|||
map <space> :toggle; down
|
||||
map <enter> shell
|
||||
map <a-enter> shell-wait
|
||||
# map <tab><tab> fzf 'Shortcuts' 'cat $XDG_DATA_HOME/lf/shortcuts 2>/dev/null' ':' '1' '2' '85%' '^'
|
||||
map <tab><tab> find_project
|
||||
map <tab>t fzf 'Tags' 'cat $XDG_DATA_HOME/lf/tags 2>/dev/null' ':' '1' '1' '50%'
|
||||
map <tab>m fzf 'Marks' 'cat $XDG_DATA_HOME/lf/marks 2>/dev/null' ':' '1' '2' '85%' '^'
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
preview
|
|
@ -5,27 +5,17 @@ RESET="\033[0m"
|
|||
|
||||
set -C -f
|
||||
|
||||
f="$(realpath "$1")" w=$2 h=$3 x=$4 y=$5
|
||||
f="$(realpath "$1")" w=$2 h=$3 # x=$4 y=$5
|
||||
|
||||
image() {
|
||||
file=${1:-$f}
|
||||
if [ -f "$file" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
|
||||
name=$(basename "$0")
|
||||
if [ "$name" = "sixel" ]; then
|
||||
[ "$TERM_PROGRAM" = "tmux" ] && tmuxflags="--passthrough tmux"
|
||||
# shellcheck disable=2086
|
||||
echo chafa "$file" -f sixel -s "$((w - 2))x$h" --animate false --polite on $tmuxflags
|
||||
exit 0
|
||||
elif [ "$name" = "ueberzug" ]; then
|
||||
if command -V ueberzug >/dev/null 2>&1; then
|
||||
printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' "$((x + 3))" "$((y + 1))" "$((w - 6))" "$((h - 2))" "$file" >"$FIFO_UEBERZUG"
|
||||
fi
|
||||
exit 1
|
||||
else
|
||||
chafa "$file" -s "$((w - 2))x$h" --polite on
|
||||
fi
|
||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||
chafa "$file" -s "$((w - 2))x$h" --polite on
|
||||
else
|
||||
# shellcheck disable=2086
|
||||
chafa -f sixel -s "${w}x${h}" --polite on --animate false "$file"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
video() {
|
||||
|
@ -60,35 +50,35 @@ run() {
|
|||
|
||||
mimetest() {
|
||||
case "$1" in
|
||||
*/pdf)
|
||||
[ ! -f "${CACHE}.jpg" ] && run pdftoppm -jpeg -f 1 -singlefile "$f" "$CACHE"
|
||||
image "${CACHE}.jpg"
|
||||
;;
|
||||
*/x-bzip-compressed-tar | */x-compressed-tar | */x-xz-compressed-tar) run als -- "$f" ;;
|
||||
*/x-7z-compressed | */vnd.rar | */x-tar | */zip | */x-java-archive | */x-xz | */gzip) run 7z l "$f" | sed 1,11d ;;
|
||||
*/x-cd-image) run iso-info --no-header -l "$f" ;;
|
||||
*/x-bittorrent) run transmission-show "$f" ;;
|
||||
*/vnd.sun.xml.writer) run odt2txt "$f" ;;
|
||||
*/msword) run catdoc "$f" ;;
|
||||
*/vnd.openxmlformats-officedocument.wordprocessingml.document) run docx2txt <"$f" ;;
|
||||
*/vnd.ms-excel) run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv ;;
|
||||
*/vnd.openxmlformats-officedocument.spreadsheetml.sheet) run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv ;;
|
||||
*/epub+zip)
|
||||
[ ! -f "$CACHE" ] && run epub-thumbnailer "$f" "$CACHE" 1024
|
||||
image "$CACHE"
|
||||
;;
|
||||
*/pgp-encrypted) run gpg -d -- "$f" ;;
|
||||
*/pkix-cert) run openssl x509 -text -noout -in "$f" ;;
|
||||
image/svg+xml)
|
||||
[ ! -f "$CACHE" ] && run inkscape --convert-dpi-method=none -o "$CACHE" --export-overwrite -D --export-png-color-mode=RGBA_16 "$f"
|
||||
image "$CACHE"
|
||||
;;
|
||||
image/*) image ;;
|
||||
video/*) video ;;
|
||||
*opendocument*) run odt2txt "$f" ;;
|
||||
*/markdown) run glow -s "$XDG_CONFIG_HOME/glow/style.json" "$f" --width "$w" ;;
|
||||
*/html) run lynx -dump "$f" ;;
|
||||
*) return 1 ;;
|
||||
*/pdf)
|
||||
[ ! -f "${CACHE}.jpg" ] && run pdftoppm -jpeg -f 1 -singlefile "$f" "$CACHE"
|
||||
image "${CACHE}.jpg"
|
||||
;;
|
||||
*/x-bzip-compressed-tar | */x-compressed-tar | */x-xz-compressed-tar) run als -- "$f" ;;
|
||||
*/x-7z-compressed | */vnd.rar | */x-tar | */zip | */x-java-archive | */x-xz | */gzip) run 7z l "$f" | sed 1,11d ;;
|
||||
*/x-cd-image) run iso-info --no-header -l "$f" ;;
|
||||
*/x-bittorrent) run transmission-show "$f" ;;
|
||||
*/vnd.sun.xml.writer) run odt2txt "$f" ;;
|
||||
*/msword) run catdoc "$f" ;;
|
||||
*/vnd.openxmlformats-officedocument.wordprocessingml.document) run docx2txt <"$f" ;;
|
||||
*/vnd.ms-excel) run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv ;;
|
||||
*/vnd.openxmlformats-officedocument.spreadsheetml.sheet) run ssconvert --export-type=Gnumeric_stf:stf_csv "$f" "fd://1" | text --language=csv ;;
|
||||
*/epub+zip)
|
||||
[ ! -f "$CACHE" ] && run epub-thumbnailer "$f" "$CACHE" 1024
|
||||
image "$CACHE"
|
||||
;;
|
||||
*/pgp-encrypted) run gpg -d -- "$f" ;;
|
||||
*/pkix-cert) run openssl x509 -text -noout -in "$f" ;;
|
||||
image/svg+xml)
|
||||
[ ! -f "$CACHE" ] && run inkscape --convert-dpi-method=none -o "$CACHE" --export-overwrite -D --export-png-color-mode=RGBA_16 "$f"
|
||||
image "$CACHE"
|
||||
;;
|
||||
image/*) image ;;
|
||||
video/*) video ;;
|
||||
*opendocument*) run odt2txt "$f" ;;
|
||||
*/markdown) run glow -s "$XDG_CONFIG_HOME/glow/style.json" "$f" --width "$w" ;;
|
||||
*/html) run lynx -dump "$f" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
@ -103,10 +93,10 @@ if command -v gio 1>/dev/null 2>&1; then
|
|||
fi
|
||||
|
||||
case "$(file -b "$f")" in
|
||||
*text*) text "$f" ;;
|
||||
*)
|
||||
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
|
||||
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"
|
||||
mediainfo "$1" | head -n -2 | grep -v -e "Complete name" -e "General"
|
||||
;;
|
||||
*text*) text "$f" ;;
|
||||
*)
|
||||
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
|
||||
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"
|
||||
mediainfo "$1" | head -n -2 | grep -v -e "Complete name" -e "General"
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
preview
|
|
@ -1 +0,0 @@
|
|||
preview
|
|
@ -1,19 +1,19 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
clean() {
|
||||
exec 3>&-
|
||||
rm "$FIFO_UEBERZUG"
|
||||
}
|
||||
# clean() {
|
||||
# exec 3>&-
|
||||
# rm "$FIFO_UEBERZUG"
|
||||
# }
|
||||
|
||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||
command lf "$@"
|
||||
command lf "$@"
|
||||
else
|
||||
[ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf"
|
||||
export FIFO_UEBERZUG="$XDG_RUNTIME_DIR/ueberzug-$$"
|
||||
mkfifo "$FIFO_UEBERZUG"
|
||||
ueberzug layer -s -p json <"$FIFO_UEBERZUG" &
|
||||
exec 3>"$FIFO_UEBERZUG"
|
||||
trap clean EXIT
|
||||
command lf "$@" 3>&-
|
||||
[ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf"
|
||||
# export FIFO_UEBERZUG="$XDG_RUNTIME_DIR/ueberzug-$$"
|
||||
# mkfifo "$FIFO_UEBERZUG"
|
||||
# ueberzug layer -s -p json <"$FIFO_UEBERZUG" &
|
||||
# exec 3>"$FIFO_UEBERZUG"
|
||||
# trap clean EXIT
|
||||
command lf "$@" 3>&-
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue