_borg 56 KB

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