mirror of
https://github.com/mintycube/dotfiles.git
synced 2024-10-22 14:05:41 +02:00
269 lines
8.4 KiB
Plaintext
269 lines
8.4 KiB
Plaintext
# Basic vars
|
|
set shellopts '-eu'
|
|
set ifs "\n"
|
|
set scrolloff 3
|
|
set icons
|
|
set nohidden
|
|
set period 1
|
|
set sortby ext
|
|
set hiddenfiles ".*:*.aux:*.log:*.bbl:*.bcf:*.blg:*.run.xml:*.srt"
|
|
set promptfmt "\033[32m \033[35;1m%d\033[0m\033[1m%f\033[0m"
|
|
set autoquit true
|
|
|
|
# Previewer
|
|
set previewer ctpv
|
|
set cleaner ctpvclear
|
|
&ctpv -s $id
|
|
&ctpvquit $id
|
|
|
|
# cmds/functions
|
|
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
|
|
|
|
cmd open ${{
|
|
case $(file --mime-type "$(readlink -f $f)" -b) in
|
|
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) localc $fx ;;
|
|
image/vnd.djvu|application/pdf|application/postscript) setsid -f zathura $fx >/dev/null 2>&1 ;;
|
|
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 &
|
|
;;
|
|
audio/*|video/x-ms-asf) setsid -f mpv --loop-file --profile=builtin-pseudo-gui $f ;;
|
|
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 ;;
|
|
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 ;;
|
|
*) 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
|
|
lf -remote "send $id set hidden"
|
|
lf -remote "send $id select $selected"
|
|
fi
|
|
}}
|
|
|
|
cmd live_server ${{
|
|
setsid -f live-server "$PWD"
|
|
}}
|
|
|
|
cmd extract ${{
|
|
clear; tput cup $(($(tput lines)/3)); tput bold
|
|
set -f
|
|
printf "%s\n\t" "$fx"
|
|
ans=$(echo -e "No\nYes" | fzf --prompt="Extract?" --ansi --border=rounded --margin=0,35% --no-info --height=7)
|
|
[ $ans = "Yes" ] && {
|
|
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"
|
|
ans=$(echo -e "No\nYes" | fzf --prompt="Delete?" --ansi --border=rounded --margin=0,35% --no-info --height=7)
|
|
[ $ans = "Yes" ] && trash-put $fx
|
|
}}
|
|
|
|
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\""
|
|
}}
|
|
|
|
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
|
|
}}
|
|
|
|
cmd sanitize ${{
|
|
set -f
|
|
sanitizefs ${fx}
|
|
# sanitizefs ${PWD}
|
|
}}
|
|
|
|
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
|
|
}}
|
|
|
|
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
|
|
}}
|
|
|
|
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
|
|
}}
|
|
|
|
cmd ff $ff "$(echo $*)"
|
|
cmd share $curl -F"file=@$fx" -Fexpires=24 https://0x0.st | xclip -selection c
|
|
cmd setbg "$1"
|
|
|
|
# Bindings
|
|
map <esc> :quit
|
|
map / :fzf_search
|
|
map ? $fzf-grep "$PWD"
|
|
map sw $setsid -f live-server "$PWD" >/dev/null 2>&1
|
|
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)"
|
|
map r sanitize
|
|
map so $organize
|
|
map <c-b> resize-for-wallpaper
|
|
map gh $lazygit
|
|
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
|
|
map <c-s> share
|
|
map <enter> shell
|
|
map x $$f
|
|
map X !$f
|
|
map o &mimeopen "$f"
|
|
map O $mimeopen --ask "$f"
|
|
map a :rename; cmd-end # at the very end
|
|
map c push A<c-u> # new rename
|
|
map I :rename; cmd-home # at the very beginning
|
|
map i :rename # before extension
|
|
map A :rename; cmd-right # after extension
|
|
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
|
|
map . set hidden!
|
|
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
|
|
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}}
|