Improve vifm backgrounding

This commit is contained in:
Akemi Izuko 2023-12-23 20:13:53 -07:00
parent 34a980fb9f
commit 23ab938841
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
6 changed files with 79 additions and 31 deletions

View file

@ -44,6 +44,19 @@ vifmmv() {
cd "$dst"
}
# Open command script in vim
viw() {
if [[ -z "$1" ]] || ! which "$1"; then
printf "No %s found in path\nAborting...\n" "$1"
exit 1
elif [[ "$(file "$(which "$1")")" =~ 'ELF.*executable' ]]; then
printf "%s is a binary\nAborting...\n" "$1"
exit 1
else
"$EDITOR" "$(which "$1")"
fi
}
# Better exiting ====================================================
# Don't exit with background jobs still running. Particularly for Qemu
function exit () {

View file

@ -24,8 +24,6 @@ upower --dump | awk '
else
printf "==== %s ========\n", device[dev]["name"];
asort(device[dev]);
for (i in device[dev]) {
is_name = (tolower(device[dev][i]) ~ /(device|model)/);
is_label = (device[dev][i] ~ /:/);

View file

@ -244,7 +244,7 @@ output DP-3 scale 2
default_border pixel 2
# Adjust gamma. More important for external displays. Laptops are usually fine
exec wlsunset -t 4000 -T 6500 -g 0.9
exec wlsunset -t 6499 -T 6500 -g 0.9
# Volume controls
bindsym XF86AudioRaiseVolume exec $volume_command 4 $volume_notify_sound

View file

@ -2,6 +2,9 @@ show-failed-attempts
image=~/.config/swaylock/default_wallpaper.png
bs-hl-color=83A598
scaling=fit
color=000000
indicator-radius=60
indicator-thickness=20

View file

@ -1,48 +1,84 @@
#!/usr/bin/env bash
print_help() {
cat <<HELP
Open given files in backgrounded programs, preferably using GUI apps
Open given files in backgrounded programs, preferably using GUI apps and tmux
Intended for use with vifm
Intended for use with vifm + tmux
HELP
}
test -z "${SWAYSOCK+x}"
declare -r is_gui=$?
requires_gui_error() {
printf 'Sway not running. Will not open gui apps\n' >&2
exit 1
}
open_pdf() {
zathura "$1" &
}
open_image() {
imv "$1" &
}
open_av_media() {
local has_video="$(ffprobe -hide_banner "$1" 2>&1 | awk '/Stream.+Video/')"
if [[ -n "$TMUX" && -z "$has_video" ]] || [[ ! $is_gui && -n "$TMUX" ]]; then
tmux split-window -h
sleep .2 # Let bash login, otherwise command won't get sent
tmux send-keys "mpv $1" Enter
elif [[ $is_gui ]]; then
mpv --force-window "$1" &>/dev/null &
fi
}
open_webpage() {
chromium "$1" &>/dev/null &
}
open_vim() {
tmux new-window -c "#{pane_current_path}"
sleep .2 # Let bash login, otherwise command won't get sent
tmux send-keys "vi $1" Enter
}
open_file() {
case "${1##*.}" in
pdf)
zathura "$1" &
if [[ $is_gui ]]; then
open_pdf "$1"
else
requires_gui_error
fi
;;
avif|icns|jpeg|jpg|png|webp)
imv "$1" &
if [[ $is_gui ]]; then
open_image "$1"
else
requires_gui_error
fi
;;
mkv|mp3|mp4|webm)
local has_video="$(ffprobe -hide_banner "$1" 2>&1 | awk '/Stream.+Video/')"
if [[ -n "$TMUX" && -z "$has_video" ]]; then
tmux split-window -h
sleep .2 # Let bash login, otherwise command won't get sent
tmux send-keys "mpv $1" Enter
else
mpv --force-window "$1" &>/dev/null &
fi
open_av_media "$1"
;;
html)
chromium "$1" &>/dev/null &
if [[ $is_gui ]]; then
open_webpage "$1"
else
requires_gui_error
fi
;;
*)
if [[ -n "$TMUX" ]] && file "$1" | grep -iq 'ascii'; then
tmux new-window -c "#{pane_current_path}"
sleep .2 # Let bash login, otherwise command won't get sent
tmux send-keys "vi $1" Enter
if [[ -n "$TMUX" && -f "$1" && "$(stat -c%s "$1")" -le 1000000 ]]; then
open_vim "$1"
fi
;;
esac
}
if [[ -z ${SWAYSOCK+x} ]]; then
printf 'Sway not running. Will not open gui apps\n' >&2
exit 1
fi
for arg in "$@"
do
case "$arg" in
@ -55,5 +91,3 @@ do
;;
esac
done
#swaymsg [con_mark=vifm_window] focus

View file

@ -270,9 +270,9 @@ command! fdcddir
command! fdeditfiles
\ :if $TMUX != '' && &columns > 90
\ | exe 'edit "'.system('fd -HE ''.git'' -t f . | fzf-tmux -p 90,30').'"'
\ | exe '!~/.configs_pointer/vifm/scripts/vifm_bg_open.sh "'.system('fd -HE ''.git'' -t f . | fzf-tmux -p 90,30').'"'
\ | else
\ | exe 'edit "'.term('fd -HE ''.git'' -t f . | fzf 2>/dev/tty').'"'
\ | exe '!~/.configs_pointer/vifm/scripts/vifm_bg_open.sh "'.term('fd -HE ''.git'' -t f . | fzf 2>/dev/tty').'"'
\ | endif
command! fdmvcursor
@ -328,7 +328,7 @@ fileviewer *[^/] env -uCOLORTERM bat --color always --theme ansi --wrap never --
filetype *.mp4,*.mkv,*.mov,*.webm,*.mp3,*.flac mpv %c
if system('uname') == 'Darwin'
if system('uname -s') == 'Darwin'
filetype *.jpg,*.jpeg,*.png,*.icns open -a Preview.app %c:p
filetype *.pdf open -a 'skim' %c || open %c:p
else