Improve vifm backgrounding

This commit is contained in:
Akemi Izuko 2022-09-27 23:29:44 -06:00
parent 7e56974965
commit 9868caafe1
No known key found for this signature in database
GPG key ID: 905D444F6A5E4BE4
6 changed files with 79 additions and 31 deletions

View file

@ -44,6 +44,19 @@ vifmmv() {
cd "$dst" 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 ==================================================== # Better exiting ====================================================
# Don't exit with background jobs still running. Particularly for Qemu # Don't exit with background jobs still running. Particularly for Qemu
function exit () { function exit () {

View file

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

View file

@ -244,7 +244,7 @@ output DP-3 scale 2
default_border pixel 2 default_border pixel 2
# Adjust gamma. More important for external displays. Laptops are usually fine # 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 # Volume controls
bindsym XF86AudioRaiseVolume exec $volume_command 4 $volume_notify_sound bindsym XF86AudioRaiseVolume exec $volume_command 4 $volume_notify_sound

View file

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

View file

@ -1,48 +1,84 @@
#!/usr/bin/env bash #!/usr/bin/env bash
print_help() { print_help() {
cat <<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 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() { open_file() {
case "${1##*.}" in case "${1##*.}" in
pdf) pdf)
zathura "$1" & if [[ $is_gui ]]; then
open_pdf "$1"
else
requires_gui_error
fi
;; ;;
avif|icns|jpeg|jpg|png|webp) avif|icns|jpeg|jpg|png|webp)
imv "$1" & if [[ $is_gui ]]; then
open_image "$1"
else
requires_gui_error
fi
;; ;;
mkv|mp3|mp4|webm) mkv|mp3|mp4|webm)
local has_video="$(ffprobe -hide_banner "$1" 2>&1 | awk '/Stream.+Video/')" open_av_media "$1"
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
;; ;;
html) 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 if [[ -n "$TMUX" && -f "$1" && "$(stat -c%s "$1")" -le 1000000 ]]; then
tmux new-window -c "#{pane_current_path}" open_vim "$1"
sleep .2 # Let bash login, otherwise command won't get sent
tmux send-keys "vi $1" Enter
fi fi
;;
esac esac
} }
if [[ -z ${SWAYSOCK+x} ]]; then
printf 'Sway not running. Will not open gui apps\n' >&2
exit 1
fi
for arg in "$@" for arg in "$@"
do do
case "$arg" in case "$arg" in
@ -55,5 +91,3 @@ do
;; ;;
esac esac
done done
#swaymsg [con_mark=vifm_window] focus

View file

@ -270,9 +270,9 @@ command! fdcddir
command! fdeditfiles command! fdeditfiles
\ :if $TMUX != '' && &columns > 90 \ :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 \ | 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 \ | endif
command! fdmvcursor 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 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 *.jpg,*.jpeg,*.png,*.icns open -a Preview.app %c:p
filetype *.pdf open -a 'skim' %c || open %c:p filetype *.pdf open -a 'skim' %c || open %c:p
else else