Mini fzf media launcher (file explorer)


Mini fzf media launcher (file explorer)

Below is a small media launcher for Linux/BASH, using, as always fzf :) You can use it to navigate, through directories and select media files to launch with your favorite media player. Of course the script can accept many improvements and it's only basic, but i am leaving this to you, as i wanted it for a specific reason, which is full filled as it is.

#!/usr/bin/bash

media="mpv"
audio="audacious"

function list_dirs {
  dirs=("..") # Add ".." to the array
  dirs+=( "$(exa --classify --group-directories-first -1 ${PWD} | sed "s/\*$//g")" )
  printf "%s\n" "${dirs[@]}"
}

while :; do
  sel="$(list_dirs | fzf --header "${PWD}")"
  if [ -d "$PWD/$sel" ]; then
    cd "$sel"
  fi
  if [ -z "$sel" ]; then
    exit
  fi
  if [ -f "$PWD/$sel" ]; then
    case "$sel" in 
      *.avi) $media "$PWD/$sel";;
      *.mkv) $media "$PWD/$sel";;
      *.mp4) $media "$PWD/$sel";;
      *.webm) $media "$PWD/$sel";;
      *.mp3) $audio "$PWD/$sel";;
    esac
  fi
done

Add a comment

Previous Next