diff options
author | B. Stack <bgstack15@gmail.com> | 2024-01-31 08:43:29 -0500 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2024-01-31 08:43:29 -0500 |
commit | b1ed46c64e689e0f22f1e94018a17f5c129d82a3 (patch) | |
tree | 8cfd3844ce825f93c0b00e0a2084343b0b2a3a52 /autocomplete-rescan.bash | |
download | jellystack-b1ed46c64e689e0f22f1e94018a17f5c129d82a3.tar.gz jellystack-b1ed46c64e689e0f22f1e94018a17f5c129d82a3.tar.bz2 jellystack-b1ed46c64e689e0f22f1e94018a17f5c129d82a3.zip |
initial commit
Diffstat (limited to 'autocomplete-rescan.bash')
-rw-r--r-- | autocomplete-rescan.bash | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/autocomplete-rescan.bash b/autocomplete-rescan.bash new file mode 100644 index 0000000..28787b2 --- /dev/null +++ b/autocomplete-rescan.bash @@ -0,0 +1,74 @@ +#!/bin/bash +# File: autocomplete-rescan.bash +# Location: /mnt/public/Support/Programs/jellyfin/scripts/ +# Author: bgstack15, pawamoy +# Startdate: 2024-01-28-1 21:40 +# SPDX-License-Identifier: CC-BY-SA-4.0 +# Title: Bash autocompletion for rescan-library +# Project: jellystack +# Purpose: Make it easy to choose a jellyfin library to rescan +# History: +# Usage: +# dot-source it and then alias the script: +# . /mnt/public/Support/Programs/jellyfin/autocmplete-rescan.bash +# alias rescan-library=/mnt/public/Support/Programs/jellyfin/rescan-library.sh +# Reference: +# 1. https://stackoverflow.com/questions/44453510/how-to-autocomplete-a-bash-commandline-with-file-paths-from-a-specific-directory/47799826#47799826 +# 2. https://stackoverflow.com/questions/1146098/properly-handling-spaces-and-quotes-in-bash-completion +# Improve: +# Dependencies: +# password stored in ~/.jellyfin.password +# jellystack.py frontend and jellystack_lib.py + +_complete_specific_path() { + # ripped from https://stackoverflow.com/questions/44453510/how-to-autocomplete-a-bash-commandline-with-file-paths-from-a-specific-directory/47799826#47799826 and modified for jellystack + # alt which did not work: https://stackoverflow.com/questions/1146098/properly-handling-spaces-and-quotes-in-bash-completion + /mnt/public/Support/Programs/jellyfin/scripts/jellystack.py --autocomplete 1>/dev/null # populates ~/.cache/jellystack + # declare variables + local _item _COMPREPLY _old_pwd + thisdir=~/.cache/jellystack + + # if we already are in the completed directory, skip this part + _old_pwd="${PWD}" + # magic here: go the specific directory! + pushd "${thisdir}" &>/dev/null || return + + # init completion and run _filedir inside specific directory + _init_completion -s || return + _filedir + + # iterate on original replies + for _item in "${COMPREPLY[@]}"; do + # this check seems complicated, but it handles the case + # where you have files/dirs of the same name + # in the current directory and in the completed one: + # we want only one "/" appended + #if [ -d "${_item}" ] && [[ "${_item}" != */ ]] && [ ! -d "${_old_pwd}/${_item}" ]; then + # # append a slash if directory + # _COMPREPLY+=("${_item}/") + #else + _COMPREPLY+=("${_item}") + #fi + done + + # popd as early as possible + popd &>/dev/null + + # if only one reply and it is a directory, don't append a space + # (don't know why we must check for length == 2 though) + if [ ${#_COMPREPLY[@]} -eq 2 ]; then + if [[ "${_COMPREPLY}" == */ ]]; then + compopt -o nospace + fi + fi + + # set the values in the right COMPREPLY variable + COMPREPLY=( "${_COMPREPLY[@]}" ) + + # clean up + unset _COMPREPLY + unset _item +} + +complete -F _complete_specific_path rescan-library +alias rescan-library="$( dirname "$( readlink -f "${0}" )" )/rescan-library.sh" |