aboutsummaryrefslogtreecommitdiff
path: root/jellystack-autocomplete.bash
diff options
context:
space:
mode:
Diffstat (limited to 'jellystack-autocomplete.bash')
-rw-r--r--jellystack-autocomplete.bash89
1 files changed, 89 insertions, 0 deletions
diff --git a/jellystack-autocomplete.bash b/jellystack-autocomplete.bash
new file mode 100644
index 0000000..55ffad4
--- /dev/null
+++ b/jellystack-autocomplete.bash
@@ -0,0 +1,89 @@
+#!/bin/bash
+# File: jellystack-autocomplete.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="/mnt/public/Support/Programs/jellyfin/scripts/rescan-library.sh"
+
+_show_manager_confs() {
+ # reference: vm4:/etc/bash_completion.d/docker-nfs-check
+ local cur prev words cword;
+ _init_completion || return
+ _tmpfile1="$( mktemp )"
+ # populate list
+ find /mnt/public/Support/Programs/jellyfin/scripts/input -mindepth 1 -maxdepth 1 ! -type d -name '*.conf' -printf '%P\n' | sed -r -e 's/\.conf$//;' > "${_tmpfile1}"
+ COMPREPLY=($( compgen -W "$( cat ${_tmpfile1} )" -- "$cur" | sed -r -e "/^${prev}/d;" ))
+ command rm -rf "${_tmpfile1:-NOTHINGTODEL}" 1>/dev/null 2>&1
+ return 0
+} &&
+complete -F _show_manager_confs manage-show
+. /mnt/public/Support/Programs/jellyfin/scripts/show-manager.sh
+alias manage-show="manage_show"
bgstack15