mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 00:00:13 -08:00
feat: Enhance Plex management with library scanner integration and bash completion support
This commit is contained in:
@@ -43,7 +43,7 @@ The completion system provides intelligent tab completion for command-line flags
|
||||
|
||||
- `--help`, `-h` - Show help message
|
||||
- `--dry-run` - Preview backup without executing
|
||||
- `--no-upload` - Skip B2 upload (local backup only)
|
||||
- `--no-upload` - Skip B2 upload (local backup only)
|
||||
- `--verbose` - Enable verbose logging
|
||||
|
||||
### backup-plex.sh
|
||||
@@ -187,7 +187,7 @@ backup-immich.sh --<TAB>
|
||||
# Relative path
|
||||
./backup-immich.sh --<TAB>
|
||||
|
||||
# Absolute path
|
||||
# Absolute path
|
||||
/home/acedanger/shell/immich/backup-immich.sh --<TAB>
|
||||
```
|
||||
|
||||
@@ -276,9 +276,9 @@ _script_name_completion() {
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
|
||||
opts="--option1 --option2 --option3"
|
||||
|
||||
|
||||
# Handle special cases
|
||||
case "${prev}" in
|
||||
--special-option)
|
||||
@@ -286,7 +286,7 @@ _script_name_completion() {
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# Standard flag completion
|
||||
if [[ ${cur} == -* ]]; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
|
||||
@@ -131,7 +131,7 @@ For commands that accept boolean flags:
|
||||
$ scan-plex-libraries.sh refresh 29 <TAB>
|
||||
true false
|
||||
|
||||
# Analyze with deep flag
|
||||
# Analyze with deep flag
|
||||
$ scan-plex-libraries.sh analyze 29 <TAB>
|
||||
true false
|
||||
```
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
# Bash completion for Plex-related scripts
|
||||
# Author: Peter Wood <peter@peterwood.dev>
|
||||
#
|
||||
#
|
||||
# This file provides intelligent tab completion for:
|
||||
# - plex.sh (main Plex management script)
|
||||
# - scan-plex-libraries.sh (library scanner script)
|
||||
@@ -16,16 +16,16 @@
|
||||
_plex_sh_completion() {
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
|
||||
# Available commands for plex.sh
|
||||
local commands="start stop restart status scan repair nuclear help"
|
||||
|
||||
|
||||
# If we're completing the first argument (command)
|
||||
if [[ ${COMP_CWORD} -eq 1 ]]; then
|
||||
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
||||
# If previous word was 'scan', complete with scanner options
|
||||
if [[ "$prev" == "scan" ]]; then
|
||||
local scanner_commands="list scan refresh analyze generate tree interactive"
|
||||
@@ -33,7 +33,7 @@ _plex_sh_completion() {
|
||||
COMPREPLY=($(compgen -W "$scanner_commands $scanner_options" -- "$cur"))
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
||||
# For other commands, no additional completion needed
|
||||
return 0
|
||||
}
|
||||
@@ -42,11 +42,11 @@ _plex_sh_completion() {
|
||||
_scan_plex_libraries_completion() {
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
|
||||
# Available commands for scan-plex-libraries.sh
|
||||
local commands="list scan refresh analyze generate tree interactive"
|
||||
local options="-v --verbose -h --help"
|
||||
|
||||
|
||||
# If we're completing the first argument
|
||||
if [[ ${COMP_CWORD} -eq 1 ]]; then
|
||||
# If it starts with -, show options
|
||||
@@ -57,7 +57,7 @@ _scan_plex_libraries_completion() {
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
||||
# Handle specific command completions
|
||||
case "${COMP_WORDS[1]}" in
|
||||
refresh)
|
||||
@@ -79,19 +79,19 @@ _scan_plex_libraries_completion() {
|
||||
# Could potentially call the script to get section IDs but that's expensive
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Completion function for generic plex aliases that might pass through to plex.sh
|
||||
_plex_alias_completion() {
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
|
||||
# For plex-scan alias, complete with scanner commands
|
||||
if [[ "${COMP_WORDS[0]}" == *"plex-scan"* ]]; then
|
||||
local scanner_commands="list scan refresh analyze generate tree interactive"
|
||||
local scanner_options="-v --verbose -h --help"
|
||||
|
||||
|
||||
if [[ ${COMP_CWORD} -eq 1 ]]; then
|
||||
if [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "$scanner_options" -- "$cur"))
|
||||
@@ -105,13 +105,13 @@ _plex_alias_completion() {
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
||||
# For plex-scanner alias, use the full scanner completion
|
||||
if [[ "${COMP_WORDS[0]}" == *"plex-scanner"* ]]; then
|
||||
_scan_plex_libraries_completion
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
||||
# For other plex aliases, just complete with main plex.sh commands
|
||||
local commands="start stop restart status scan repair nuclear help"
|
||||
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
|
||||
@@ -123,10 +123,10 @@ _plex_alias_completion() {
|
||||
_plex_scanner_with_sections() {
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
|
||||
# First try the basic completion
|
||||
_scan_plex_libraries_completion
|
||||
|
||||
|
||||
# If we didn't get any completions and we're looking for a section ID
|
||||
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
|
||||
case "${COMP_WORDS[1]}" in
|
||||
@@ -136,14 +136,14 @@ _plex_scanner_with_sections() {
|
||||
# Attempt to get section IDs from the scanner
|
||||
local script_dir="$(dirname "${COMP_WORDS[0]}")"
|
||||
local scanner_script=""
|
||||
|
||||
|
||||
# Try to find the scanner script
|
||||
if [[ -f "$script_dir/scan-plex-libraries.sh" ]]; then
|
||||
scanner_script="$script_dir/scan-plex-libraries.sh"
|
||||
elif [[ -f "/home/acedanger/shell/plex/scan-plex-libraries.sh" ]]; then
|
||||
scanner_script="/home/acedanger/shell/plex/scan-plex-libraries.sh"
|
||||
fi
|
||||
|
||||
|
||||
if [[ -n "$scanner_script" ]]; then
|
||||
# Attempt to get section IDs (with timeout to avoid hanging)
|
||||
local section_ids
|
||||
@@ -155,7 +155,7 @@ _plex_scanner_with_sections() {
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ _plex_list_sections() {
|
||||
_plex_extended_completion() {
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local cmd="${COMP_WORDS[0]}"
|
||||
|
||||
|
||||
# This function can be extended for future plex-related commands
|
||||
case "$cmd" in
|
||||
*plex-backup*)
|
||||
@@ -209,7 +209,7 @@ _plex_extended_completion() {
|
||||
# If restore scripts get their own completion, handle here
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user