Skip to content

Instantly share code, notes, and snippets.

@CIAvash
Last active June 16, 2021 10:11
Show Gist options
  • Save CIAvash/0be3a112d4d4f24de557c11c19ec53a9 to your computer and use it in GitHub Desktop.
Save CIAvash/0be3a112d4d4f24de557c11c19ec53a9 to your computer and use it in GitHub Desktop.
A solution for opening a file and the other files residing in the same directory, while maintaining position. For VLC playlist(video, audio) and imv(image)
#!/usr/bin/env bash
# Gets a filename and a file type, returns the files with the same type in the same directory
function find_files_by_type {
directory=$(dirname -- "$1")
items=$(fd . "$directory" --exact-depth 1 -t f -x file --mime-type '{}' | rg "$2" | perl -ne 's/:\s+.*$//; print' | sort -V)
echo "$items"
}
#!/usr/bin/env bash
source "${0%/*}"/find_files.sh
IFS=$'\n'
images=$(find_files_by_type "$1" 'image')
index=$(echo "$images" | rg -n "$1" | cut -d : -f 1)
imv -n $index $images
#!/usr/bin/env bash
source "${0%/*}"/find_files.sh
IFS=$'\n'
items=$(find_files_by_type "$1" 'video|audio')
index=$(($(echo "$items" | rg -n "$1" | cut -d : -f 1) - 1))
items_array=($items)
sorted_items=(${items_array[@]:$index:$((${#items_array[@]} - $index))})
sorted_items+=(${items_array[@]:0:$index})
vlc ${sorted_items[@]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment