summaryrefslogtreecommitdiff
path: root/lf
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2022-10-05 22:00:32 -0500
committerzachir <zachir@librem.one>2022-10-05 22:00:32 -0500
commitf39d735e2ba625a31a7dbf6fb8bdd62501379ad1 (patch)
treed17c96714c930e0b8bc75616cc9c81b961ed5aa0 /lf
Initial Commit
Diffstat (limited to 'lf')
-rwxr-xr-xlf/3q2
-rwxr-xr-xlf/cleaner4
-rwxr-xr-xlf/image18
-rw-r--r--lf/lfrc351
-rwxr-xr-xlf/preview83
5 files changed, 458 insertions, 0 deletions
diff --git a/lf/3q b/lf/3q
new file mode 100755
index 0000000..06ec272
--- /dev/null
+++ b/lf/3q
@@ -0,0 +1,2 @@
+#!/bin/sh
+chafa "$1"
diff --git a/lf/cleaner b/lf/cleaner
new file mode 100755
index 0000000..a184d84
--- /dev/null
+++ b/lf/cleaner
@@ -0,0 +1,4 @@
+#!/bin/sh
+if [ -n "$FIFO_UEBERZUG" ]; then
+ printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG"
+fi
diff --git a/lf/image b/lf/image
new file mode 100755
index 0000000..77ddb5b
--- /dev/null
+++ b/lf/image
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+readonly ID_PREVIEW="preview"
+main() {
+ case "$1" in
+ "clear")
+ declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
+ > "$FIFO_UEBERZUG"
+ ;;
+ "draw")
+ declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" \
+ [x]="$3" [y]="$4" [max_width]="$5" [max_height]="$6" \
+ [path]="$2") > "$FIFO_UEBERZUG"
+ ;;
+ "*") echo "Unknown command: '$1', '$2'" ;;
+ esac
+}
+main "$@"
+
diff --git a/lf/lfrc b/lf/lfrc
new file mode 100644
index 0000000..37c9fc7
--- /dev/null
+++ b/lf/lfrc
@@ -0,0 +1,351 @@
+set ratios 1:2:3
+set cleaner ~/.config/lf/cleaner
+set previewer ~/.config/lf/preview
+# Basic Settings
+set preview true
+set drawbox false
+set icons true
+set ignorecase true
+
+# Custom Functions
+cmd open ${{
+ case $(file --mime-type "$f" -bL) in
+ text/*|application/json) $EDITOR "$f";;
+ video/*) mpv "$f";;
+ audio/*) mpv "$f";;
+ application/pdf) zathura "$f" ;;
+ image/*) sxiv "$f" ;;
+ *) xdg-open "$f" ;;
+ esac
+}}
+
+cmd mkdir ${{
+ printf "Directory Name: "
+ read ans
+ mkdir $ans
+}}
+
+cmd mkfile ${{
+ printf "File Name: "
+ read ans
+ $EDITOR $ans
+}}
+
+cmd chmod ${{
+ printf "Mode Bits: "
+ read ans
+
+ for file in "$fx"
+ do
+ chmod $ans $file
+ done
+}}
+
+cmd sudomkfile ${{
+ printf "File Name: "
+ read ans
+ doas $EDITOR $ans
+}}
+
+cmd setwallpaper %cp "$f" ~/background.jpg && xwallpaper --center "$f"
+
+cmd fzf_jump ${{
+ res="$(find . -maxdepth 3 | fzf --reverse --header='Jump to location')"
+ if [ -f "$res" ]; then
+ cmd="select"
+ elif [ -d "$res" ]; then
+ cmd="cd"
+ fi
+ lf -remote "send $id $cmd \"$res\""
+}}
+
+cmd broot_jump ${{
+ f=$(mktemp)
+ res="$(broot --outcmd $f && cat $f | sed 's/cd //')"
+ rm -f "$f"
+ if [ -f "$res" ]; then
+ cmd="select"
+ elif [ -d "$res" ]; then
+ cmd="cd"
+ fi
+ lf -remote "send $id $cmd \"$res\""
+}}
+
+cmd open_config ${{
+ $EDITOR $(bookmenu -b ~/.config/bookmenu/configs -f fzf -o)
+}}
+
+cmd dragon %dragon-drop -a -x $fx
+cmd dragon-stay %dragon-drop -a $fx
+cmd dragon-individual %dragon-drop $fx
+cmd cpdragon %cpdragon
+cmd mvdragon %mvdragon
+cmd dlfile %dlfile
+
+# Archive bindings
+cmd unarchive ${{
+ case "$f" in
+ *.zip) unzip "$f" ;;
+ *.tar.gz) tar -xzvf "$f" ;;
+ *.tar.bz2) tar -xjvf "$f" ;;
+ *.tar.xz) tar -xJvf "$f" ;;
+ *.tar) tar -xvf "$f" ;;
+ *) echo "Unsupported format" ;;
+ esac
+}}
+
+cmd gitpull ${{
+ git pull
+ read dummy
+}}
+
+cmd gitadd ${{
+ git add $(basename $fx)
+}}
+
+cmd gitaddall ${{
+ git add .
+}}
+
+cmd gitpush ${{
+ git push
+ read dummy
+}}
+
+cmd gitcommit ${{
+ git commit -S
+}}
+
+cmd gitdiff ${{
+ git diff
+ read dummy
+}}
+
+cmd gitdifffile ${{
+ git diff `basename $fx`
+ read dummy
+}}
+
+cmd gitstatus ${{
+ git status | less
+}}
+
+cmd gitrestore ${{
+ git restore `basename $fx`
+ read dummy
+}}
+
+cmd gitsubmoduleupdate ${{
+ git submodule update
+ read dummy
+}}
+
+cmd gitsubmoduleinit ${{
+ git submodule update --init
+ read dummy
+}}
+
+cmd gitsubmoduleadd ${{
+ read url
+ read folder
+ git submodule add "$url" "$folder"
+ read dummy
+}}
+
+cmd make ${{
+ make -j4 all
+ read dummy
+}}
+
+cmd makeinstall ${{
+ sudo make -j4 install
+ read dummy
+}}
+
+cmd makeclean ${{
+ make -j4 clean
+ read dummy
+}}
+
+cmd openshell ${{
+ zsh
+}}
+
+cmd catclip ${{
+ catclip "$fx"
+}}
+
+cmd zip %zip -r "$f" "$f"
+cmd tar %tar cvf "$f.tar" "$f"
+cmd targz %tar cvzf "$f.tar.gz" "$f"
+cmd tarbz2 %tar cjvf "$f.tar.bz2" "$f"
+
+# Trash cli bindings
+cmd trash ${{
+ files=$(printf "$fx" | tr '\n' ';')
+ while [ "$files" ]; do
+ # extract the substring from start of string up to delimiter.
+ # this is the first "element" of the string.
+ file=${files%%;*}
+
+ trash-put "$(basename "$file")"
+ # if there's only one element left, set `files` to an empty string.
+ # this causes us to exit this `while` loop.
+ # else, we delete the first "element" of the string from files, and move onto the next.
+ if [ "$files" = "$file" ]; then
+ files=''
+ else
+ files="${files#*;}"
+ fi
+ done
+}}
+
+cmd clear_trash %trash-empty
+
+cmd restore_trash ${{
+ trash-restore
+}}
+
+cmd stripspace %stripspace "$f"
+
+# Bindings
+# Remove some defaults
+map m
+map o
+map n
+map "'"
+map '"'
+map d
+map c
+map e
+map f
+map ,
+
+# ZachIR bindings
+map ,gp gitpull
+map ,gP gitpush
+map ,gc gitcommit
+map ,ga gitadd
+map ,gA gitaddall
+map ,gd gitdifffile
+map ,gD gitdiff
+map ,gu gitsubmoduleupdate
+map ,gi gitsubmoduleinit
+map ,gm gitsubmoduleadd
+map ,gs gitstatus
+map ,gr gitrestore
+map ,mk make
+map ,mi makeinstall
+map ,mC makeclean
+map ,ss openshell
+map ,sc catclip
+
+
+# Not really image preview
+map - $~/.config/lf/draw_img "$f"
+
+cmd video_preview ${{
+ CACHE=$(mktemp /tmp/thumb_cache.XXXXX)
+ ffmpegthumbnailer -i "$f" -o $CACHE -s 0
+ ~/.config/lf/draw_img $CACHE && rm $CACHE
+}}
+map + :video_preview
+
+# File Openers
+map ee $$EDITOR "$f"
+map u $view "$f"
+
+# Archive Mappings
+map az zip
+map at tar
+map ag targz
+map ab targz
+map au unarchive
+
+# Trash Mappings
+map dd trash
+map tc clear_trash
+map tr restore_trash
+
+# Broot Mapping
+map f broot_jump
+
+# Dragon Mapping
+map dr dragon
+map ds dragon-stay
+map di dragon-individual
+map dm mvdragon
+map dc cpdragon
+map dl dlfile
+
+map ss stripspace
+
+# Basic Functions
+map . set hidden!
+map DD delete
+map p paste
+map x cut
+map y copy
+map <enter> open
+map mf mkfile
+map mr sudomkfile
+map md mkdir
+map ms $mkscript
+map ch chmod
+map bg setwallpaper
+map o open_config
+map br $vimv $fx
+map r rename
+map H top
+map L bottom
+map R reload
+map C clear
+map U unselect
+
+# Movement
+map ga cd ~/.config/awesome
+map gb cd ~/.local/bin
+map gc cd ~/.config
+map gdc cd ~/Documents
+map gdo cd ~/Downloads
+map gdw cd ~/suckless/dwm
+map gdb cd ~/.local/src/dwmbar
+map ge cd ~/Desktop
+map gE cd /etc
+map gf cd ~/.var/app
+map glb cd ~/.local/bin
+map glc cd ~/Games/cache
+map gls cd ~/.local/share
+map glf cd ~/.config/lf
+map gnv cd ~/.config/nvim
+map gns cd ~/.natvst
+map gp cd ~/Pictures
+map gqc cd ~/.config/qutebrowser
+map gqp cd ~/.local/share/qutebrowser-profiles
+map gqt cd ~/.config/qtile
+map gre cd ~/.local/src
+map grs cd /etc/runit/sv
+map gsc cd ~/.local/scripts
+map gsh cd ~/.config/sh
+map gsl cd ~/.local/src/slock
+map gss cd /etc/s6/sv
+map gsx cd ~/.config/sxhkd
+map gtr cd ~/.local/share/Trash/files
+map gU. cd /usr
+map gUs cd /usr/share
+map gva cd ~/.var
+map gVa cd /var
+map gvi cd ~/Videos
+map gvs cd ~/.vst
+map gv3 cd ~/.vst3
+map gwa cd ~/git/wallpapers
+map gwd cd ~/.local/share/wineprefixes/default
+map gwD cd ~/.local/share/wineprefixes/default/drive_c/users/zachir/Downloads
+map gwr cd ~/.local/share/wineprefixes
+map gww cd ~/.local/share/wineprefixes/work
+map gx cd ~/.config/X11
+map gyb cd ~/.cache/yay
+map gyc cd ~/.config/yay
+map gzs cd ~/.config/zsh
+map gzx cd ~/Documents/zachir.xyz
+
diff --git a/lf/preview b/lf/preview
new file mode 100755
index 0000000..4b70b2e
--- /dev/null
+++ b/lf/preview
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+image() {
+ if [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
+ printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' "$4" "$5" "$(($2-1))" "$(($3-1))" "$1" > "$FIFO_UEBERZUG"
+ exit 1
+ else
+ chafa "$1" -s "$4x"
+ fi
+}
+
+batorcat() {
+ file="$1"
+ shift
+ if command -v bat > /dev/null 2>&1
+ then
+ bat --color=always --style=plain --pager=never "$file" "$@"
+ else
+ cat "$file"
+ fi
+}
+
+CACHE="$HOME/.cache/lf/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}'))"
+
+case "$(printf "%s\n" "$(readlink -f "$1")" | awk '{print tolower($0)}')" in
+ *.tgz|*.tar.gz) tar tzf "$1" ;;
+ *.tar.bz2|*.tbz2) tar tjf "$1" ;;
+ *.tar.txz|*.txz) xz --list "$1" ;;
+ *.tar) tar tf "$1" ;;
+ *.zip|*.jar|*.war|*.ear|*.oxt) unzip -l "$1" ;;
+ *.rar) unrar l "$1" ;;
+ *.md) glow -s dark "$1" ;;
+ *.7z) 7z l "$1" ;;
+ *.[1-8]) man "$1" | col -b ;;
+ *.o) nm "$1";;
+ *.torrent) transmission-show "$1" ;;
+ *.iso) iso-info --no-header -l "$1" ;;
+ *.odt|*.ods|*.odp|*.sxw) odt2txt "$1" ;;
+ *.doc) catdoc "$1" ;;
+ *.docx) docx2txt "$1" - ;;
+ *.xml|*.html) w3m -dump "$1";;
+ *.xls|*.xlsx)
+ ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv
+ ;;
+ *.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx]|*.mka)
+ exiftool "$1"
+ ;;
+ *.pdf)
+ [ ! -f "${CACHE}.jpg" ] && \
+ pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
+ image "${CACHE}.jpg" "$2" "$3" "$4" "$5"
+ ;;
+ *.epub)
+ [ ! -f "$CACHE" ] && \
+ epub-thumbnailer "$1" "$CACHE" 1024
+ image "$CACHE" "$2" "$3" "$4" "$5"
+ ;;
+ *.cbz|*.cbr|*.cbt)
+ [ ! -f "$CACHE" ] && \
+ comicthumb "$1" "$CACHE" 1024
+ image "$CACHE" "$2" "$3" "$4" "$5"
+ ;;
+ *.avi|*.mp4|*.wmv|*.dat|*.3gp|*.ogv|*.mkv|*.mpg|*.mpeg|*.vob|*.fl[icv]|*.m2v|*.mov|*.webm|*.ts|*.mts|*.m4v|*.r[am]|*.qt|*.divx)
+ [ ! -f "${CACHE}.jpg" ] && \
+ ffmpegthumbnailer -i "$1" -o "${CACHE}.jpg" -s 0 -q 5
+ image "${CACHE}.jpg" "$2" "$3" "$4" "$5"
+ ;;
+ *.bmp|*.jpg|*.jpeg|*.png|*.xpm|*.webp|*.gif|*.jfif)
+ image "$1" "$2" "$3" "$4" "$5"
+ ;;
+ *.svg)
+ [ ! -f "${CACHE}.jpg" ] && \
+ convert "$1" "${CACHE}.jpg"
+ image "${CACHE}.jpg" "$2" "$3" "$4" "$5"
+ ;;
+ *.ino)
+ batorcat --language=cpp "$1"
+ ;;
+ *)
+ batorcat "$1"
+ ;;
+esac
+exit 0