Last active
June 16, 2021 10:11
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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