-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvrecord-completion.bash
More file actions
137 lines (125 loc) · 3.75 KB
/
vrecord-completion.bash
File metadata and controls
137 lines (125 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env bash
# vrecord-completion.bash - Bash completion for vrecord
#
# Installation:
# 1. Source this file in your ~/.bashrc or ~/.bash_profile:
# source /path/to/vrecord-completion.bash
#
# 2. Or copy to system completion directory:
# sudo cp vrecord-completion.bash /etc/bash_completion.d/vrecord
#
# Features:
# - Complete commands and options
# - Smart context-aware completions
# - File completion for -r/--resume
# - Option completion based on context
_vrecord_completions() {
local cur prev words cword
_init_completion || return
local commands="start pause resume stop status list help"
local global_opts="-n --no-mp3 -b --no-beep -v --verbose -q --quiet -h --help -V --version"
# Get the command if one has been specified
local cmd=""
local i
for ((i=1; i < cword; i++)); do
if [[ " $commands " == *" ${words[i]} "* ]]; then
cmd="${words[i]}"
break
fi
done
# If we're still looking for a command
if [[ -z "$cmd" ]]; then
case "$prev" in
-n|--no-mp3|-v|--verbose|-q|--quiet)
# After global options, suggest commands
mapfile -t COMPREPLY < <(compgen -W "$commands" -- "$cur")
return
;;
*)
# No command yet, show commands and global options
if [[ "$cur" == -* ]]; then
mapfile -t COMPREPLY < <(compgen -W "$global_opts" -- "$cur")
else
mapfile -t COMPREPLY < <(compgen -W "$commands" -- "$cur")
fi
return
;;
esac
fi
# Command-specific completions
case "$cmd" in
start)
case "$prev" in
start)
# After 'start', could be prefix or options
if [[ "$cur" == -* ]]; then
mapfile -t COMPREPLY < <(compgen -W "-c --continue-last -r --resume -t --transcribe" -- "$cur")
else
# Suggest some common prefixes
mapfile -t COMPREPLY < <(compgen -W "interview meeting lecture podcast note" -- "$cur")
fi
;;
-r|--resume)
# Complete with WAV files from recording directory
local recording_dir="${RECORDING_DIR:-$HOME/Recordings}"
if [[ -d "$recording_dir" ]]; then
# Get basenames of WAV files using find (safer than ls)
local files
files=$(find "$recording_dir" -maxdepth 1 -name '*.wav' -printf '%f\n' 2>/dev/null | sed 's/\.wav$//')
mapfile -t COMPREPLY < <(compgen -W "$files" -- "$cur")
fi
;;
-c|--continue-last)
# No more arguments after -c
COMPREPLY=()
;;
*)
# Could be prefix after other args
if [[ "$cur" != -* ]] && [[ "$prev" != "-r" ]] && [[ "$prev" != "--resume" ]]; then
mapfile -t COMPREPLY < <(compgen -W "interview meeting lecture podcast note" -- "$cur")
fi
;;
esac
;;
list)
case "$prev" in
list)
mapfile -t COMPREPLY < <(compgen -W "--all" -- "$cur")
;;
*)
COMPREPLY=()
;;
esac
;;
stop)
case "$prev" in
stop)
if [[ "$cur" == -* ]]; then
mapfile -t COMPREPLY < <(compgen -W "-t --transcribe" -- "$cur")
else
COMPREPLY=()
fi
;;
*)
COMPREPLY=()
;;
esac
;;
pause|resume|status|help)
# These commands take no arguments
COMPREPLY=()
;;
*)
# Shouldn't get here, but just in case
COMPREPLY=()
;;
esac
}
# Register the completion function for vrecord
complete -F _vrecord_completions vrecord
# Also register for the full path if it's in PATH
if command -v vrecord >/dev/null 2>&1; then
complete -F _vrecord_completions "$(command -v vrecord)"
fi
# vim: ft=bash
#fin