diff --git a/.config/bookmarks/files b/.config/bookmarks/files deleted file mode 100644 index 546c135a1..000000000 --- a/.config/bookmarks/files +++ /dev/null @@ -1,3 +0,0 @@ -# keys filename -bf $XDG_CONFIG_HOME/bookmarks/files -bd $XDG_CONFIG_HOME/bookmarks/directories diff --git a/.config/bookmarks/directories b/.config/directories similarity index 100% rename from .config/bookmarks/directories rename to .config/directories diff --git a/.config/lf/lfrc b/.config/lf/lfrc index 4b42c7faa..ea84fa6d7 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -133,28 +133,28 @@ cmd dupe &{{ # TODO: Move this to zsh config cmd fzfsearch ${{ - file="$(find -L $PWD | fzf --header="Searching Filenames" || true)" + file="$(find -L $PWD | fzf --header='Searching Filenames' --preview='head -$LINES {} 2>/dev/null || ls -lhpAN --color=always --group-directories-first {}' || true)" [ -z "$file" ] && return - [ -d $file ] && lf -remote "send $id cd $file" && return 0 - [ -f $file ] && lf -remote "send $id select $file" + [ -d "$file" ] && lf -remote "send $id cd $file" && return 0 + [ -f "$file" ] && lf -remote "send $id select $file" }} cmd fzftags ${{ - file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/tags | fzf --header="Searching Tags" | sed 's/:.$//' || true)" + file="$(cat $XDG_DATA_HOME/lf/tags | fzf --header='Searching Tags' | sed 's/:.$//' || true)" [ -z "$file" ] && return - [ -d $file ] && lf -remote "send $id cd $file" && return 0 - [ -f $file ] && lf -remote "send $id select $file" + [ -d "$file" ] && lf -remote "send $id cd $file" && return 0 + [ -f "$file" ] && lf -remote "send $id select $file" }} cmd fzfmarks ${{ - file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/marks | fzf --header="Searching Marks" | cut -b 3- || true)" + file="$(cat $XDG_DATA_HOME/lf/marks | fzf --header='Searching Marks' | cut -b 3- || true)" [ -z "$file" ] && return - [ -d $file ] && lf -remote "send $id cd $file" && return 0 - [ -f $file ] && lf -remote "send $id select $file" + [ -d "$file" ] && lf -remote "send $id cd $file" && return 0 + [ -f "$file" ] && lf -remote "send $id select $file" }} cmd fzfshortcut ${{ - file="$(cat ${XDG_CONFIG_HOME:-$HOME/.config}/lf/shortcutrc | cut -d '"' -f2 | fzf --header="Searching Shortcuts")" + file="$(cat $XDG_DATA_HOME/lf/dirs | fzf --header='Searching Shortcuts' --preview='echo '{}' | cut -f2 | xargs ls' | cut -f2 )" [ -z "$file" ] && return - [ -d $file ] && lf -remote "send $id cd $file" && return 0 - [ -f $file ] && lf -remote "send $id select $file" + [ -d "$file" ] && lf -remote "send $id cd $file" && return 0 + [ -f "$file" ] && lf -remote "send $id select $file" }} # cmd fzfworkon ${{ # workon -n $(workon | fzf) diff --git a/.config/lf/preview/clean b/.config/lf/preview/clean index 1653fcd94..acab52f2c 100755 --- a/.config/lf/preview/clean +++ b/.config/lf/preview/clean @@ -1,4 +1,5 @@ #!/bin/sh + if [ -n "$FIFO_UEBERZUG" ]; then printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG" fi diff --git a/.config/lf/preview/preview b/.config/lf/preview/preview index 88f62c86f..01cec7a25 100755 --- a/.config/lf/preview/preview +++ b/.config/lf/preview/preview @@ -8,87 +8,85 @@ set -C -f f="$(realpath "$1")" w=$2 h=$3 x=$4 y=$5 image() { - f=$1 w=$2 h=$3 x=$4 y=$5 - if [ -f "$f" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then - name=$(basename "$0") - if [ "$name" = "sixel" ]; then - [ "$TERM_PROGRAM" = "tmux" ] && tmuxflags="--passthrough tmux" - # shellcheck disable=2086 - chafa "$f" -f sixel -s "$(($2 - 2))x$3" --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' "$(($4 + 3))" "$(($5 + 1))" "$(($2 - 6))" "$(($3 - 2))" "$1" >"$FIFO_UEBERZUG" - fi - exit 1 - else - chafa "$f" -s "$(($2 - 2))x$3" --polite on - fi - fi + 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 + fi } video() { - f=$1 w=$2 h=$3 x=$4 y=$5 - thumb="$("$HOME/.config/lf/preview/vidthumb" "$f")" || ( - printf "%b" "${RED}vidthumb failed to execute${RESET}" - return 1 - ) - image "$thumb" "$w" "$h" "$x" "$y" + thumb="$("$HOME/.config/lf/preview/vidthumb" "$f")" || ( + printf "%b" "${RED}vidthumb failed to execute${RESET}" + return 1 + ) + image "$thumb" } text() { - f=$1 w=$2 - bat --color=always --style=plain --pager=never --terminal-width "$((w - 2))" "$f" && exit 1 - cat "$f" - exit 1 + bat --color=always --style=plain --pager=never --terminal-width "$((w - 2))" "$f" && exit 1 + cat "$f" + exit 1 } run() { - #shellcheck disable=SC2068 - if ! command -v "$1" >/dev/null 2>&1; then - printf "%b" "${RED}Cannot execute $1${RESET}" - exit 1 - elif $@; then - exit 1 - else - printf "%b" "${RED}Failed to run command: $*${RESET}" - exit 1 - fi + #shellcheck disable=SC2068 + if ! command -v "$1" >/dev/null 2>&1; then + printf "%b" "${RED}Cannot execute $1${RESET}" + exit 1 + elif $@; then + exit 1 + else + printf "%b" "${RED}Failed to run command: $*${RESET}" + exit 1 + fi } mimetest() { - case "$1" in - */pdf) - [ ! -f "${CACHE}.jpg" ] && cat "$f" | run pdftoppm -jpeg -f 1 -singlefile - "$CACHE" - image "${CACHE}.jpg" "$w" "$h" "$x" "$y" - ;; - */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" "$w" "$h" "$x" "$y" - ;; - */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" "$w" "$h" "$x" "$y" - ;; - image/*) image "$f" "$w" "$h" "$x" "$y" ;; - video/*) video "$f" "$w" "$h" "$x" "$y" ;; - *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 + 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 ;; + esac } CACHE="${XDG_CACHE_HOME}/lf/thumbnail-$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')" @@ -97,15 +95,15 @@ filerun="$(file --brief --dereference --mime-type "$f")" mimetest "$filerun" && exit 1 if command -v gio 1>/dev/null 2>&1; then - giorun="$(gio info "$f" 2>/dev/null | grep standard::content-type | cut -d' ' -f4)" - mimetest "$giorun" && exit 1 + giorun="$(gio info "$f" 2>/dev/null | grep standard::content-type | cut -d' ' -f4)" + mimetest "$giorun" && exit 1 fi case "$(file -b "$f")" in -*text*) text "$f" "$w" ;; +*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" - ;; + 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 diff --git a/.config/lf/preview/vidthumb b/.config/lf/preview/vidthumb index 3c5165711..105622186 100755 --- a/.config/lf/preview/vidthumb +++ b/.config/lf/preview/vidthumb @@ -1,37 +1,36 @@ -#!/usr/bin/env bash -# Script to generate thumbnails for lf +#!/bin/sh if ! [ -f "$1" ]; then - exit 1 + exit 1 fi -cache="${XDG_CACHE_HOME:-$HOME/.cache}/lf" +cache="$XDG_CACHE_HOME/lf" index="$cache/index.json" -movie="$(realpath "$1")" +file="$(realpath "$1")" mkdir -p "$cache" if [ -f "$index" ]; then - thumbnail="$(jq -r ". \"$movie\"" <"$index")" - if [[ "$thumbnail" != "null" ]]; then - if [[ ! -f "$cache/$thumbnail" ]]; then - exit 1 - fi - echo "$cache/$thumbnail" - exit 0 - fi + thumbnail="$(jq -r ". \"$file\"" <"$index")" + if [ "$thumbnail" != "null" ]; then + if [ ! -f "$cache/$thumbnail" ]; then + exit 1 + fi + echo "$cache/$thumbnail" + exit 0 + fi fi thumbnail="$(uuidgen).jpg" -if ! ffmpegthumbnailer -i "$movie" -o "$cache/$thumbnail" -s 0 2>/dev/null; then - exit 1 +if ! ffmpegthumbnailer -i "$file" -o "$cache/$thumbnail" -s 0 2>/dev/null; then + exit 1 fi -if [[ ! -f "$index" ]]; then - echo "{\"$movie\": \"$thumbnail\"}" >"$index" +if [ ! -f "$index" ]; then + echo "{\"$file\": \"$thumbnail\"}" >"$index" fi -json="$(jq -r --arg "$movie" "$thumbnail" ". + {\"$movie\": \"$thumbnail\"}" <"$index")" +json="$(jq -r --arg "$file" "$thumbnail" ". + {\"$file\": \"$thumbnail\"}" <"$index")" echo "$json" >"$index" echo "$cache/$thumbnail" diff --git a/.config/zsh/configs/hashes b/.config/zsh/configs/hashes index 1938ff112..e69de29bb 100644 --- a/.config/zsh/configs/hashes +++ b/.config/zsh/configs/hashes @@ -1,20 +0,0 @@ -hash -d h=/home/luca -hash -d ch=/home/luca/.cache -hash -d cf=/home/luca/.config -hash -d dt=/home/luca/.local/share -hash -d st=/home/luca/.local/state -hash -d sc=/home/luca/.local/bin -hash -d se=/home/luca/.local/libexec -hash -d mn=/mnt -hash -d co=/home/luca/Documents/dev -hash -d dl=/home/luca/Downloads -hash -d dm=/home/luca/Documents -hash -d dk=/home/luca/Desktop -hash -d ms=/home/luca/Music -hash -d pc=/home/luca/Pictures -hash -d vd=/home/luca/Videos -hash -d dot=/home/luca/.local/share/stow/dots -hash -d lg=/home/luca/.local/log -hash -d sv=/home/luca/.local/sv -hash -d bf=/home/luca/.config/bookmarks/files -hash -d bd=/home/luca/.config/bookmarks/directories diff --git a/.local/bin/shortcuts b/.local/bin/shortcuts index 9d65de177..8983f9e17 100755 --- a/.local/bin/shortcuts +++ b/.local/bin/shortcuts @@ -1,23 +1,20 @@ #!/bin/sh # Inputs -bmdirs="$XDG_CONFIG_HOME/bookmarks/directories" -bmfiles="$XDG_CONFIG_HOME/bookmarks/files" +bmdirs="$XDG_CONFIG_HOME/directories" # Outputs zsh_named_dirs="$ZDOTDIR/configs/hashes" -lf_files="$XDG_DATA_HOME/lf/shortcut-files" -lf_dirs="$XDG_DATA_HOME/lf/shortcut-dirs" -lf_shortcuts="$XDG_CONFIG_HOME/lf/shortcutrc" +lf_dirs="$XDG_DATA_HOME/lf/dirs" +# TODO: Finish this function LOL find_marker() { file=$1 for marker in \ "# @SHORTCUTS@" \ "-- @SHORTCUTS@" \ "// @SHORTCUTS@" \ - "/* @SHORTCUTS@ */" - do + "/* @SHORTCUTS@ */"; do file=$(grep -xn "$marker" "$file") if [ -n "$file" ]; then echo "$file" @@ -38,31 +35,17 @@ write_dirs_tmp() { mkdir -p /tmp/shortcuts while IFS= read -r line; do shortcut=$(echo "$line" | cut -d' ' -f1) - path=$(echo "$line" | cut -d' ' -f2); path=$(eval "echo $path") + path=$(echo "$line" | cut -d' ' -f2) + path=$(eval "echo $path") printf "hash -d %s=%s\n" "$shortcut" "$path" >>"/tmp/shortcuts/zsh_named_dirs" - printf "map g%s cd \"%s\"\n" "$shortcut" "$path" >>"/tmp/shortcuts/lf_shortcuts" - printf "map %s" "$path" >>"/tmp/shortcuts/lf_dirs" + printf "%\t%s\n" "$shortcut" "$path" >>"/tmp/shortcuts/lf_dirs" done } -write_files_tmp() { - read -r contents - mkdir -p /tmp/shortcuts - - shortcut=$(echo "$contents" | cut -d' ' -f1) - path=$(echo "$contents" | cut -d' ' -f2); - - printf "hash -d %s=%s\n" "$shortcut" "$path" >>"/tmp/shortcuts/zsh_named_dirs" - printf "map %s" "$path" >>"/tmp/shortcuts/lf_files" - -} - apply_tmp() { cat /tmp/shortcuts/zsh_named_dirs >"$zsh_named_dirs" - cat /tmp/shortcuts/lf_shortcuts >"$lf_shortcuts" cat /tmp/shortcuts/lf_dirs >"$lf_dirs" - cat /tmp/shortcuts/lf_files >"$lf_files" } read_file() { @@ -70,10 +53,9 @@ read_file() { sed 's/#.*//;/^$/d' "$in_file" | tr -s ' ' } -clean +trap clean EXIT read_file "$bmdirs" | write_dirs_tmp -read_file "$bmfiles" | write_files_tmp apply_tmp diff --git a/TODO.md b/TODO.md index 1874e024e..552ea99a9 100644 --- a/TODO.md +++ b/TODO.md @@ -2,3 +2,5 @@ - [ ] Refactor Neovim config - [ ] Plumbing script! something to handle URLs, filepaths, and other stuff - [ ] TMUX w/ Sixel support +- [ ] Finish testing shortcuts script +- [ ] Continue work on shortcuts script