2024-04-23 04:34:15 +02:00
|
|
|
# Basic vars
|
|
|
|
set shellopts '-eu'
|
|
|
|
set ifs "\n"
|
2024-07-05 08:58:36 +02:00
|
|
|
set scrolloff 3
|
2024-04-23 04:34:15 +02:00
|
|
|
set icons
|
2024-05-16 18:23:57 +02:00
|
|
|
set nohidden
|
2024-04-23 04:34:15 +02:00
|
|
|
set period 1
|
|
|
|
set sortby ext
|
2024-07-13 09:45:45 +02:00
|
|
|
set hiddenfiles ".*:*.aux:*.log:*.bbl:*.bcf:*.blg:*.run.xml:*.srt"
|
2024-04-23 04:34:15 +02:00
|
|
|
set promptfmt "\033[32m \033[35;1m%d\033[0m\033[1m%f\033[0m"
|
|
|
|
set autoquit true
|
|
|
|
|
2024-07-05 04:01:24 +02:00
|
|
|
# Previewer
|
2024-04-23 04:34:15 +02:00
|
|
|
set previewer ctpv
|
|
|
|
set cleaner ctpvclear
|
|
|
|
&ctpv -s $id
|
|
|
|
&ctpvquit $id
|
|
|
|
|
2024-07-05 04:01:24 +02:00
|
|
|
# cmds/functions
|
2024-06-29 08:48:30 +02:00
|
|
|
cmd on-cd &{{
|
|
|
|
printf "\033]0; $PWD\007" > /dev/tty
|
|
|
|
export STARSHIP_SHELL=
|
|
|
|
fmt="$(starship prompt)"
|
|
|
|
lf -remote "send $id set promptfmt \"$fmt\""
|
|
|
|
}}
|
|
|
|
|
|
|
|
on-cd
|
|
|
|
|
2024-04-23 04:34:15 +02:00
|
|
|
cmd open ${{
|
|
|
|
case $(file --mime-type "$(readlink -f $f)" -b) in
|
|
|
|
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) localc $fx ;;
|
2024-05-16 18:23:57 +02:00
|
|
|
image/vnd.djvu|application/pdf|application/postscript) setsid -f zathura $fx >/dev/null 2>&1 ;;
|
2024-04-23 04:34:15 +02:00
|
|
|
text/html) $EDITOR $fx;;
|
|
|
|
text/*|application/json|inode/x-empty|application/x-subrip|application/javascript) $EDITOR $fx;;
|
|
|
|
image/x-xcf) setsid -f gimp $f >/dev/null 2>&1 ;;
|
|
|
|
image/svg+xml) display -- $f ;;
|
|
|
|
image/*) rotdir $f | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|avif\|tif\|ico\)\(_large\)*$" |
|
|
|
|
setsid -f nsxiv -aio 2>/dev/null | while read -r file; do
|
|
|
|
[ -z "$file" ] && continue
|
|
|
|
lf -remote "send select \"$file\""
|
|
|
|
lf -remote "send toggle"
|
|
|
|
done &
|
|
|
|
;;
|
2024-05-18 10:37:45 +02:00
|
|
|
audio/*|video/x-ms-asf) setsid -f mpv --loop-file --profile=builtin-pseudo-gui $f ;;
|
2024-04-23 04:34:15 +02:00
|
|
|
video/*) setsid -f mpv --loop-file $f -quiet >/dev/null 2>&1 ;;
|
|
|
|
application/pdf|application/vnd.djvu|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;;
|
|
|
|
application/pgp-encrypted) $EDITOR $fx ;;
|
2024-05-16 18:23:57 +02:00
|
|
|
application/vnd.openxmlformats-officedocument.wordprocessingml.document|application/vnd.oasis.opendocument.text|application/vnd.openxmlformats-officedocument.spreadsheetml.sheet|application/vnd.oasis.opendocument.spreadsheet|application/vnd.oasis.opendocument.spreadsheet-template|application/vnd.openxmlformats-officedocument.presentationml.presentation|application/vnd.oasis.opendocument.presentation-template|application/vnd.oasis.opendocument.presentation|application/vnd.ms-powerpoint|application/vnd.oasis.opendocument.graphics|application/vnd.oasis.opendocument.graphics-template|application/vnd.oasis.opendocument.formula|application/vnd.oasis.opendocument.database) setsid -f libreoffice $fx >/dev/null 2>&1 ;;
|
|
|
|
application/octet-stream) case ${f##*.} in
|
|
|
|
doc|docx|xls|xlsx|odt|ppt|pptx) setsid -f libreoffice $fx >/dev/null 2>&1 ;;
|
|
|
|
ghw) setsid -f gtkwave $f >/dev/null 2>&1 ;;
|
|
|
|
ts) setsid -f mpv $f -quiet >/dev/null 2>&1 ;;
|
|
|
|
*) setsid -f zathura $fx >/dev/null 2>&1 ;;
|
|
|
|
esac ;;
|
2024-04-23 04:34:15 +02:00
|
|
|
*) for f in $fx; do setsid -f $OPENER $f >/dev/null 2>&1; done;;
|
|
|
|
esac
|
|
|
|
}}
|
|
|
|
|
|
|
|
cmd fzf_search ${{
|
|
|
|
selected=$(fzf-fd)
|
|
|
|
if [ -n "$selected" ]; then
|
2024-06-29 08:48:05 +02:00
|
|
|
lf -remote "send $id set hidden"
|
|
|
|
lf -remote "send $id select $selected"
|
2024-04-23 04:34:15 +02:00
|
|
|
fi
|
|
|
|
}}
|
|
|
|
|
2024-04-27 13:24:27 +02:00
|
|
|
cmd live_server ${{
|
2024-04-27 18:01:42 +02:00
|
|
|
setsid -f live-server "$PWD"
|
2024-04-23 04:34:15 +02:00
|
|
|
}}
|
|
|
|
|
|
|
|
cmd extract ${{
|
|
|
|
clear; tput cup $(($(tput lines)/3)); tput bold
|
|
|
|
set -f
|
|
|
|
printf "%s\n\t" "$fx"
|
2024-07-05 08:58:36 +02:00
|
|
|
ans=$(echo -e "No\nYes" | fzf --prompt="Extract?" --ansi --border=rounded --margin=0,35% --no-info --height=7)
|
|
|
|
[ $ans = "Yes" ] && {
|
2024-04-23 04:34:15 +02:00
|
|
|
case $fx in
|
|
|
|
*.tar.bz2) tar xjf $fx ;;
|
|
|
|
*.tar.gz) tar xzf $fx ;;
|
|
|
|
*.bz2) bunzip2 $fx ;;
|
|
|
|
*.rar) unrar e $fx ;;
|
|
|
|
*.gz) gunzip $fx ;;
|
|
|
|
*.tar) tar xf $fx ;;
|
|
|
|
*.tbz2) tar xjf $fx ;;
|
|
|
|
*.tgz) tar xzf $fx ;;
|
|
|
|
*.zip) unzip $fx ;;
|
|
|
|
*.Z) uncompress $fx ;;
|
|
|
|
*.7z) 7z x $fx ;;
|
|
|
|
*.tar.xz) tar xf $fx ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
|
|
|
|
cmd delete ${{
|
|
|
|
clear; tput cup $(($(tput lines)/3)); tput bold
|
|
|
|
set -f
|
|
|
|
printf "%s\n\t" "$fx"
|
2024-07-05 08:58:36 +02:00
|
|
|
ans=$(echo -e "No\nYes" | fzf --prompt="Delete?" --ansi --border=rounded --margin=0,35% --no-info --height=7)
|
|
|
|
[ $ans = "Yes" ] && trash-put $fx
|
2024-04-23 04:34:15 +02:00
|
|
|
}}
|
|
|
|
|
|
|
|
cmd moveto ${{
|
|
|
|
clear; tput cup $(($(tput lines)/3)); tput bold
|
|
|
|
set -f
|
|
|
|
clear; echo "Move to where?"
|
|
|
|
dest="$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf | sed 's|~|$HOME|')" &&
|
|
|
|
for x in $fx; do
|
|
|
|
eval mv -iv \"$x\" \"$dest\"
|
|
|
|
done &&
|
|
|
|
notify-send "🚚 File(s) moved." "File(s) moved to $dest."
|
|
|
|
}}
|
|
|
|
|
|
|
|
cmd copyto ${{
|
|
|
|
clear; tput cup $(($(tput lines)/3)); tput bold
|
|
|
|
set -f
|
|
|
|
clear; echo "Copy to where?"
|
|
|
|
dest="$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf | sed 's|~|$HOME|')" &&
|
|
|
|
for x in $fx; do
|
|
|
|
eval cp -ivr \"$x\" \"$dest\"
|
|
|
|
done &&
|
|
|
|
notify-send "📋 File(s) copied." "File(s) copies to $dest."
|
|
|
|
}}
|
|
|
|
|
|
|
|
cmd bulkrename ${{
|
|
|
|
tmpfile_old="$(mktemp)"
|
|
|
|
tmpfile_new="$(mktemp)"
|
|
|
|
|
|
|
|
[ -n "$fs" ] && fs=$(basename -a $fs) || fs=$(ls)
|
|
|
|
|
|
|
|
echo "$fs" > "$tmpfile_old"
|
|
|
|
echo "$fs" > "$tmpfile_new"
|
|
|
|
$EDITOR "$tmpfile_new"
|
|
|
|
|
|
|
|
[ "$(wc -l < "$tmpfile_old")" -eq "$(wc -l < "$tmpfile_new")" ] || { rm -f "$tmpfile_old" "$tmpfile_new"; exit 1; }
|
|
|
|
|
|
|
|
paste "$tmpfile_old" "$tmpfile_new" | while IFS="$(printf '\t')" read -r src dst
|
|
|
|
do
|
|
|
|
[ "$src" = "$dst" ] || [ -e "$dst" ] || mv -- "$src" "$dst"
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -f "$tmpfile_old" "$tmpfile_new"
|
|
|
|
lf -remote "send $id unselect"
|
|
|
|
}}
|
|
|
|
|
|
|
|
cmd git_branch ${{
|
|
|
|
git branch | fzf | xargs git checkout
|
|
|
|
pwd_shell=$(pwd | sed 's/\\/\\\\/g;s/"/\\"/g')
|
|
|
|
lf -remote "send $id updir"
|
|
|
|
lf -remote "send $id cd \"$pwd_shell\""
|
|
|
|
}}
|
2024-07-05 04:01:24 +02:00
|
|
|
|
2024-06-29 08:48:30 +02:00
|
|
|
cmd git_root ${{
|
|
|
|
root="$(git rev-parse --show-toplevel 2>/dev/null)"
|
|
|
|
if [ -n "$root" ]; then
|
|
|
|
lf -remote "send $id cd $root"
|
|
|
|
else
|
|
|
|
printf "Not in a git repository"
|
|
|
|
read -r _
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}}
|
2024-04-23 04:34:15 +02:00
|
|
|
|
2024-05-13 18:33:56 +02:00
|
|
|
cmd sanitize ${{
|
|
|
|
set -f
|
|
|
|
sanitizefs ${fx}
|
|
|
|
# sanitizefs ${PWD}
|
|
|
|
}}
|
|
|
|
|
2024-06-29 08:48:30 +02:00
|
|
|
cmd resize-for-wallpaper ${{
|
|
|
|
resolution=$(xrandr | grep '*' | awk '{print $1}' | head -n 1)
|
|
|
|
default_resolution="1366x768"
|
|
|
|
if [ -z "$resolution" ]; then
|
|
|
|
resolution=$default_resolution
|
|
|
|
fi
|
|
|
|
for input_image in $fx; do
|
|
|
|
filename=$(basename "$input_image")
|
|
|
|
extension="${filename##*.}"
|
|
|
|
filename="${filename%.*}"
|
|
|
|
output_image="${filename}-${resolution}.${extension}"
|
|
|
|
magick "$input_image" -resize "$resolution" "$output_image"
|
|
|
|
done
|
|
|
|
}}
|
|
|
|
|
2024-07-13 09:45:45 +02:00
|
|
|
cmd extract-audio ${{
|
|
|
|
for video in $fx; do
|
|
|
|
# Check if the file is a video
|
|
|
|
mime_type=$(file --mime-type -b "$video")
|
|
|
|
if [[ $mime_type == video/* ]]; then
|
|
|
|
# Extract the filename without the extension
|
|
|
|
filename=$(basename -- "$video")
|
|
|
|
extension="${filename##*.}"
|
|
|
|
filename="${filename%.*}"
|
|
|
|
|
|
|
|
# Use ffmpeg to extract audio and save it as mp3
|
|
|
|
ffmpeg -i "$video" -q:a 0 -map a "${filename}.mp3"
|
|
|
|
echo "Audio extracted from $video and saved as ${filename}.mp3"
|
|
|
|
else
|
|
|
|
echo "$video is not a video file. Skipping."
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}}
|
|
|
|
|
2024-06-29 08:48:30 +02:00
|
|
|
cmd toggle_preview %{{
|
|
|
|
if [ "$lf_preview" = "true" ]; then
|
|
|
|
lf -remote "send $id :set preview false; set ratios 1:5"
|
|
|
|
else
|
|
|
|
lf -remote "send $id :set preview true; set ratios 1:2:3"
|
|
|
|
fi
|
|
|
|
}}
|
|
|
|
|
|
|
|
cmd change_preview %{{
|
|
|
|
if [ "$lf_previewer" = "ctpv" ]; then
|
|
|
|
lf -remote "send $id :set previewer exiftool; reload"
|
|
|
|
else
|
|
|
|
lf -remote "send $id :set previewer ctpv; reload"
|
|
|
|
fi
|
|
|
|
}}
|
|
|
|
|
2024-07-05 04:01:24 +02:00
|
|
|
cmd ff $ff "$(echo $*)"
|
2024-06-29 08:48:30 +02:00
|
|
|
cmd share $curl -F"file=@$fx" -Fexpires=24 https://0x0.st | xclip -selection c
|
2024-07-05 04:01:24 +02:00
|
|
|
cmd setbg "$1"
|
2024-06-29 08:48:30 +02:00
|
|
|
|
2024-04-23 04:34:15 +02:00
|
|
|
# Bindings
|
2024-06-25 13:52:46 +02:00
|
|
|
map <esc> :quit
|
2024-04-23 04:34:15 +02:00
|
|
|
map / :fzf_search
|
2024-06-29 08:48:30 +02:00
|
|
|
map ? $fzf-grep "$PWD"
|
|
|
|
map sw $setsid -f live-server "$PWD" >/dev/null 2>&1
|
2024-04-23 04:34:15 +02:00
|
|
|
map J $lf -remote "send $id cd $(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf)"
|
2024-05-13 18:33:56 +02:00
|
|
|
map r sanitize
|
2024-06-29 08:48:30 +02:00
|
|
|
map so $organize
|
|
|
|
map <c-b> resize-for-wallpaper
|
|
|
|
map gh $lazygit
|
2024-04-23 04:34:15 +02:00
|
|
|
map gg top
|
|
|
|
map D delete
|
|
|
|
map E extract
|
|
|
|
map C copyto
|
|
|
|
map M moveto
|
|
|
|
map <c-n> push :ff<space>
|
|
|
|
map <c-r> reload
|
2024-07-05 04:01:24 +02:00
|
|
|
map <c-s> share
|
2024-04-23 04:34:15 +02:00
|
|
|
map <enter> shell
|
|
|
|
map x $$f
|
|
|
|
map X !$f
|
|
|
|
map o &mimeopen "$f"
|
|
|
|
map O $mimeopen --ask "$f"
|
2024-05-13 18:33:56 +02:00
|
|
|
map a :rename; cmd-end # at the very end
|
2024-04-23 04:34:15 +02:00
|
|
|
map c push A<c-u> # new rename
|
|
|
|
map I :rename; cmd-home # at the very beginning
|
|
|
|
map i :rename # before extension
|
2024-05-13 18:33:56 +02:00
|
|
|
map A :rename; cmd-right # after extension
|
2024-04-23 04:34:15 +02:00
|
|
|
map B bulkrename
|
|
|
|
map b $setbg $f
|
|
|
|
map <c-e> down
|
|
|
|
map <c-y> up
|
|
|
|
map V push :!nvim<space>
|
|
|
|
map W $setsid -f $TERMINAL >/dev/null 2>&1
|
2024-06-25 13:52:46 +02:00
|
|
|
map . set hidden!
|
2024-05-16 18:23:57 +02:00
|
|
|
map U $printf "%s" "$fx" | xclip -selection clipboard
|
|
|
|
map u $printf "%s" "$fx" | sed 's/.*\///' | xclip -selection clipboard
|
|
|
|
map T $sxiv -t "$(pwd)" # opens thumbnail mode
|
|
|
|
map <c-l> unselect
|
2024-07-05 04:01:24 +02:00
|
|
|
map zp toggle_preview
|
|
|
|
map ze change_preview
|
|
|
|
map gb :git_branch
|
|
|
|
map gr :git_root
|
|
|
|
map gp ${{clear; git pull --rebase || true; echo "press ENTER"; read ENTER}}
|
|
|
|
map gs ${{clear; git status; echo "press ENTER"; read ENTER}}
|
|
|
|
map gl ${{clear; git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit}}
|