Files
proton-drive-linux/packaging/completions.sh
T
nvrl f25c2459a0 feat(cli,core): shell completions with live values from the service
`pdfs completions <shell>` prints a completion script for bash, zsh, fish,
elvish or PowerShell, built on clap_complete's dynamic engine: on Tab the
shell calls `pdfs` back, which completes commands and options and also the
values the running service knows, each with a description: paths in My
files, synced-folder and queue ids, computers, trash, albums, items shared
with me, invitations, bookmarks, conflict copies, and a file's versions or
a share's members and public link once its path is typed.

A completer that gets no answer from the service within two seconds offers
nothing rather than hanging the prompt. Listings that ask Proton are kept
for 30 s in $XDG_RUNTIME_DIR (0600), so repeated Tabs do not wait again.
Completion is triggered by PDFS_COMPLETE rather than clap's generic
COMPLETE, because the same binary runs the daemon.

Share roles are now checked by the CLI before the request. The package
recipes install the bash, zsh and fish scripts via packaging/completions.sh.
2026-11-12 11:43:53 +01:00

24 lines
929 B
Bash
Executable File

#!/usr/bin/env bash
# Write the shell completion scripts of a built `pdfs` into <datadir>, where
# bash-completion, zsh and fish look for them. Packages pass their install
# tree, e.g. "$pkgdir/usr/share". The scripts call `pdfs` from PATH on every
# Tab, so they are the same for every version and need no rebuild per release.
set -euo pipefail
if [ $# -ne 2 ]; then
echo "usage: $0 <pdfs binary> <datadir>" >&2
exit 2
fi
pdfs="$1"
datadir="$2"
install -d "$datadir/bash-completion/completions" \
"$datadir/zsh/site-functions" \
"$datadir/fish/vendor_completions.d"
"$pdfs" completions bash > "$datadir/bash-completion/completions/pdfs"
"$pdfs" completions zsh > "$datadir/zsh/site-functions/_pdfs"
"$pdfs" completions fish > "$datadir/fish/vendor_completions.d/pdfs.fish"
chmod 644 "$datadir/bash-completion/completions/pdfs" \
"$datadir/zsh/site-functions/_pdfs" \
"$datadir/fish/vendor_completions.d/pdfs.fish"