_borg 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644
  1. #compdef borg borgfs -P -value-,BORG_*,-default-
  2. # Zsh completion for Borg Backup 1.2.0a9 (2020-09-27).
  3. #
  4. # Recommended _borg specific settings:
  5. #
  6. # zstyle -e ':completion:*:*:borg-*:argument-rest:*' tag-order \
  7. # '[[ $words[CURRENT] == -* ]] && reply=( "! archives archive-files" "-" )'
  8. # zstyle ':completion:*:*:(borg|-value-,BORG_)*' sort false
  9. # zstyle ':completion:*:*:borg-config:argument-2:keys' list-grouped false
  10. # zstyle ':completion:*:*:borg-*:*' gain-privileges true
  11. # zstyle ':completion:*' fake-parameters 'BORG_REPO:scalar'
  12. #
  13. # Custom styles:
  14. #
  15. # archive-description-format
  16. # Default: `{archive:<36} {time} [{id}]`.
  17. # archive-sort
  18. # In which order archive names should be listed.
  19. # Possible values are: `inverse`, `timestamp`, `name`, `id`.
  20. # file-description-format
  21. # Default: `{mode} {user:6} {group:6} {size:8d} {mtime} {path}{extra}`.
  22. # path-style-selector
  23. # Style selector used to select a path (when Borg would use either `pp` or `pf`).
  24. # Default: `fm`.
  25. # repository-suffix
  26. # This boolean style controls whether to add the `::` auto-removable suffix to a repository.
  27. # Default: `true`.
  28. (( $+functions[_borg_commands] )) ||
  29. _borg_commands() {
  30. local -a commands_=(
  31. 'benchmark:benchmark command'
  32. 'break-lock:break the repository lock'
  33. 'check:check repository consistency'
  34. 'compact:compact segment files in the repository'
  35. 'config:get, set, and delete values in a repository or cache config file'
  36. 'create:create new archive'
  37. 'debug:debugging command (not intended for normal use)'
  38. 'delete:delete an existing repository or archives'
  39. 'diff:diff contents of two archives'
  40. 'export-tar:export archive contents as a tarball'
  41. 'extract:extract archive contents'
  42. 'help:extra help'
  43. 'info:show repository or archive information'
  44. 'init:initialize an empty repository'
  45. 'key:manage repository key'
  46. 'list:list archive or repository contents'
  47. 'mount:mount archive or an entire repository as a FUSE filesystem'
  48. 'prune:prune repository archives according to specified rules'
  49. 'recreate:re-create archives'
  50. 'rename:rename an existing archive'
  51. 'serve:start in server mode'
  52. 'umount:un-mount the FUSE filesystem'
  53. 'upgrade:upgrade a repository from a previous version'
  54. 'with-lock:run a user specified command with the repository lock held'
  55. )
  56. _describe -t commands 'borg commands' commands_
  57. }
  58. (( $+functions[_borg-benchmark] )) ||
  59. _borg-benchmark() {
  60. local -a common_options
  61. __borg_setup_common_options
  62. _arguments -s -w -S : \
  63. $common_options \
  64. ':type:(crud)' \
  65. ': :_borg_repository' \
  66. ':PATH:_files'
  67. }
  68. (( $+functions[_borg-break-lock] )) ||
  69. _borg-break-lock() {
  70. local -a common_options
  71. __borg_setup_common_options
  72. _arguments -s -w -S : \
  73. $common_options \
  74. ':: :_borg_repository'
  75. }
  76. (( $+functions[_borg-check] )) ||
  77. _borg-check() {
  78. local -a common_options common_archive_filters_options
  79. __borg_setup_common_options
  80. __borg_setup_common_archive_filters_options
  81. _arguments -s -w -S : \
  82. '--repository-only[only perform repository checks]' \
  83. '--archives-only[only perform archives checks]' \
  84. '(--repository-only)--verify-data[perform cryptographic archive data integrity verification]' \
  85. '--repair[attempt to repair any inconsistencies found]' \
  86. '--save-space[work slower, but using less space]' \
  87. '--max-duration=[partial repo check for max. SECONDS]: : _borg_guard_unsigned_number "SECONDS"' \
  88. $common_archive_filters_options \
  89. $common_options \
  90. '::REPOSITORY_OR_ARCHIVE: _borg_repository_or_archive'
  91. }
  92. (( $+functions[_borg-compact] )) ||
  93. _borg-compact() {
  94. local -a common_options
  95. __borg_setup_common_options
  96. _arguments -s -w -S : \
  97. $common_options \
  98. '--cleanup-commits[cleanup commit-only 17-byte segment files]' \
  99. '--threshold=[set minimum threshold for saved space in PERCENT (default: 10)]: : _borg_guard_unsigned_number "PERCENT (default\: 10)"' \
  100. ':: :_borg_repository'
  101. }
  102. (( $+functions[_borg-config] )) ||
  103. _borg-config() {
  104. local -a common_options
  105. __borg_setup_common_options
  106. _arguments -s -w -S : \
  107. '(-c --cache)'{-c,--cache}'[get and set values from the repo cache]' \
  108. '(-d --delete)'{-d,--delete}'[delete the key from the config]' \
  109. '(-l --list)'{-l,--list}'[list the configuration of the repo]' \
  110. $common_options \
  111. ': :_borg_repository' \
  112. ': : _borg_config $line[1]' \
  113. '::VALUE'
  114. }
  115. (( $+functions[_borg-create] )) ||
  116. _borg-create() {
  117. local -a common_options common_create_options state line
  118. local curcontext="$curcontext" state_descr
  119. declare -A opt_args
  120. local -i ret=1
  121. __borg_setup_common_options
  122. __borg_setup_common_create_options
  123. local lastspec='*:PATH:_files'
  124. (( $words[(I)--content-from-command] )) &&
  125. lastspec='*:::PATH:->command'
  126. _arguments -C -s -w -S : \
  127. '*'{-e,--exclude}'=[exclude paths matching PATTERN]: : _borg_style_selector_or_archive_files -f -e "$line[1]" fm "${(@)line[2,-1]}"' \
  128. '*--pattern=[experimental: include/exclude paths matching PATTERN]: : _borg_style_selector_or_archive_files -p -f -e "$line[1]" sh "${(@)line[2,-1]}"' \
  129. $common_create_options \
  130. '(-s --stats)--json[Output stats as JSON. Implies --stats.]' \
  131. '--no-cache-sync[experimental: do not synchronize the cache. Implies not using the files cache.]' \
  132. '--stdin-name=[use NAME in archive for stdin data (default: "stdin")]:NAME' \
  133. '--content-from-command[interpret PATH as command and store its stdout]' \
  134. '--exclude-nodump[exclude files flagged NODUMP]' \
  135. '(-x --one-file-system)'{-x,--one-file-system}'[stay in the same file system]' \
  136. '--numeric-owner[only store numeric user and group identifiers]' \
  137. '--noatime[do not store atime into archive]' \
  138. '--atime[do store atime into archive]' \
  139. '--noctime[do not store ctime into archive]' \
  140. '--nobirthtime[do not store birthtime (creation date) into archive]' \
  141. '--nobsdflags[deprecated, use --noflags instead]' \
  142. '--noflags[do not read and store flags (e.g. NODUMP, IMMUTABLE) into archive]' \
  143. '--files-cache=[operate files cache in MODE. default: ctime,size,inode]:MODE:(ctime,size,inode mtime,size,inode ctime,size mtime,size rechunk,ctime rechunk,mtime disabled)' \
  144. '--read-special[open and read block and char device files as well as FIFOs as if they were regular files]' \
  145. $common_options \
  146. ':ARCHIVE: _borg_repository_or_archive -a -p' \
  147. $lastspec && ret=0
  148. case $state in
  149. (command)
  150. if (( CURRENT <= 1 )); then
  151. _command_names -e && ret=0
  152. else
  153. _normal && ret=0
  154. fi
  155. ;;
  156. esac
  157. return ret
  158. }
  159. (( $+functions[_borg-debug] )) ||
  160. _borg-debug() {
  161. local -a state line common_options
  162. local curcontext="$curcontext" state_descr
  163. declare -A opt_args
  164. local -i ret=1
  165. __borg_setup_common_options
  166. _arguments -s -w -C : \
  167. $common_options \
  168. ': :->command' \
  169. '*:: :->option-or-argument' && ret=0
  170. case $state in
  171. (command)
  172. local -a debug_commands=(
  173. 'info:show system infos for debugging / bug reports'
  174. 'dump-archive-items:dump archive items (metadata)'
  175. 'dump-archive:dump decoded archive metadata'
  176. 'dump-manifest:dump decoded repository metadata'
  177. 'dump-repo-objs:dump repo objects'
  178. 'search-repo-objs:search repo objects'
  179. 'get-obj:get object from repository'
  180. 'put-obj:put object to repository'
  181. 'delete-obj:delete object from repository'
  182. 'refcount-obj:show refcount for object from repository'
  183. 'convert-profile:convert Borg profile to Python profile'
  184. )
  185. _describe -t commands 'command' debug_commands && ret=0
  186. ;;
  187. (option-or-argument)
  188. curcontext="${curcontext%:*}-$line[1]:"
  189. case $line[1] in
  190. (info)
  191. _arguments -s -w -S : \
  192. $common_options && ret=0
  193. ;;
  194. (dump-archive-items)
  195. _arguments -s -w -S : \
  196. $common_options \
  197. ':ARCHIVE: _borg_repository_or_archive -a' && ret=0
  198. ;;
  199. (dump-archive)
  200. _arguments -s -w -S : \
  201. $common_options \
  202. ':ARCHIVE: _borg_repository_or_archive -a' \
  203. ':PATH:_files' && ret=0
  204. ;;
  205. (dump-manifest)
  206. _arguments -s -w -S : \
  207. $common_options \
  208. ': :_borg_repository' \
  209. ':PATH:_files' && ret=0
  210. ;;
  211. (dump-repo-objs)
  212. _arguments -s -w -S : \
  213. $common_options \
  214. ': :_borg_repository' && ret=0
  215. ;;
  216. (search-repo-objs)
  217. _arguments -s -w -S : \
  218. $common_options \
  219. ': :_borg_repository' \
  220. ':WANTED (hex or string):' && ret=0
  221. ;;
  222. (get-obj)
  223. _arguments -s -w -S : \
  224. $common_options \
  225. ': :_borg_repository' \
  226. ':ID (hex object):' \
  227. ':PATH:_files' && ret=0
  228. ;;
  229. (put-obj)
  230. _arguments -s -w -S : \
  231. $common_options \
  232. ': :_borg_repository' \
  233. '*:PATH:_files' && ret=0
  234. ;;
  235. (delete-obj)
  236. _arguments -s -w -S : \
  237. $common_options \
  238. ': :_borg_repository' \
  239. '*:ID (hex object):' && ret=0
  240. ;;
  241. (refcount-obj)
  242. _arguments -s -w -S : \
  243. $common_options \
  244. ': :_borg_repository' \
  245. '*:ID (hex object):' && ret=0
  246. ;;
  247. (convert-profile)
  248. _arguments -s -w -S : \
  249. $common_options \
  250. ':INPUT:_files' \
  251. ':OUTPUT:_files' && ret=0
  252. ;;
  253. (*)
  254. if ! _call_function ret _borg_debug_$line[1]; then
  255. _default && ret=0
  256. fi
  257. ;;
  258. esac
  259. ;;
  260. esac
  261. return ret
  262. }
  263. (( $+functions[_borg-delete] )) ||
  264. _borg-delete() {
  265. local -a common_options common_archive_filters_options common_dry_run_stats_options
  266. __borg_setup_common_options
  267. __borg_setup_common_archive_filters_options
  268. __borg_setup_common_dry_run_stats_options
  269. _arguments -s -w -S : \
  270. $common_dry_run_stats_options \
  271. '--cache-only[delete only the local cache for the given repository]' \
  272. '*--force[force deletion of corrupted archives, use "--force --force" in case "--force" does not work]' \
  273. '--keep-security-info[keep the local security info when deleting a repository]' \
  274. '--save-space[work slower, but using less space]' \
  275. $common_archive_filters_options \
  276. $common_options \
  277. ':REPOSITORY_OR_ARCHIVE: _borg_repository_or_archive' \
  278. '*:ARCHIVE: _borg_archive "${line[1]%%::*}"'
  279. }
  280. (( $+functions[_borg-diff] )) ||
  281. _borg-diff() {
  282. local -a common_options common_exclude_options
  283. __borg_setup_common_options
  284. __borg_setup_common_exclude_options
  285. _arguments -s -w -S : \
  286. '--numeric-owner[only obey numeric user and group identifiers]' \
  287. '--same-chunker-params[override check of chunker parameters]' \
  288. '--sort[sort the output lines by file path]' \
  289. $common_exclude_options \
  290. $common_options \
  291. ':ARCHIVE1: _borg_repository_or_archive -a' \
  292. ':ARCHIVE2: _borg_archive "${line[1]%%::*}"' \
  293. '*: : _borg_style_selector_or_archive_files -e "$line[1]" pp'
  294. }
  295. (( $+functions[_borg-export-tar] )) ||
  296. _borg-export-tar() {
  297. local -a common_options common_exclude_extract_options
  298. __borg_setup_common_options
  299. __borg_setup_common_exclude_extract_options
  300. _arguments -s -w -S : \
  301. '--tar-filter[filter program to pipe data through]: :_cmdstring' \
  302. '--list[output verbose list of items (files, dirs, ...)]' \
  303. $common_exclude_extract_options \
  304. $common_options \
  305. ':ARCHIVE: _borg_repository_or_archive -a' \
  306. ':FILE:_files' \
  307. '*: : _borg_style_selector_or_archive_files -e "$line[1]" pp'
  308. }
  309. (( $+functions[_borg-extract] )) ||
  310. _borg-extract() {
  311. local -a common_options common_exclude_extract_options
  312. __borg_setup_common_options
  313. __borg_setup_common_exclude_extract_options
  314. _arguments -s -w -S : \
  315. '--list[output verbose list of items (files, dirs, ...)]' \
  316. '(-n --dry-run)'{-n,--dry-run}'[do not actually change any files]' \
  317. '--numeric-owner[only obey numeric user and group identifiers]' \
  318. '--nobsdflags[deprecated, use --noflags instead]' \
  319. '--noflags[do not extract/set flags (e.g. NODUMP, IMMUTABLE)]' \
  320. '--stdout[write all extracted data to stdout]' \
  321. '--sparse[create holes in output sparse file from all-zero chunks]' \
  322. $common_exclude_extract_options \
  323. $common_options \
  324. ':ARCHIVE: _borg_repository_or_archive -a' \
  325. '*: : _borg_style_selector_or_archive_files -e "$line[1]" pp'
  326. }
  327. (( $+functions[_borg-help] )) ||
  328. _borg-help() {
  329. local -a common_options
  330. __borg_setup_common_options
  331. _arguments -s -w -S : \
  332. '--epilog-only' \
  333. '--usage-only' \
  334. $common_options \
  335. ':: : _alternative "topics:TOPIC:(patterns placeholders compression)" ": :_borg_commands"'
  336. }
  337. (( $+functions[_borg-info] )) ||
  338. _borg-info() {
  339. local -a common_options common_archive_filters_options
  340. __borg_setup_common_options
  341. __borg_setup_common_archive_filters_options
  342. _arguments -s -w -S : \
  343. '--json[format output as JSON]' \
  344. $common_archive_filters_options \
  345. $common_options \
  346. '::REPOSITORY_OR_ARCHIVE: _borg_repository_or_archive'
  347. }
  348. (( $+functions[_borg-init] )) ||
  349. _borg-init() {
  350. local -i ret=1
  351. local -a common_options common_init_options
  352. __borg_setup_common_options
  353. __borg_setup_common_init_options
  354. # special handling for the required optional argument
  355. if (( ! ${words[(I)(-e|--encryption)(|=*)]} )); then
  356. local desc='select encryption key mode'
  357. local -a long=( "--encryption:$desc" ) short=( "-e:$desc" ) remove_chars=( -r '= \t\n\-' )
  358. _describe -t required-options 'required option' long -S '=' $remove_chars -- short $remove_chars && ret=0
  359. fi
  360. _arguments -s -w -S : \
  361. '(-e --encryption)'{-e,--encryption}'=[select encryption key mode (required)]:MODE:(none keyfile keyfile-blake2 repokey repokey-blake2 authenticated authenticated-blake2)' \
  362. $common_init_options \
  363. '--make-parent-dirs[create parent directories]' \
  364. '::REPOSITORY:_directories' && ret=0
  365. return ret
  366. }
  367. (( $+functions[_borg-key] )) ||
  368. _borg-key() {
  369. local -a state line common_options
  370. local curcontext="$curcontext" state_descr
  371. declare -A opt_args
  372. local -i ret=1
  373. __borg_setup_common_options
  374. _arguments -s -w -C : \
  375. $common_options \
  376. ': :->command' \
  377. '*:: :->option-or-argument' && ret=0
  378. case $state in
  379. (command)
  380. local -a key_commands=(
  381. 'change-passphrase:Change repository key file passphrase'
  382. 'export:Export the repository key for backup'
  383. 'import:Import the repository key from backup'
  384. 'migrate-to-repokey:Migrate passphrase -> repokey'
  385. )
  386. _describe -t commands 'command' key_commands && ret=0
  387. ;;
  388. (option-or-argument)
  389. curcontext="${curcontext%:*}-$line[1]:"
  390. case $line[1] in
  391. (change-passphrase)
  392. _arguments -s -w -S : \
  393. $common_options \
  394. ': :_borg_repository' && ret=0
  395. ;;
  396. (export)
  397. _arguments -s -w -S : \
  398. '--paper[create an export suitable for printing and later type-in]' \
  399. '--qr-html[create an html file suitable for printing and later type-in or qr scan]' \
  400. $common_options \
  401. ': :_borg_repository' \
  402. '::PATH:_files' && ret=0
  403. ;;
  404. (import)
  405. _arguments -s -w -S : \
  406. '--paper[interactively import from a backup done with --paper]' \
  407. $common_options \
  408. ': :_borg_repository' \
  409. '::PATH:_files' && ret=0
  410. ;;
  411. (migrate-to-repokey)
  412. _arguments -s -w -S : \
  413. $common_options \
  414. ':: :_borg_repository' && ret=0
  415. ;;
  416. (*)
  417. if ! _call_function ret _borg_key_$line[1]; then
  418. _default && ret=0
  419. fi
  420. ;;
  421. esac
  422. ;;
  423. esac
  424. return ret
  425. }
  426. (( $+functions[_borg-list] )) ||
  427. _borg-list() {
  428. local -a common_options common_exclude_options common_archive_filters_options
  429. __borg_setup_common_options
  430. __borg_setup_common_exclude_options
  431. __borg_setup_common_archive_filters_options
  432. _arguments -s -w -S : \
  433. '--consider-checkpoints[show checkpoint archives in the repository contents list (default: hidden)]' \
  434. '--short[only print file/directory names, nothing else]' \
  435. {--format,--list-format}'=[specify format for file listing]:FORMAT: _borg_format_keys $line[1]' \
  436. '--json[Only valid for listing repository contents. Format output as JSON.]' \
  437. '--json-lines[Only valid for listing archive contents. Format output as JSON Lines.]' \
  438. $common_archive_filters_options \
  439. $common_exclude_options \
  440. $common_options \
  441. ':REPOSITORY_OR_ARCHIVE: _borg_repository_or_archive' \
  442. '*: : _borg_style_selector_or_archive_files -e "$line[1]" pp'
  443. }
  444. (( $+functions[_borg-mount] )) ||
  445. _borg-mount() {
  446. local -a common_options common_exclude_extract_options common_archive_filters_options
  447. __borg_setup_common_options
  448. __borg_setup_common_exclude_extract_options
  449. __borg_setup_common_archive_filters_options
  450. _arguments -s -w -S : \
  451. $* \
  452. '--consider-checkpoints[show checkpoint archives in the repository contents list (default: hidden)]' \
  453. '(-f --foreground)'{-f,--foreground}'[stay in foreground, do not daemonize]' \
  454. '-o[mount options]: :_fuse_values "mount options"
  455. "versions[merged, versioned view of the files in the archives]"
  456. "allow_damaged_files[read damaged files]"
  457. "ignore_permissions[not enforce \"default_permissions\"]"' \
  458. $common_archive_filters_options \
  459. $common_exclude_extract_options \
  460. $common_options \
  461. ':REPOSITORY_OR_ARCHIVE: _borg_repository_or_archive' \
  462. ':MOUNTPOINT:_directories' \
  463. '*: : _borg_style_selector_or_archive_files "$line[1]" pp'
  464. }
  465. (( $+functions[_borg-prune] )) ||
  466. _borg-prune() {
  467. local -a common_options common_prefix_and_glob_archives_filter_options common_dry_run_stats_options
  468. __borg_setup_common_options
  469. __borg_setup_common_prefix_and_glob_archives_filter_options
  470. __borg_setup_common_dry_run_stats_options
  471. _arguments -s -w -S : \
  472. $common_dry_run_stats_options \
  473. '*--force[force pruning of corrupted archives, use "--force --force" in case "--force" does not work]' \
  474. '--list[output verbose list of archives it keeps/prunes]' \
  475. '--keep-within[keep all archives within this time interval]: : _borg_guard_unsigned_number "INTERVAL"' \
  476. '(--keep-last --keep-secondly)'{--keep-last,--keep-secondly}'[number of secondly archives to keep]: : _borg_guard_unsigned_number "N"' \
  477. '--keep-minutely[number of minutely archives to keep]: : _borg_guard_unsigned_number "N"' \
  478. '(-H --keep-hourly)'{-H,--keep-hourly}'[number of hourly archives to keep]: : _borg_guard_unsigned_number "N"' \
  479. '(-d --keep-daily)'{-d,--keep-daily}'[number of daily archives to keep]: : _borg_guard_unsigned_number "N"' \
  480. '(-w --keep-weekly)'{-w,--keep-weekly}'[number of weekly archives to keep]: : _borg_guard_unsigned_number "N"' \
  481. '(-m --keep-monthly)'{-m,--keep-monthly}'[number of monthly archives to keep]: : _borg_guard_unsigned_number "N"' \
  482. '(-y --keep-yearly)'{-y,--keep-yearly}'[number of yearly archives to keep]: : _borg_guard_unsigned_number "N"' \
  483. '--save-space[work slower, but using less space]' \
  484. $common_prefix_and_glob_archives_filter_options \
  485. $common_options \
  486. ':: :_borg_repository'
  487. }
  488. (( $+functions[_borg-recreate] )) ||
  489. _borg-recreate() {
  490. local -a common_options common_create_options
  491. __borg_setup_common_options
  492. __borg_setup_common_create_options
  493. local -a mods=(
  494. 'if-different:recompress if current compression is with a different compression algorithm (the level is not considered)'
  495. 'always:recompress even if current compression is with the same compression algorithm (use this to change the compression level)'
  496. 'never:do not recompress (use this option to explicitly prevent recompression)'
  497. )
  498. mods=( ${(q)mods//\\/\\\\} )
  499. mods=( ${mods//:/\\:} )
  500. _arguments -s -w -S : \
  501. $common_create_options \
  502. '--target=[create a new archive with the name ARCHIVE]:ARCHIVE: _borg_placeholder_or_archive "${line[1]%%\:\:*}"' \
  503. '--recompress=[recompress data chunks according to "MODE" and "--compression"]:MODE:'"(($mods))" \
  504. $common_options \
  505. ':REPOSITORY_OR_ARCHIVE: _borg_repository_or_archive' \
  506. '*: : _borg_style_selector_or_archive_files -e "$line[1]" pp'
  507. }
  508. (( $+functions[_borg-rename] )) ||
  509. _borg-rename() {
  510. local -a common_options
  511. __borg_setup_common_options
  512. _arguments -s -w -S : \
  513. $common_options \
  514. ':ARCHIVE: _borg_repository_or_archive -a' \
  515. ':NEWNAME'
  516. }
  517. (( $+functions[_borg-serve] )) ||
  518. _borg-serve() {
  519. local -a common_options common_init_options
  520. __borg_setup_common_options
  521. __borg_setup_common_init_options
  522. _arguments -s -w -S : \
  523. $common_init_options \
  524. '*--restrict-to-path=[restrict repository access to PATH]:PATH:_files' \
  525. '*--restrict-to-repository=[restrict repository access]: :_borg_repository'
  526. }
  527. (( $+functions[_borg-umount] )) ||
  528. _borg-umount() {
  529. local -a common_options
  530. __borg_setup_common_options
  531. _arguments -s -w -S : \
  532. $common_options \
  533. ':MOUNTPOINT:_umountable'
  534. }
  535. (( $+functions[_borg-upgrade] )) ||
  536. _borg-upgrade() {
  537. local -a common_options
  538. __borg_setup_common_options
  539. _arguments -s -w -S : \
  540. '(-n --dry-run)'{-n,--dry-run}'[do not change repository]' \
  541. '--inplace[rewrite repository in place, with no chance of going back to older versions of the repository]' \
  542. '--force[force upgrade]' \
  543. '--tam[enable manifest authentication (in key and cache)]' \
  544. '--disable-tam[disable manifest authentication (in key and cache)]' \
  545. $common_options \
  546. ':: :_borg_repository'
  547. }
  548. (( $+functions[_borg-with-lock] )) ||
  549. _borg-with-lock() {
  550. local -a state line common_options
  551. local curcontext="$curcontext" state_descr
  552. declare -A opt_args
  553. local -i ret=1
  554. __borg_setup_common_options
  555. _arguments -s -w -C -S : \
  556. $common_options \
  557. '(-): :_borg_repository' \
  558. '(-):COMMAND: _command_names -e' \
  559. '(-)*:ARGS:->normal' && ret=0
  560. case $state in
  561. (normal)
  562. shift 2 words
  563. (( CURRENT -= 2 ))
  564. _normal && ret=0
  565. ;;
  566. esac
  567. return ret
  568. }
  569. (( $+functions[__borg_setup_common_options] )) ||
  570. __borg_setup_common_options() {
  571. typeset -ga common_options=(
  572. '(- :)'{-h,--help}'[show this help message and exit]'
  573. '--critical[work on log level CRITICAL]'
  574. '--error[work on log level ERROR]'
  575. '--warning[work on log level WARNING (default)]'
  576. '(--info -v --verbose)'{--info,-v,--verbose}'[work on log level INFO]'
  577. '--debug[work on log level DEBUG]'
  578. '--debug-topic=[enable TOPIC debugging (can be specified multiple times)]:TOPIC'
  579. '(-p --progress)'{-p,--progress}'[show progress information]'
  580. '--log-json[Output one JSON object per log line instead of formatted text.]'
  581. '--lock-wait=[wait at most SECONDS for acquiring a repository/cache lock (default: 1)]: : _borg_guard_unsigned_number "SECONDS"'
  582. '--bypass-lock[bypass locking mechanism]'
  583. '(- :)--show-version[show/log the borg version]'
  584. '--show-rc[show/log the return code (rc)]'
  585. '--umask=[set umask to M (local only, default: 0077)]:M'
  586. '--remote-path=[set remote path to executable (default: "borg")]: :_cmdstring'
  587. '--remote-ratelimit=[set remote network upload rate limit in kiByte/s (default: 0=unlimited)]: : _borg_guard_unsigned_number "RATE"'
  588. '--consider-part-files[treat part files like normal files (e.g. to list/extract them)]'
  589. '--debug-profile=[write execution profile in Borg format into FILE]:FILE:_files'
  590. '--rsh=[use COMMAND instead of ssh]: :_cmdstring'
  591. )
  592. }
  593. (( $+functions[__borg_setup_common_exclude_options] )) ||
  594. __borg_setup_common_exclude_options() {
  595. typeset -ga common_exclude_options=(
  596. '*'{-e,--exclude}'=[exclude paths matching PATTERN]: : _borg_style_selector_or_archive_files "$line[1]" fm'
  597. '*--exclude-from=[read exclude patterns from EXCLUDEFILE, one per line]:EXCLUDEFILE:_files'
  598. '*--pattern=[experimental: include/exclude paths matching PATTERN]: : _borg_style_selector_or_archive_files -p "$line[1]" sh'
  599. '*--patterns-from=[experimental: read include/exclude patterns from PATTERNFILE, one per line]:PATTERNFILE:_files'
  600. )
  601. }
  602. (( $+functions[__borg_setup_common_exclude_extract_options] )) ||
  603. __borg_setup_common_exclude_extract_options() {
  604. local -a common_exclude_options
  605. __borg_setup_common_exclude_options
  606. typeset -ga common_exclude_extract_options=(
  607. $common_exclude_options
  608. '--strip-components=[Remove the specified number of leading path elements. Paths with fewer elements will be silently skipped.]: : _borg_guard_unsigned_number "NUMBER"'
  609. )
  610. }
  611. (( $+functions[__borg_setup_common_prefix_and_glob_archives_filter_options] )) ||
  612. __borg_setup_common_prefix_and_glob_archives_filter_options() {
  613. typeset -ga common_prefix_and_glob_archives_filter_options=(
  614. '(-P --prefix -a --glob-archives)'{-P,--prefix}'=[only consider archive names starting with this prefix]:PREFIX: _borg_archive -n "${line[1]%%\:\:*}"'
  615. '(-P --prefix)*'{-a,--glob-archives}'=[only consider archive names matching the glob]:GLOB: _borg_archive -n "${line[1]%%\:\:*}"'
  616. )
  617. }
  618. (( $+functions[__borg_setup_common_archive_filters_options] )) ||
  619. __borg_setup_common_archive_filters_options() {
  620. local -a common_prefix_and_glob_archives_filter_options
  621. __borg_setup_common_prefix_and_glob_archives_filter_options
  622. typeset -ga common_archive_filters_options=(
  623. $common_prefix_and_glob_archives_filter_options
  624. '--sort-by=[Comma-separated list of sorting keys, default: timestamp]:KEYS:(timestamp name id)'
  625. '(--last)--first=[consider first N archives after other filters were applied]:N: _borg_archive -n "${line[1]%%\:\:*}"'
  626. '(--first)--last=[consider last N archives after other filters were applied]:N: _borg_archive -n "${line[1]%%\:\:*}"'
  627. )
  628. }
  629. (( $+functions[__borg_setup_common_dry_run_stats_options] )) ||
  630. __borg_setup_common_dry_run_stats_options() {
  631. typeset -ga common_dry_run_stats_options=(
  632. '(-n --dry-run -s --stats)'{-n,--dry-run}'[do not change anything]'
  633. '(-n --dry-run -s --stats)'{-s,--stats}'[print statistics at end]'
  634. # NOTE: actual messages for subcommands differ in details
  635. )
  636. }
  637. (( $+functions[__borg_setup_common_create_options] )) ||
  638. __borg_setup_common_create_options() {
  639. local -a common_dry_run_stats_options common_exclude_options
  640. __borg_setup_common_dry_run_stats_options
  641. __borg_setup_common_exclude_options
  642. typeset -ga common_create_options=(
  643. $common_dry_run_stats_options
  644. '--list[output verbose list of items (files, dirs, ...)]'
  645. '--filter=[only display items with the given status characters]: :_borg_statuschars'
  646. $common_exclude_options
  647. '--exclude-caches[exclude directories that contain a CACHEDIR.TAG file]'
  648. '*--exclude-if-present=[exclude directories that are tagged by containing a filesystem object with the given NAME]:NAME:_files'
  649. '--keep-exclude-tags[if tag objects are specified with --exclude-if-present, don'\''t omit the tag objects themselves]'
  650. '--comment=[add a comment text to the archive]:COMMENT:_borg_placeholders'
  651. '--timestamp=[manually specify the archive creation date/time]:TIMESTAMP:_borg_timestamp'
  652. '(-c --checkpoint-interval)'{-c,--checkpoint-interval}'=[write checkpoint every SECONDS seconds (default: 1800)]: : _borg_guard_unsigned_number "SECONDS"'
  653. '--chunker-params=[specify the chunker parameters]: :_borg_chunker_params_examples'
  654. '(-C --compression)'{-C,--compression}'=[select compression algorithm]: :_borg_compression'
  655. )
  656. }
  657. (( $+functions[__borg_setup_common_init_options] )) ||
  658. __borg_setup_common_init_options() {
  659. local -a common_options
  660. __borg_setup_common_options
  661. typeset -ga common_init_options=(
  662. $common_options
  663. '--append-only[only allow appending to repository segment files]'
  664. '--storage-quota=[override storage quota of the repository]: :_borg_quota_suffixes'
  665. )
  666. }
  667. (( $+functions[_borgfs] )) ||
  668. _borgfs() {
  669. _borg-mount '(- :)'{-V,--version}'[show version number and exit]'
  670. }
  671. (( $+functions[_borg_parameters] )) ||
  672. _borg_parameters() {
  673. local name=$1
  674. shift
  675. local -i ret=1
  676. local -a expl
  677. case $name in
  678. (REPO)
  679. local BORG_REPO
  680. unset BORG_REPO
  681. _borg_repository && ret=0
  682. ;;
  683. ((|NEW_)PASSPHRASE)
  684. _message -e 'passphrase' && ret=0
  685. ;;
  686. (DISPLAY_PASSPHRASE)
  687. _message -e 'answer to the "display the passphrase for verification" question' && ret=0
  688. ;;
  689. (HOST_ID)
  690. _message -e 'unique ID' && ret=0
  691. ;;
  692. (FILES_CACHE_TTL)
  693. _borg_guard_unsigned_number 'time to live (default: 20)' && ret=0
  694. ;;
  695. (MOUNT_DATA_CACHE_ENTRIES)
  696. _borg_guard_unsigned_number 'number of cached data chunks' && ret=0
  697. ;;
  698. (PASSCOMMAND|RSH|REMOTE_PATH)
  699. _cmdstring && ret=0
  700. ;;
  701. (HOSTNAME_IS_UNIQUE|SHOW_SYSINFO|(UNKNOWN_UNENCRYPTED|RELOCATED)_REPO_ACCESS_IS_OK)
  702. _description values expl 'value'
  703. compadd "$expl[@]" yes no && ret=0
  704. ;;
  705. ((CHECK|DELETE)_I_KNOW_WHAT_I_AM_DOING)
  706. _description values expl 'value'
  707. compadd "$expl[@]" YES NO && ret=0
  708. ;;
  709. (WORKAROUNDS)
  710. _wanted workarounds expl 'workaround' _sequence compadd - basesyncfile && ret=0
  711. ;;
  712. (KEYS_DIR)
  713. _directories && ret=0
  714. ;;
  715. (*)
  716. _default && ret=0
  717. ;;
  718. esac
  719. return ret
  720. }
  721. (( $+functions[_borg_repository] )) ||
  722. _borg_repository() {
  723. local -a alts opts qopts
  724. zparseopts -E -a opts S:
  725. qopts=( ${(q)opts} )
  726. [[ -n $BORG_REPO ]] && alts+=( "default-repository: : __borg_default_repository $qopts" )
  727. alts+=( "cached-repositories:cached repositories:_borg_cached_repositories $qopts" )
  728. alts+=( 'directories: :_directories -r ":/ \t\n\-"' )
  729. alts+=( 'remote-repositories: : _borg_remote_repositories' )
  730. _alternative $alts
  731. }
  732. (( $+functions[__borg_default_repository] )) ||
  733. __borg_default_repository() {
  734. local -a opts suf
  735. zparseopts -E -a opts S:
  736. (( $opts[(I)-S] )) && suf=( -S '' )
  737. local -a default_repository=( "\:\::$BORG_REPO" )
  738. _describe -t default-repository 'default repository' default_repository "$suf[@]"
  739. }
  740. (( $+functions[_borg_cached_repositories] )) ||
  741. _borg_cached_repositories() {
  742. local -a cached_repos
  743. local sed_script='/^previous_location = / {
  744. s///
  745. # no port was given
  746. /ssh:\/\/[^/:]+:[0-9]+/! {
  747. # lstrip the `ssh://` prefix and add a colon before the first slash
  748. s!ssh://([^:/]+)/(.*)!\1:/\2!
  749. }
  750. p
  751. }'
  752. local cachedir=${BORG_CACHE_DIR:-${XDG_CACHE_HOME:-${BORG_BASE_DIR:-$HOME}/.cache}/borg}
  753. cached_repos=( ${(f)"$(_call_program -p cached-repositories sed -n -E ${(q)sed_script} \
  754. "${(q)cachedir}/*/config(#qN.om)" 2>/dev/null)"} )
  755. if [[ $compstate[quote] != (\'|\") ]]; then
  756. # hide ~BORG_REPO and other scalars
  757. local BORG_REPO
  758. unset BORG_REPO sed_script cachedir
  759. cached_repos=( "${(@D)cached_repos}" )
  760. fi
  761. compadd -Q "$@" -r ': \t\n\-' -a cached_repos
  762. }
  763. (( $+functions[_borg_remote_repositories] )) ||
  764. _borg_remote_repositories() {
  765. local -a match mbegin mend expl alts
  766. if compset -P '(#b)ssh://[^/]##@[^/]##:([0-9]##)/'; then
  767. _remote_files -/ -- ssh -p $match[1]
  768. return
  769. fi
  770. local -i have_scheme=0
  771. compset -P 'ssh://' && have_scheme=1
  772. if compset -P '*:'; then
  773. (( have_scheme )) && alts+=( 'ports: : _borg_guard_unsigned_number "port"' )
  774. alts+=( 'remote-files:remote file: _remote_files -/ -- ssh' )
  775. _alternative $alts
  776. elif compset -P 1 '(#b)(*)@'; then
  777. local user=$match[1]
  778. _wanted -C user-at hosts expl "host for $user" \
  779. _combination -s '[:@]' accounts users-hosts users="$user" hosts -S ':' -
  780. elif compset -S '@*'; then
  781. _wanted users expl "user" \
  782. _combination -s '[:@]' accounts users-hosts users -q -
  783. else
  784. alts=(
  785. 'users:user:_users -S "@"'
  786. 'hosts:host:_hosts -S ":"'
  787. )
  788. (( ! have_scheme )) && alts+=( 'prefixes:ssh:compadd -S "" ssh://' )
  789. _alternative $alts
  790. fi
  791. }
  792. # _borg_repository_or_archive [-a] [-p]
  793. #
  794. # -a archive is mandatory. The suffix `::` will be added to the repository if possible.
  795. # -p complete placeholders
  796. (( $+functions[_borg_repository_or_archive] )) ||
  797. _borg_repository_or_archive() {
  798. local -A opts
  799. zparseopts -A opts -D -E a p
  800. if compset -P 1 '*::'; then
  801. local qrepo=$IPREFIX[1,-3]
  802. local -i def_repo=0
  803. [[ -z $qrepo && -n $BORG_REPO ]] && qrepo=${(q)BORG_REPO} && def_repo=1
  804. if [[ -n $qrepo ]]; then
  805. if (( ! def_repo )); then
  806. case $compstate[quote] in
  807. (\') qrepo=${(qq)qrepo} ;;
  808. (\") qrepo=${(qqq)${(e)qrepo}} ;;
  809. # NOTE: currently `(e)` don't have any effect, but maybe one day zsh will stop to change the quoting method
  810. # of double quoted parameters
  811. esac
  812. fi
  813. if (( $+opts[-p] )); then
  814. _borg_placeholder_or_archive $qrepo
  815. else
  816. _borg_archive $qrepo
  817. fi
  818. else
  819. _message "not a borg repository: ${(Q)qrepo}"
  820. return 1
  821. fi
  822. else
  823. local -a suf
  824. if ! compset -S '::*'; then
  825. if (( $+opts[-a] )) || zstyle -T ":completion:${curcontext}:repositories" repository-suffix; then
  826. suf=( -S '::' )
  827. fi
  828. local oqrepo="$PREFIX$SUFFIX"
  829. local qrepo=$oqrepo
  830. [[ $compstate[quote] != (\'|\") ]] && qrepo=${(Q)qrepo}
  831. if __borg_is_borg_repo $qrepo; then
  832. qrepo=${oqrepo%%/}
  833. [[ -z $SUFFIX ]] && PREFIX=${PREFIX%%/} || SUFFIX=${SUFFIX%%/}
  834. compadd -S '::' -r ':/ \t\n\-' -Q -- $qrepo
  835. return
  836. fi
  837. fi
  838. _borg_repository "$suf[@]"
  839. fi
  840. }
  841. # _borg_archive [-F] [-n] [qrepo]
  842. #
  843. # -F don't apply archive filter options on the command line
  844. # -n reverse order, disable matchers and don't do menu completion/selection
  845. (( $+functions[_borg_archive] )) ||
  846. _borg_archive() {
  847. local -A opts
  848. zparseopts -A opts -D -E F n
  849. local qrepo=$1
  850. if [[ -z $qrepo ]]; then
  851. if [[ -n $BORG_REPO ]]; then
  852. qrepo=${(q)BORG_REPO}
  853. else
  854. _message 'no repository specified'
  855. return 1
  856. fi
  857. fi
  858. local -i ret=1
  859. _tags archives
  860. while _tags; do
  861. if _requested archives; then
  862. local -a expl disp archive_filters
  863. local -i reversed_order=1
  864. if (( ! $+opts[-F] )); then
  865. local -a archive_filter_options=( -P --prefix -a --glob-archives --first --last --sort-by ) tmp
  866. local k
  867. for k in $archive_filter_options; do
  868. if [[ -n $opt_args[$k] ]]; then
  869. IFS=: read -A tmp <<<$opt_args[$k]
  870. archive_filters+=( $k=${^tmp:#} )
  871. fi
  872. done
  873. fi
  874. if (( $+opts[-n] )); then
  875. __borg_skip_pattern_matching || return 1
  876. disp+=( -U )
  877. compstate[insert]=''
  878. compstate[list]='list force'
  879. reversed_order=0
  880. fi
  881. local -a asort
  882. zstyle -a ":completion:${curcontext}:archives" archive-sort asort
  883. if (( $asort[(I)inverse] )); then
  884. (( reversed_order = ! reversed_order ))
  885. fi
  886. local -a sort_by=( --sort-by=${(M)^asort:#(timestamp|name|id)} )
  887. # NOTE: in case of option repetition, the later one takes precedence
  888. if (( ! $+__borg_archives_need_update )); then
  889. comppostfuncs+=( __borg_unset_archives_need_update )
  890. typeset -gHi __borg_archives_need_update=1
  891. if (( ! $#archive_filters && ! $+opts[-n] )); then
  892. local erepo
  893. [[ -n $1 ]] && __borg_expand_path ${(Q)qrepo} erepo
  894. local -a newest_file=( $erepo/(hints|index|integrity).<1->(#qN.om[1]) )
  895. if [[ -n $newest_file ]]; then
  896. if zmodload -F zsh/stat b:zstat 2>/dev/null; then
  897. local -a stats
  898. zstat -A stats +mtime $newest_file
  899. local -i mtime=$stats[1]
  900. if [[ $__borg_prev_repo == $erepo
  901. && __borg_prev_mtime -ge mtime
  902. && $__borg_prev_order == $reversed_order
  903. && $__borg_prev_sort_by == $sort_by ]]
  904. then
  905. __borg_archives_need_update=0
  906. else
  907. typeset -gH __borg_prev_repo=$erepo
  908. typeset -gHi __borg_prev_mtime=mtime __borg_prev_order=reversed_order
  909. typeset -gHa __borg_prev_sort_by=( $sort_by )
  910. fi
  911. fi
  912. fi
  913. else
  914. unset __borg_prev_{repo,mtime,order,sort_by}
  915. comppostfuncs+=( __borg_unset_archives )
  916. fi
  917. fi
  918. if zstyle -t ":completion:${curcontext}:archives" verbose; then
  919. if (( __borg_archives_need_update || ! $+__borg_archive_names || ! $+__borg_archive_descriptions )); then
  920. __borg_archives_need_update=0
  921. typeset -gHa __borg_archive_names=() __borg_archive_descriptions=()
  922. local fmt descfmt name desc
  923. zstyle -s ":completion:${curcontext}:archives" archive-description-format descfmt ||
  924. descfmt='{archive:<36} {time} [{id}]'
  925. fmt="{barchive}{NUL}$descfmt{NUL}"
  926. _call_program -p archive-descriptions \
  927. ${(q)__borg_command:-borg} list --format=${(q)fmt} ${(q)sort_by} $archive_filters $qrepo 2>/dev/null |
  928. while IFS= read -r -d $'\0' name && IFS= read -r -d $'\0' descr; do
  929. __borg_archive_names[1,0]=( $name )
  930. __borg_archive_descriptions[1,0]=( "$descr" )
  931. done
  932. (( $pipestatus[1] )) && {
  933. _message "couldn't list repository: ${(Q)qrepo}"
  934. unset __borg_prev_{repo,mtime,order,sort_by}
  935. return 1
  936. }
  937. (( ! reversed_order )) &&
  938. __borg_archive_names=( "${(@aO)__borg_archive_names}" ) &&
  939. __borg_archive_descriptions=( "${(@aO)__borg_archive_descriptions}" )
  940. fi
  941. disp+=( -ld __borg_archive_descriptions )
  942. elif (( __borg_archives_need_update || ! $+__borg_archive_names )); then
  943. __borg_archives_need_update=0
  944. typeset -gHa __borg_archive_names=()
  945. local fmt='{barchive}{NUL}'
  946. __borg_archive_names=( ${(@0aO)"$(_call_program -p archives \
  947. ${(q)__borg_command:-borg} list --format=${(q)fmt} ${(q)sort_by} $archive_filters $qrepo 2>/dev/null)"} )
  948. (( $pipestatus[1] )) && {
  949. _message "couldn't list repository: ${(Q)qrepo}"
  950. unset __borg_prev_{repo,mtime,order,sort_by}
  951. return 1
  952. }
  953. (( ! reversed_order )) &&
  954. __borg_archive_names=( "${(@aO)__borg_archive_names}" )
  955. fi
  956. _all_labels archives expl 'ARCHIVE' compadd "$disp[@]" -a __borg_archive_names && ret=0
  957. fi
  958. (( ret )) || return 0
  959. done
  960. return 1
  961. }
  962. (( $+functions[__borg_unset_archives] )) ||
  963. __borg_unset_archives() {
  964. unset __borg_archive_names __borg_archive_descriptions
  965. }
  966. (( $+functions[__borg_unset_archives_need_update] )) ||
  967. __borg_unset_archives_need_update() {
  968. unset __borg_archives_need_update
  969. }
  970. (( $+functions[__borg_is_borg_repo] )) ||
  971. __borg_is_borg_repo() {
  972. local repo=$1
  973. __borg_expand_path $repo repo
  974. if [[ -d $repo && -d $repo/data ]]; then
  975. local -a files=( $repo/(hints|index|integrity).<1->(#qN.) )
  976. (( $#files >= 3 )) && return 0
  977. fi
  978. return 1
  979. }
  980. (( $+functions[__borg_expand_path] )) ||
  981. __borg_expand_path() {
  982. local _path=$1
  983. local -a match mbegin mend
  984. if [[ $_path == (#b)(\~[^/]#)(|/*) ]]; then
  985. local etilde
  986. etilde=$~match[1] 2>/dev/null
  987. _path="$etilde$match[2]"
  988. fi
  989. _path=${(e)_path//\\\\/\\\\\\\\}
  990. eval typeset -g ${2:-REPLY}=\$_path
  991. }
  992. (( $+functions[_borg_placeholder_or_archive] )) ||
  993. _borg_placeholder_or_archive() {
  994. local qrepo=$1
  995. shift
  996. _alternative \
  997. 'placeholders: :_borg_placeholders' \
  998. "archives: : _borg_archive ${(q)qrepo}"
  999. }
  1000. (( $+functions[_borg_placeholders] )) ||
  1001. _borg_placeholders() {
  1002. local -a placeholders=(
  1003. 'hostname:The (short) hostname of the machine.'
  1004. 'fqdn:The full name of the machine.'
  1005. 'reverse-fqdn:The full name of the machine in reverse domain name notation.'
  1006. 'now:The current local date and time, by default in ISO-8601 format. You can also supply your own format string, e.g. {now:%Y-%m-%d_%H:%M:%S}'
  1007. 'utcnow:The current UTC date and time, by default in ISO-8601 format. You can also supply your own format string, e.g. {utcnow:%Y-%m-%d_%H:%M:%S}'
  1008. 'user:The user name (or UID, if no name is available) of the user running borg.'
  1009. 'pid:The current process ID.'
  1010. 'borgversion:The version of borg, e.g.: 1.0.8rc1'
  1011. 'borgmajor:The version of borg, only the major version, e.g.: 1'
  1012. 'borgminor:The version of borg, only major and minor version, e.g.: 1.0'
  1013. 'borgpatch:The version of borg, only major, minor and patch version, e.g.: 1.0.8'
  1014. )
  1015. __borg_complete_keys _describe -t placeholders 'placeholder' placeholders '"$copts[@]"'
  1016. }
  1017. (( $+functions[_borg_format_keys] )) ||
  1018. _borg_format_keys() {
  1019. local repo_or_arch=${(Q)1}
  1020. local -a keys=( NEWLINE NL NUL SPACE TAB CR LF )
  1021. local -a repository_keys=( archive name barchive comment bcomment id start time end hostname username )
  1022. local -a archive_keys=( type mode uid gid user group path bpath source linktarget flags size csize dsize dcsize
  1023. num_chunks unique_chunks mtime ctime atime isomtime isoctime isoatime blake2b blake2s md5 sha1 sha224 sha256 sha384
  1024. sha3_224 sha3_256 sha3_384 sha3_512 sha512 shake_128 shake_256 archiveid archivename extra health )
  1025. local akeys rkeys
  1026. akeys='archive-keys:archive keys:compadd -a archive_keys'
  1027. rkeys='repository-keys:repository keys:compadd -a repository_keys'
  1028. local -a alts=( 'keys:keys:compadd -a keys' )
  1029. if [[ $repo_or_arch == *::?* ]]; then
  1030. alts+=( $akeys )
  1031. elif [[ -n $repo_or_arch ]]; then
  1032. alts+=( $rkeys )
  1033. else
  1034. alts+=( $rkeys $akeys )
  1035. fi
  1036. __borg_complete_keys _alternative -O copts ${(q)alts}
  1037. }
  1038. (( $+functions[__borg_complete_keys] )) ||
  1039. __borg_complete_keys() {
  1040. compset -P '*[^A-Za-z]##'
  1041. compset -S '[^A-Za-z]##*'
  1042. [[ -n $ISUFFIX ]] && compstate[to_end]=''
  1043. # NOTE: `[[ -n $ISUFFIX ]]` is a workarond for a bug that causes cursor movement to the right further than it should
  1044. # NOTE: the _oldlist completer doesn't respect compstate[to_end]=''
  1045. local ipref suf
  1046. if [[ $IPREFIX[-1] != '{' ]]; then
  1047. ipref='{'
  1048. [[ $compstate[quote] != (\'|\") ]] && ipref='\{'
  1049. fi
  1050. if [[ $ISUFFIX[1] != (|\\)\} ]]; then
  1051. suf='}'
  1052. [[ $compstate[quote] != (\'|\") ]] && suf='\}'
  1053. fi
  1054. local -a copts=( -i "$ipref" -S "$suf" )
  1055. eval "$@"
  1056. }
  1057. # _borg_style_selector_or_archive_files [-e] [-p] archive default_style_selector
  1058. #
  1059. # -e apply exclusion options on the command line
  1060. # -p complete `--pattern`
  1061. # -f complete files rather than borg paths
  1062. (( $+functions[_borg_style_selector_or_archive_files] )) ||
  1063. _borg_style_selector_or_archive_files() {
  1064. local -A opts
  1065. zparseopts -A opts -D -E e p f
  1066. local arch=$1 default_style_selector=$2
  1067. shift 2
  1068. local -a match mbegin mend expl tags=( style-selectors archive-files ) ss_suf=( -S ':' -r ':' )
  1069. (( $+opts[-f] )) && tags=( style-selectors files )
  1070. local -i ret=1
  1071. if (( $+opts[-p] )); then
  1072. if ! compset -P '(#b)([RP\+\-\!])'; then
  1073. local -a pattern_rules=(
  1074. 'P:pattern style'
  1075. 'R:root path'
  1076. '+:include'
  1077. '-:exclude'
  1078. '!:exclude non-recurse'
  1079. )
  1080. _describe -t pattern-rules 'pattern rule' pattern_rules -S ''
  1081. return
  1082. else
  1083. if [[ $compstate[quote] == (\'|\") ]]; then
  1084. compset -P ' #'
  1085. else
  1086. compset -P '(\\ )#'
  1087. fi
  1088. if [[ $match[1] == 'R' ]]; then
  1089. default_style_selector='pp'
  1090. elif [[ $match[1] == 'P' ]]; then
  1091. tags=( style-selectors )
  1092. ss_suf=()
  1093. fi
  1094. fi
  1095. fi
  1096. _tags $tags
  1097. while _tags; do
  1098. if _requested style-selectors; then
  1099. _all_labels style-selectors expl 'style selector' \
  1100. __borg_style_selectors $default_style_selector "$ss_suf[@]" - && ret=0
  1101. fi
  1102. if _requested archive-files; then
  1103. _all_labels archive-files expl 'PATTERN' \
  1104. __borg_archive_files ${(k)opts} "$arch" $default_style_selector - && ret=0
  1105. fi
  1106. if _requested files; then
  1107. local -a borg_paths=( ${(Q)${(e)${~@}}} )
  1108. _all_labels files expl 'PATH' \
  1109. __borg_pattern_files ${(k)opts} borg_paths - && ret=0
  1110. fi
  1111. (( ret )) || return 0
  1112. done
  1113. return 1
  1114. }
  1115. (( $+functions[__borg_style_selectors] )) ||
  1116. __borg_style_selectors() {
  1117. local default_style_selector=$1 path_style_selector
  1118. shift
  1119. zstyle -s ":completion:${curcontext}:archive-files" path-style-selector path_style_selector ||
  1120. path_style_selector='fm'
  1121. local -a disp
  1122. local -A style_selectors
  1123. __borg_setup_style_selectors
  1124. if zstyle -T ":completion:${curcontext}:style-selectors" verbose; then
  1125. local -a style_selector_descriptions extra
  1126. local k v sep
  1127. for k v in ${(kv)style_selectors}; do
  1128. extra=()
  1129. [[ $k == $default_style_selector ]] && extra+=( 'default' )
  1130. [[ $k == $path_style_selector ]] && __borg_choose_path_or_pattern "" "$default_style_selector" &&
  1131. extra+=( 'path' )
  1132. (( $#extra )) && v+=" (${(j:, :)extra})"
  1133. style_selector_descriptions+=( "${${k//\\/\\\\}//:/\\:}:$v" )
  1134. done
  1135. zstyle -s ":completion:${curcontext}:style-selectors" list-separator sep || sep=--
  1136. zformat -a style_selector_descriptions " $sep " $style_selector_descriptions
  1137. disp=( -ld style_selector_descriptions )
  1138. fi
  1139. compadd "$disp[@]" "$@" -k style_selectors
  1140. }
  1141. (( $+functions[__borg_archive_files] )) ||
  1142. __borg_archive_files() {
  1143. local -A opts
  1144. zparseopts -A opts -D e p
  1145. local arch=$1 default_style_selector=$2
  1146. shift 2
  1147. if [[ -z $arch || $arch != *::?* ]]; then
  1148. _message 'no archive specified'
  1149. return 1
  1150. fi
  1151. local -a qargs tmp disp pref match mbegin mend archive_files descs
  1152. local -A style_selectors
  1153. local k cword fmt descfmt style_selector path_style_selector name descr
  1154. # take into account exclude options on the command line
  1155. if (( $+opts[-e] )); then
  1156. local -a exclude_options=( -e --exclude --exclude-from --pattern --pattern-from )
  1157. local -a excludes
  1158. for k in $exclude_options; do
  1159. if [[ -n $opt_args[$k] ]]; then
  1160. IFS=: read -A tmp <<<$opt_args[$k]
  1161. excludes+=( $k="${^tmp[@]}" )
  1162. fi
  1163. done
  1164. [[ -n $excludes ]] && qargs+=( "$excludes[@]" )
  1165. fi
  1166. (( $_matcher_num > 1 )) && return 1
  1167. __borg_skip_pattern_matching || return 1
  1168. cword="$PREFIX$SUFFIX"
  1169. [[ $compstate[quote] != (\'|\") ]] && cword=${(Q)cword}
  1170. [[ -z $cword ]] && return 1
  1171. if zstyle -t ":completion:${curcontext}:archive-files" verbose; then
  1172. zstyle -s ":completion:${curcontext}:archive-files" file-description-format descfmt ||
  1173. descfmt='{mode} {user:6} {group:6} {size:8d} {mtime} {path}{extra}'
  1174. fmt="{bpath}{NUL}$descfmt{NUL}"
  1175. else
  1176. fmt='{bpath}{NUL}'
  1177. fi
  1178. qargs+=( --format=${(q)fmt} )
  1179. qargs+=( $arch )
  1180. __borg_setup_style_selectors
  1181. [[ $cword == (#b)(${~${(j:|:)${(kb)style_selectors}}}):* ]] && style_selector=$match[1]
  1182. local -i path_expected=0
  1183. __borg_choose_path_or_pattern "$style_selector" $default_style_selector $cword && path_expected=1
  1184. if [[ -n $cword ]]; then
  1185. if (( path_expected )); then
  1186. [[ -n $style_selector ]] && compset -P "$style_selector:" && pref=( -P "$style_selector:" )
  1187. cword="$PREFIX$SUFFIX"
  1188. [[ $compstate[quote] != (\'|\") ]] && cword=${(Q)cword}
  1189. zstyle -s ":completion:${curcontext}:archive-files" path-style-selector path_style_selector ||
  1190. path_style_selector='fm'
  1191. cword="$path_style_selector:$cword"
  1192. else
  1193. [[ -z $style_selector ]] && cword="$default_style_selector:$cword"
  1194. fi
  1195. qargs+=( ${(q)cword} )
  1196. fi
  1197. if zstyle -t ":completion:${curcontext}:archive-files" verbose; then
  1198. _call_program -p archive-file-descriptions ${(q)__borg_command:-borg} list $qargs 2>/dev/null |
  1199. while IFS= read -r -d $'\0' name && IFS= read -r -d $'\0' descr; do
  1200. archive_files+=( $name )
  1201. descs+=( $descr )
  1202. done
  1203. (( $pipestatus[1] )) && { _message "couldn't list archive: ${(Q)arch}"; return 1 }
  1204. disp=( -ld descs )
  1205. else
  1206. archive_files=( ${(0)"$(_call_program -p archive-files ${(q)__borg_command:-borg} list $qargs 2>/dev/null)"} )
  1207. (( $pipestatus[1] )) && { _message "couldn't list archive: ${(Q)arch}"; return 1 }
  1208. fi
  1209. if (( $#archive_files )); then
  1210. if (( path_expected )); then
  1211. compstate[insert]='automenu'
  1212. else
  1213. compstate[insert]=''
  1214. compstate[list]='list force'
  1215. fi
  1216. fi
  1217. compadd "$pref[@]" -U "$disp[@]" "$@" -a archive_files
  1218. }
  1219. (( $+functions[__borg_choose_path_or_pattern] )) ||
  1220. __borg_choose_path_or_pattern() {
  1221. local ss=$1 defss=$2 cword=$3
  1222. shift 2
  1223. [[ $ss == (pp|pf) || ( -z $ss && $defss == (pp|pf) ) ]]
  1224. }
  1225. # transform borg exclude patterns into zsh ignore patterns and then complete files
  1226. (( $+functions[__borg_pattern_files] )) ||
  1227. __borg_pattern_files() {
  1228. local -A opts
  1229. zparseopts -A opts -D -E e p f
  1230. local paths_varname=$1
  1231. shift
  1232. local -a args
  1233. local -A style_selectors
  1234. __borg_setup_style_selectors
  1235. local pr_pat='[RP\+\-\!]' ss_pat="(${(j:|:)${(@kb)style_selectors}}):"
  1236. local prs_pat="$pr_pat #"
  1237. if (( $+opts[-e] )); then
  1238. local -a borg_excludes exclude_options=( -e --exclude --pattern ) tmp
  1239. local k cword
  1240. local -i i
  1241. for k in $exclude_options; do
  1242. if [[ -n $opt_args[$k] ]]; then
  1243. IFS=: read -A tmp <<<$opt_args[$k]
  1244. tmp=( ${(Q)tmp} )
  1245. # lstrip style selectors and pattern rules
  1246. [[ $+opts[-p] -gt 0 || $k == --pattern ]] && tmp=( ${tmp#$~prs_pat} )
  1247. tmp=( ${tmp#$~ss_pat} )
  1248. # don't take into account the word under the cursor
  1249. cword="$PREFIX$SUFFIX"
  1250. [[ $compstate[quote] != (\'|\") ]] && cword=${(Q)cword}
  1251. [[ $+opts[-p] -gt 0 || $k == --pattern ]] && cword=${cword#$~prs_pat}
  1252. cword=${cword#$~ss_pat}
  1253. i=$tmp[(I)$cword]
  1254. (( i )) && tmp=( "${(@)tmp[1,i-1]}" "${(@)tmp[i+1,-1]}" )
  1255. borg_excludes+=( "$tmp[@]" )
  1256. fi
  1257. done
  1258. [[ -n $borg_excludes ]] && args+=( -F borg_excludes )
  1259. fi
  1260. [[ -n ${(P)paths_varname} ]] && args+=( -W $paths_varname )
  1261. args+=( "$@" )
  1262. # lstrip style selectors and pattern rules
  1263. if (( $+opts[-p] )); then
  1264. if [[ $compstate[quote] != (\'|\") ]]; then
  1265. compset -P $pr_pat
  1266. compset -P '(\\ )#'
  1267. else
  1268. compset -P $prs_pat
  1269. fi
  1270. fi
  1271. compset -P $ss_pat
  1272. compstate[insert]=''
  1273. compstate[list]='list force'
  1274. _path_files "$args[@]"
  1275. }
  1276. (( $+functions[__borg_setup_style_selectors] )) ||
  1277. __borg_setup_style_selectors() {
  1278. typeset -gA style_selectors=(
  1279. fm 'Fnmatch'
  1280. sh 'Shell-style patterns'
  1281. re 'Regular expressions'
  1282. pp 'Path prefix'
  1283. pf 'Path full-match'
  1284. )
  1285. }
  1286. (( $+functions[__borg_skip_pattern_matching] )) ||
  1287. __borg_skip_pattern_matching() {
  1288. # unset glob_complete
  1289. [[ $compstate[pattern_match] == '*' ]] && compstate[pattern_match]=''
  1290. # skip the _match completer
  1291. [[ -n $compstate[pattern_match] ]] && return 1
  1292. return 0
  1293. }
  1294. (( $+functions[_borg_config] )) ||
  1295. _borg_config() {
  1296. local qrepo=$1
  1297. shift
  1298. if (( ! $+__borg_config_sect )); then
  1299. comppostfuncs+=( __borg_unset_config )
  1300. typeset -gH __borg_config_sect=
  1301. typeset -gHa __borg_config_keys=()
  1302. local sect line
  1303. local -a match mbegin mend
  1304. _call_program -p keys ${(q)__borg_command:-borg} config --list $qrepo 2>/dev/null | {
  1305. IFS= read -r sect
  1306. sect=${${sect#\[}%\]}
  1307. __borg_config_sect=$sect
  1308. while IFS= read -r line && [[ $line == (#b)(*)\ =\ (*) ]]; do
  1309. __borg_config_keys+=( "${${match[1]//\\/\\\\}//:/\\:}:(current: $match[2])" )
  1310. done
  1311. }
  1312. fi
  1313. local -a alts=( 'keys:key: _describe -t keys "key" __borg_config_keys' )
  1314. compset -P "${__borg_config_sect}." || alts+=( 'sections:section:compadd -S "." $__borg_config_sect' )
  1315. _alternative $alts
  1316. }
  1317. (( $+functions[__borg_unset_config] )) ||
  1318. __borg_unset_config() {
  1319. unset __borg_config_sect __borg_config_keys
  1320. }
  1321. # A simple prefix-oriented completion function for compressors. Can be improved by supporting the suffix.
  1322. (( $+functions[_borg_compression] )) ||
  1323. _borg_compression() {
  1324. local -a nolvl=(
  1325. 'none:do not compress'
  1326. 'lz4:very high speed, very low compression'
  1327. )
  1328. local -a havelvl=(
  1329. 'zstd:("zstandart")'
  1330. 'zlib:("gz") medium speed, medium compression'
  1331. 'lzma:("xz") low speed, high compression'
  1332. )
  1333. local -a auto=(
  1334. 'auto:compress compressible, otherwise "none"'
  1335. )
  1336. local -a match mbegin mend
  1337. # NOTE: Zsh's `-prefix` condition is confused by the leading parenthesis in the pattern.
  1338. # Fortunately, we simply need to show a message.
  1339. if compset -P '(#b)(|auto,)(zstd|zlib|lzma),'; then
  1340. local -i from to def
  1341. case $match[2] in
  1342. (zstd) from=1 to=22 def=3 ;;
  1343. (zlib|lzma) from=0 to=9 def=6 ;;
  1344. esac
  1345. _message -e "compression level (from $from to $to, default: $def)"
  1346. elif compset -P 'auto,'; then
  1347. _describe -t compression 'compression' nolvl -- havelvl -qS,
  1348. else
  1349. _describe -t compression 'compression' nolvl -- havelvl -qS, -- auto -S,
  1350. fi
  1351. }
  1352. (( $+functions[_borg_chunker_params] )) ||
  1353. _borg_chunker_params() {
  1354. if compset -P 'buzhash,'; then
  1355. if compset -P '*,*,*,'; then
  1356. _message -e 'HASH_WINDOW_SIZE'
  1357. elif compset -P '*,*,'; then
  1358. _message -e 'HASH_MASK_BITS (statistical medium chunk size ~= 2^HASH_MASK_BITS B)'
  1359. elif compset -P '*,'; then
  1360. _message -e 'CHUNK_MAX_EXP (maximum chunk size = 2^CHUNK_MAX_EXP B)'
  1361. else
  1362. _message -e 'CHUNK_MIN_EXP (minimum chunk size = 2^CHUNK_MIN_EXP B)'
  1363. fi
  1364. elif compset -P 'fixed,'; then
  1365. if compset -P '*,'; then
  1366. _message -e 'HEADER_SIZE (B)'
  1367. else
  1368. _message -e 'BLOCK_SIZE (B)'
  1369. fi
  1370. else
  1371. local -a algorithms=(
  1372. 'fixed:a simple, low cpu overhead, fixed blocksize chunker, optionally supporting a header block of different size'
  1373. 'buzhash:variable, content-defined blocksize, uses a rolling hash computed by the Buzhash algorithm'
  1374. )
  1375. _describe -t algorithm 'ALGO' algorithms -S ,
  1376. fi
  1377. }
  1378. (( $+functions[_borg_chunker_params_examples] )) ||
  1379. _borg_chunker_params_examples() {
  1380. local -a params=(
  1381. 'default:buzhash,19,23,21,4095'
  1382. 'buzhash,19,23,21,4095:small amount of chunks (default)'
  1383. 'buzhash,10,23,16,4095:big amount of chunks'
  1384. )
  1385. params=( ${(q)params} )
  1386. _alternative \
  1387. 'chunker-params: :_borg_chunker_params' \
  1388. "chunker-params-examples:chunker params examples:(($params))"
  1389. }
  1390. (( $+functions[_borg_statuschars] )) ||
  1391. _borg_statuschars() {
  1392. _values -s '' 'STATUSCHARS' \
  1393. 'A[regular file, added]' \
  1394. 'M[regular file, modified]' \
  1395. 'U[regular file, unchanged]' \
  1396. 'C[regular file, it changed while we backed it up]' \
  1397. 'E[regular file, an error happened while accessing/reading this file]' \
  1398. 'd[directory]' \
  1399. 'b[block device]' \
  1400. 'c[char device]' \
  1401. 'h[regular file, hardlink (to already seen inodes)]' \
  1402. 's[symlink]' \
  1403. 'f[fifo]' \
  1404. 'i[backup data was read from standard input (stdin)]' \
  1405. '-[dry run, item was not backed up]' \
  1406. 'x[excluded, item was not backed up]' \
  1407. '?[missing status code]'
  1408. }
  1409. (( $+functions[_borg_quota_suffixes] )) ||
  1410. _borg_quota_suffixes() {
  1411. if compset -P '[0-9]##'; then
  1412. local -a suffixes=(
  1413. 'K:10 ** 3 bytes'
  1414. 'M:10 ** 6 bytes'
  1415. 'G:10 ** 9 bytes'
  1416. 'T:10 ** 12 bytes'
  1417. 'P:10 ** 15 bytes'
  1418. )
  1419. # NOTE: tag `suffixes` is already in use (file extensions)
  1420. _describe -t multiplier 'suffix' suffixes
  1421. else
  1422. _message -e 'QUOTA'
  1423. fi
  1424. }
  1425. (( $+functions[_borg_timestamp] )) ||
  1426. _borg_timestamp() {
  1427. _alternative \
  1428. "dates:TIMESTAMP: _dates -f '%FT%T'" \
  1429. 'files:reference:_files'
  1430. }
  1431. (( $+functions[_borg_guard_unsigned_number] )) ||
  1432. _borg_guard_unsigned_number() {
  1433. local -A opts
  1434. zparseopts -K -D -A opts M+: J+: V+: 1 2 o+: n F: x+: X+:
  1435. _guard '[0-9]#' ${1:-number}
  1436. }
  1437. _borg() {
  1438. local -a match mbegin mend line state
  1439. local curcontext="$curcontext" state_descr
  1440. typeset -A opt_args
  1441. local -i ret=1
  1442. if [[ $service == 'borg' ]]; then
  1443. local __borg_command=$words[1]
  1444. local -a common_options
  1445. __borg_setup_common_options
  1446. _arguments -s -w -C : \
  1447. '(- :)'{-V,--version}'[show version number and exit]' \
  1448. $common_options \
  1449. '(-): :->command' \
  1450. '(-)*:: :->option-or-argument' && return
  1451. case $state in
  1452. (command)
  1453. _borg_commands && ret=0
  1454. ;;
  1455. (option-or-argument)
  1456. curcontext="${curcontext%:*:*}:borg-$words[1]:"
  1457. if ! _call_function ret _borg-$words[1]; then
  1458. _default && ret=0
  1459. fi
  1460. ;;
  1461. esac
  1462. elif [[ $service == (#b)-value-,BORG_(*),-default- ]]; then
  1463. _borg_parameters $match[1] && ret=0
  1464. elif ! _call_function ret _$service; then
  1465. _default && ret=0
  1466. fi
  1467. return ret
  1468. }
  1469. _borg "$@"