summaryrefslogtreecommitdiff
path: root/lf
diff options
context:
space:
mode:
authorTimmy Keller <tjk@tjkeller.xyz>2021-07-07 15:21:45 -0500
committerTimmy Keller <tjk@tjkeller.xyz>2021-07-07 15:21:45 -0500
commit3764b268dbeaa95a8d4b2da8d4433eab75ad8478 (patch)
tree7c0db4481dfa7c4369f3db355056703cbe442072 /lf
downloaddotconfig-3764b268dbeaa95a8d4b2da8d4433eab75ad8478.tar.xz
dotconfig-3764b268dbeaa95a8d4b2da8d4433eab75ad8478.zip
dotfiles
Diffstat (limited to 'lf')
-rw-r--r--lf/draw_img67
-rw-r--r--lf/image18
-rw-r--r--lf/lfrc253
-rw-r--r--lf/preview48
4 files changed, 386 insertions, 0 deletions
diff --git a/lf/draw_img b/lf/draw_img
new file mode 100644
index 0000000..5a70d5e
--- /dev/null
+++ b/lf/draw_img
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+
+clear_screen() {
+ printf '\e[%sH\e[9999C\e[1J%b\e[1;%sr' \
+ "$((LINES-2))" "${TMUX:+\e[2J}" "$max_items"
+}
+
+# Get a file's mime_type.
+mime_type=$(file -bi "$1")
+
+# File isn't an image file, give warning.
+if [[ $mime_type != image/* ]]; then
+ lf -remote "send $id echoerr 'Not an image'"
+ exit
+fi
+
+w3m_paths=(/usr/{local/,}{lib,libexec,lib64,libexec64}/w3m/w3mi*)
+read -r w3m _ < <(type -p w3mimgdisplay "${w3m_paths[@]}")
+read -r LINES COLUMNS < <(stty size)
+
+# Get terminal window size in pixels and set it to WIDTH and HEIGHT.
+export $(xdotool getactivewindow getwindowgeometry --shell)
+
+# Get the image size in pixels.
+read -r img_width img_height < <("$w3m" <<< "5;${CACHE:-$1}")
+
+((img_width > WIDTH)) && {
+ ((img_height=img_height*WIDTH/img_width))
+ ((img_width=WIDTH))
+}
+
+((img_height > HEIGHT)) && {
+ ((img_width=img_width*HEIGHT/img_height))
+ ((img_height=HEIGHT))
+}
+
+# Variable needed for centering image.
+HALF_HEIGHT=$(expr $HEIGHT / 2)
+HALF_WIDTH=$(expr $WIDTH / 2)
+HALF_IMG_HEIGHT=$(expr $img_height / 2)
+HALF_IMG_WIDTH=$(expr $img_width / 2)
+X_POS=$(expr $HALF_WIDTH - $HALF_IMG_WIDTH)
+Y_POS=$(expr $HALF_HEIGHT - $HALF_IMG_HEIGHT)
+
+clear_screen
+# Hide the cursor.
+printf '\e[?25l'
+
+# Display the image.
+printf '0;1;%s;%s;%s;%s;;;;;%s\n3;\n4\n' \
+ ${X_POS:-0} \
+ ${Y_POS:-0} \
+ "$img_width" \
+ "$img_height" \
+ "${CACHE:-$1}" | "$w3m" &>/dev/null
+
+# Wait for user input.
+read -ern 1
+
+# Clear the image.
+printf '6;%s;%s;%s;%s\n3;' \
+ "${X_POS:-0}" \
+ "${Y_POS:-0}" \
+ "$WIDTH" \
+ "$HEIGHT" | "$w3m" &>/dev/null
+
+clear_screen
diff --git a/lf/image b/lf/image
new file mode 100644
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..0282a9e
--- /dev/null
+++ b/lf/lfrc
@@ -0,0 +1,253 @@
+# Basic Settings
+set previewer ~/scripts/lf/preview
+set preview true
+set hidden true
+#set drawbox true
+set icons true
+set ignorecase true
+
+# Custom Functions
+cmd open ${{
+ case $(file --mime-type "$f" -bL) in
+ text/*|application/json) $EDITOR "$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
+
+ lf -remote 'send reload'
+}}
+
+cmd sudomkfile ${{
+ printf "File Name: "
+ read ans
+ sudo $EDITOR $ans
+}}
+
+cmd setwallpaper %cp "$f" ~/.config/wall.png && xwallpaper --zoom "$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-drag-and-drop -a -x $fx
+cmd dragon-stay %dragon-drag-and-drop -a $fx
+cmd dragon-individual %dragon-drag-and-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) tar -xvf "$f" ;;
+ *) echo "Unsupported format" ;;
+ esac
+}}
+
+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
+
+# 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 gtr cd ~/.local/share/Trash/files
+map gus cd /run/media/brodie
+
+map gv. cd ~/videos
+map gva cd ~/videos/anime
+
+map gy. cd ~/videos/youtube
+map gyt cd ~/videos/youtube/ToUpload
+map gyu cd ~/videos/youtube/Uploaded
+map gya cd ~/videos/youtube/asset
+map go. cd ~/videos/podcast
+map got cd ~/videos/podcast/ToUpload
+map gou cd ~/videos/podcast/Uploaded
+
+map gp. cd ~/pictures
+map gpm cd ~/pictures/mpvscreenshots
+map gpa cd ~/pictures/Anime
+map gps cd ~/pictures/screenshots
+
+map gw. cd ~/pictures/Wallpapers
+map gww cd ~/pictures/Wallpapers/Wallpapers
+map gwm cd ~/pictures/Wallpapers/MobileWallpapers
+
+map gt. cd ~/documents/Textbooks
+map gt1 cd ~/documents/Textbooks/1stYear
+map gt2 cd ~/documents/Textbooks/2ndYear
+map gt3 cd ~/documents/Textbooks/3rdYear
+map gu3 cd ~/documents/Uni/3rdYear
+map gd cd ~/documents
+
+map gD cd ~/downloads
+map ge cd ~/desktop
+
+map gs. cd ~/scripts
+map gsl cd ~/scripts/lf
+map gsa cd ~/scripts/alsa
+map gsi cd ~/scripts/i3
+map gse cd ~/scripts/lemonbar
+map gsp cd ~/scripts/polybar
+map gsb cd ~/scripts/bspwm
+map gsu cd ~/scripts/pulse
+map gdt cd ~/scripts/transmission
+
+map gr. cd ~/repos
+map grb cd ~/repos/bookmenu
+map grf cd ~/repos/cleanfullscreen
+map grm cd ~/repos/dmenu
+map grd cd ~/repos/dotfiles
+map gri cd ~/repos/init
+map grk cd ~/repos/kanban-board
+map grl cd ~/repos/lbryurlconvert
+map grP cd ~/repos/PerlProjects
+map grr cd ~/repos/reading-list
+map grs cd ~/repos/st
+map grw cd ~/repos/website
+
+map gc cd ~/.config
+map gC cd ~/.local/share/cell
+map gl cd ~/.local
+map gE cd /etc
+map gU. cd /usr
+map gUs cd /usr/share
+
+map \;j cd ~
diff --git a/lf/preview b/lf/preview
new file mode 100644
index 0000000..3069a06
--- /dev/null
+++ b/lf/preview
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+# Clear the last preview (if any)
+$HOME/.config/lf/image clear
+
+# Calculate where the image should be placed on the screen.
+num=$(printf "%0.f\n" "`echo "$(tput cols) / 2" | bc`")
+numb=$(printf "%0.f\n" "`echo "$(tput cols) - $num - 1" | bc`")
+numc=$(printf "%0.f\n" "`echo "$(tput lines) - 2" | bc`")
+
+case "$1" 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";;
+ *.7z) 7z l "$1";;
+ *.[1-8]) man "$1" | col -b ;;
+ *.o) nm "$1" | less ;;
+ *.torrent) transmission-show "$1";;
+ *.iso) iso-info --no-header -l "$1";;
+ *odt,*.ods,*.odp,*.sxw) odt2txt "$1";;
+ *.doc) catdoc "$1" ;;
+ *.docx) docx2txt "$1" - ;;
+ *.csv) cat "$1" | sed s/,/\\n/g ;;
+ *.pdf)
+ CACHE=$(mktemp /tmp/thumbcache.XXXXX)
+ pdftoppm -png -f 1 -singlefile "$1" "$CACHE"
+ $HOME/.config/lf/image draw "$CACHE.png" $num 1 $numb $numc
+ ;;
+ *.epub)
+ CACHE=$(mktemp /tmp/thumbcache.XXXXX)
+ epub-thumbnailer "$1" "$CACHE" 1024
+ $HOME/.config/lf/image draw "$CACHE" $num 1 $numb $numc
+ ;;
+ *.bmp|*.jpg|*.jpeg|*.png|*.xpm)
+ $HOME/.config/lf/image draw "$1" $num 1 $numb $numc
+ ;;
+ *.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx]|*.flac) exiftool "$1";;
+ *.avi|*.mp4|*.wmv|*.dat|*.3gp|*.ogv|*.mkv|*.mpg|*.mpeg|*.vob|*.fl[icv]|*.m2v|*.mov|*.webm|*.ts|*.mts|*.m4v|*.r[am]|*.qt|*.divx)
+ CACHE=$(mktemp /tmp/thumbcache.XXXXX)
+ ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0
+ $HOME/.config/lf/image draw "$CACHE" $num 1 $numb $numc
+ ;;
+ *) highlight --out-format ansi "$1" || cat "$1";;
+esac
+