_borg 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  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 to explicitly 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. '--bypass-lock[bypass locking mechanism]'
  595. '(- :)--show-version[show/log the borg version]'
  596. '--show-rc[show/log the return code (rc)]'
  597. '--umask=[set umask to M (local only, default: 0077)]:M'
  598. '--remote-path=[set remote path to executable (default: "borg")]: :_cmdstring'
  599. '--remote-ratelimit=[set remote network upload rate limit in kiByte/s (default: 0=unlimited)]: : _borg_guard_unsigned_number "RATE"'
  600. '--remote-buffer=[set upload buffer size in MiB. (default: 0=no buffer)]: : _borg_guard_unsigned_number "UPLOAD_BUFFER"'
  601. '--consider-part-files[treat part files like normal files (e.g. to list/extract them)]'
  602. '--debug-profile=[write execution profile in Borg format into FILE]:FILE:_files'
  603. '--rsh=[use COMMAND instead of ssh]: :_cmdstring'
  604. )
  605. }
  606. (( $+functions[__borg_setup_common_exclude_options] )) ||
  607. __borg_setup_common_exclude_options() {
  608. typeset -ga common_exclude_options=(
  609. '*'{-e,--exclude}'=[exclude paths matching PATTERN]: : _borg_style_selector_or_archive_files "$line[1]" fm'
  610. '*--exclude-from=[read exclude patterns from EXCLUDEFILE, one per line]:EXCLUDEFILE:_files'
  611. '*--pattern=[experimental: include/exclude paths matching PATTERN]: : _borg_style_selector_or_archive_files -p "$line[1]" sh'
  612. '*--patterns-from=[experimental: read include/exclude patterns from PATTERNFILE, one per line]:PATTERNFILE:_files'
  613. )
  614. }
  615. (( $+functions[__borg_setup_common_exclude_extract_options] )) ||
  616. __borg_setup_common_exclude_extract_options() {
  617. local -a common_exclude_options
  618. __borg_setup_common_exclude_options
  619. typeset -ga common_exclude_extract_options=(
  620. $common_exclude_options
  621. '--strip-components=[Remove the specified number of leading path elements. Paths with fewer elements will be silently skipped.]: : _borg_guard_unsigned_number "NUMBER"'
  622. )
  623. }
  624. (( $+functions[__borg_setup_common_prefix_and_glob_archives_filter_options] )) ||
  625. __borg_setup_common_prefix_and_glob_archives_filter_options() {
  626. typeset -ga common_prefix_and_glob_archives_filter_options=(
  627. '(-P --prefix -a --glob-archives)'{-P,--prefix}'=[only consider archive names starting with this prefix]:PREFIX: _borg_archive -n "${line[1]%%\:\:*}"'
  628. '(-P --prefix)*'{-a,--glob-archives}'=[only consider archive names matching the glob]:GLOB: _borg_archive -n "${line[1]%%\:\:*}"'
  629. )
  630. }
  631. (( $+functions[__borg_setup_common_archive_filters_options] )) ||
  632. __borg_setup_common_archive_filters_options() {
  633. local -a common_prefix_and_glob_archives_filter_options
  634. __borg_setup_common_prefix_and_glob_archives_filter_options
  635. typeset -ga common_archive_filters_options=(
  636. $common_prefix_and_glob_archives_filter_options
  637. '--sort-by=[Comma-separated list of sorting keys, default: timestamp]:KEYS:(timestamp name id)'
  638. '(--last)--first=[consider first N archives after other filters were applied]:N: _borg_archive -n "${line[1]%%\:\:*}"'
  639. '(--first)--last=[consider last N archives after other filters were applied]:N: _borg_archive -n "${line[1]%%\:\:*}"'
  640. )
  641. }
  642. (( $+functions[__borg_setup_common_dry_run_stats_options] )) ||
  643. __borg_setup_common_dry_run_stats_options() {
  644. typeset -ga common_dry_run_stats_options=(
  645. '(-n --dry-run -s --stats)'{-n,--dry-run}'[do not change anything]'
  646. '(-n --dry-run -s --stats)'{-s,--stats}'[print statistics at end]'
  647. # NOTE: actual messages for subcommands differ in details
  648. )
  649. }
  650. (( $+functions[__borg_setup_common_create_options] )) ||
  651. __borg_setup_common_create_options() {
  652. local -a common_dry_run_stats_options common_exclude_options
  653. __borg_setup_common_dry_run_stats_options
  654. __borg_setup_common_exclude_options
  655. typeset -ga common_create_options=(
  656. $common_dry_run_stats_options
  657. '--list[output verbose list of items (files, dirs, ...)]'
  658. '--filter=[only display items with the given status characters]: :_borg_statuschars'
  659. $common_exclude_options
  660. '--exclude-caches[exclude directories that contain a CACHEDIR.TAG file]'
  661. '*--exclude-if-present=[exclude directories that are tagged by containing a filesystem object with the given NAME]:NAME:_files'
  662. '--keep-exclude-tags[if tag objects are specified with --exclude-if-present, don'\''t omit the tag objects themselves]'
  663. '--comment=[add a comment text to the archive]:COMMENT:_borg_placeholders'
  664. '--timestamp=[manually specify the archive creation date/time]:TIMESTAMP:_borg_timestamp'
  665. '(-c --checkpoint-interval)'{-c,--checkpoint-interval}'=[write checkpoint every SECONDS seconds (default: 1800)]: : _borg_guard_unsigned_number "SECONDS"'
  666. '--chunker-params=[specify the chunker parameters]: :_borg_chunker_params_examples'
  667. '(-C --compression)'{-C,--compression}'=[select compression algorithm]: :_borg_compression'
  668. )
  669. }
  670. (( $+functions[__borg_setup_common_init_options] )) ||
  671. __borg_setup_common_init_options() {
  672. local -a common_options
  673. __borg_setup_common_options
  674. typeset -ga common_init_options=(
  675. $common_options
  676. '--append-only[only allow appending to repository segment files]'
  677. '--storage-quota=[override storage quota of the repository]: :_borg_quota_suffixes'
  678. )
  679. }
  680. (( $+functions[_borgfs] )) ||
  681. _borgfs() {
  682. _borg-mount '(- :)'{-V,--version}'[show version number and exit]'
  683. }
  684. (( $+functions[_borg_parameters] )) ||
  685. _borg_parameters() {
  686. local name=$1
  687. shift
  688. local -i ret=1
  689. local -a expl
  690. case $name in
  691. (REPO)
  692. local BORG_REPO
  693. unset BORG_REPO
  694. _borg_repository && ret=0
  695. ;;
  696. ((|NEW_)PASSPHRASE)
  697. _message -e 'passphrase' && ret=0
  698. ;;
  699. (DISPLAY_PASSPHRASE)
  700. _message -e 'answer to the "display the passphrase for verification" question' && ret=0
  701. ;;
  702. (HOST_ID)
  703. _message -e 'unique ID' && ret=0
  704. ;;
  705. (FILES_CACHE_TTL)
  706. _borg_guard_unsigned_number 'time to live (default: 20)' && ret=0
  707. ;;
  708. (MOUNT_DATA_CACHE_ENTRIES)
  709. _borg_guard_unsigned_number 'number of cached data chunks' && ret=0
  710. ;;
  711. (PASSCOMMAND|RSH|REMOTE_PATH)
  712. _cmdstring && ret=0
  713. ;;
  714. (HOSTNAME_IS_UNIQUE|SHOW_SYSINFO|(UNKNOWN_UNENCRYPTED|RELOCATED)_REPO_ACCESS_IS_OK)
  715. _description values expl 'value'
  716. compadd "$expl[@]" yes no && ret=0
  717. ;;
  718. ((CHECK|DELETE)_I_KNOW_WHAT_I_AM_DOING)
  719. _description values expl 'value'
  720. compadd "$expl[@]" YES NO && ret=0
  721. ;;
  722. (LIBC)
  723. _wanted libraries expl 'library' \
  724. compadd - ${^=LD_LIBRARY_PATH:-/usr/lib /usr/local/lib}/lib*.(a|so*)(:t:fr:s/lib//) && ret=0
  725. ;;
  726. (SELFTEST)
  727. _description values expl 'value'
  728. compadd "$expl[@]" disabled && ret=0
  729. ;;
  730. (WORKAROUNDS)
  731. _wanted workarounds expl 'workaround' _sequence compadd - basesyncfile && ret=0
  732. ;;
  733. (KEYS_DIR)
  734. _directories && ret=0
  735. ;;
  736. (*)
  737. _default && ret=0
  738. ;;
  739. esac
  740. return ret
  741. }
  742. (( $+functions[_borg_repository] )) ||
  743. _borg_repository() {
  744. local -a alts opts qopts
  745. zparseopts -E -a opts S:
  746. qopts=( ${(q)opts} )
  747. [[ -n $BORG_REPO ]] && alts+=( "default-repository: : __borg_default_repository $qopts" )
  748. alts+=( "cached-repositories:cached repositories:_borg_cached_repositories $qopts" )
  749. alts+=( 'directories: :_directories -r ":/ \t\n\-"' )
  750. alts+=( 'remote-repositories: : _borg_remote_repositories' )
  751. _alternative $alts
  752. }
  753. (( $+functions[__borg_default_repository] )) ||
  754. __borg_default_repository() {
  755. local -a opts suf
  756. zparseopts -E -a opts S:
  757. (( $opts[(I)-S] )) && suf=( -S '' )
  758. local -a default_repository=( "\:\::$BORG_REPO" )
  759. _describe -t default-repository 'default repository' default_repository "$suf[@]"
  760. }
  761. (( $+functions[_borg_cached_repositories] )) ||
  762. _borg_cached_repositories() {
  763. local -a cached_repos
  764. local sed_script='/^previous_location = / {
  765. s///
  766. # no port was given
  767. /ssh:\/\/[^/:]+:[0-9]+/! {
  768. # lstrip the `ssh://` prefix and add a colon before the first slash
  769. s!ssh://([^:/]+)/(.*)!\1:/\2!
  770. }
  771. p
  772. }'
  773. local cachedir=${BORG_CACHE_DIR:-${XDG_CACHE_HOME:-${BORG_BASE_DIR:-$HOME}/.cache}/borg}
  774. cached_repos=( ${(f)"$(_call_program -p cached-repositories sed -n -E ${(q)sed_script} \
  775. "${(q)cachedir}/*/config(#qN.om)" 2>/dev/null)"} )
  776. if [[ $compstate[quote] != (\'|\") ]]; then
  777. # hide ~BORG_REPO and other scalars
  778. local BORG_REPO
  779. unset BORG_REPO sed_script cachedir
  780. cached_repos=( "${(@D)cached_repos}" )
  781. fi
  782. compadd -Q "$@" -r ': \t\n\-' -a cached_repos
  783. }
  784. (( $+functions[_borg_remote_repositories] )) ||
  785. _borg_remote_repositories() {
  786. local -a match mbegin mend expl alts
  787. if compset -P '(#b)ssh://[^/]##@[^/]##:([0-9]##)/'; then
  788. _remote_files -/ -- ssh -p $match[1]
  789. return
  790. fi
  791. local -i have_scheme=0
  792. compset -P 'ssh://' && have_scheme=1
  793. if compset -P '*:'; then
  794. (( have_scheme )) && alts+=( 'ports: : _borg_guard_unsigned_number "port"' )
  795. alts+=( 'remote-files:remote file: _remote_files -/ -- ssh' )
  796. _alternative $alts
  797. elif compset -P 1 '(#b)(*)@'; then
  798. local user=$match[1]
  799. _wanted -C user-at hosts expl "host for $user" \
  800. _combination -s '[:@]' accounts users-hosts users="$user" hosts -S ':' -
  801. elif compset -S '@*'; then
  802. _wanted users expl "user" \
  803. _combination -s '[:@]' accounts users-hosts users -q -
  804. else
  805. alts=(
  806. 'users:user:_users -S "@"'
  807. 'hosts:host:_hosts -S ":"'
  808. )
  809. (( ! have_scheme )) && alts+=( 'prefixes:ssh:compadd -S "" ssh://' )
  810. _alternative $alts
  811. fi
  812. }
  813. # _borg_repository_or_archive [-a] [-p]
  814. #
  815. # -a archive is mandatory. The suffix `::` will be added to the repository if possible.
  816. # -p complete placeholders
  817. (( $+functions[_borg_repository_or_archive] )) ||
  818. _borg_repository_or_archive() {
  819. local -A opts
  820. zparseopts -A opts -D -E a p
  821. if compset -P 1 '*::'; then
  822. local qrepo=$IPREFIX[1,-3]
  823. local -i def_repo=0
  824. [[ -z $qrepo && -n $BORG_REPO ]] && qrepo=${(q)BORG_REPO} && def_repo=1
  825. if [[ -n $qrepo ]]; then
  826. if (( ! def_repo )); then
  827. case $compstate[quote] in
  828. (\') qrepo=${(qq)qrepo} ;;
  829. (\") qrepo=${(qqq)${(e)qrepo}} ;;
  830. # NOTE: currently `(e)` don't have any effect, but maybe one day zsh will stop to change the quoting method
  831. # of double quoted parameters
  832. esac
  833. fi
  834. if (( $+opts[-p] )); then
  835. _borg_placeholder_or_archive $qrepo
  836. else
  837. _borg_archive $qrepo
  838. fi
  839. else
  840. _message "not a borg repository: ${(Q)qrepo}"
  841. return 1
  842. fi
  843. else
  844. local -a suf
  845. if ! compset -S '::*'; then
  846. if (( $+opts[-a] )) || zstyle -T ":completion:${curcontext}:repositories" repository-suffix; then
  847. suf=( -S '::' )
  848. fi
  849. local oqrepo="$PREFIX$SUFFIX"
  850. local qrepo=$oqrepo
  851. [[ $compstate[quote] != (\'|\") ]] && qrepo=${(Q)qrepo}
  852. if __borg_is_borg_repo $qrepo; then
  853. qrepo=${oqrepo%%/}
  854. [[ -z $SUFFIX ]] && PREFIX=${PREFIX%%/} || SUFFIX=${SUFFIX%%/}
  855. compadd -S '::' -r ':/ \t\n\-' -Q -- $qrepo
  856. return
  857. fi
  858. fi
  859. _borg_repository "$suf[@]"
  860. fi
  861. }
  862. # _borg_archive [-F] [-n] [qrepo]
  863. #
  864. # -F don't apply archive filter options on the command line
  865. # -n reverse order, disable matchers and don't do menu completion/selection
  866. (( $+functions[_borg_archive] )) ||
  867. _borg_archive() {
  868. local -A opts
  869. zparseopts -A opts -D -E F n
  870. local qrepo=$1
  871. if [[ -z $qrepo ]]; then
  872. if [[ -n $BORG_REPO ]]; then
  873. qrepo=${(q)BORG_REPO}
  874. else
  875. _message 'no repository specified'
  876. return 1
  877. fi
  878. fi
  879. local -i ret=1
  880. _tags archives
  881. while _tags; do
  882. if _requested archives; then
  883. local -a expl disp archive_filters
  884. local -i reversed_order=1
  885. if (( ! $+opts[-F] )); then
  886. local -a archive_filter_options=( -P --prefix -a --glob-archives --first --last --sort-by ) tmp
  887. local k
  888. for k in $archive_filter_options; do
  889. if [[ -n $opt_args[$k] ]]; then
  890. IFS=: read -A tmp <<<$opt_args[$k]
  891. archive_filters+=( $k=${^tmp:#} )
  892. fi
  893. done
  894. fi
  895. if (( $+opts[-n] )); then
  896. __borg_skip_pattern_matching || return 1
  897. disp+=( -U )
  898. compstate[insert]=''
  899. compstate[list]='list force'
  900. reversed_order=0
  901. fi
  902. local -a asort
  903. zstyle -a ":completion:${curcontext}:archives" archive-sort asort
  904. if (( $asort[(I)inverse] )); then
  905. (( reversed_order = ! reversed_order ))
  906. fi
  907. local -a sort_by=( --sort-by=${(M)^asort:#(timestamp|name|id)} )
  908. # NOTE: in case of option repetition, the later one takes precedence
  909. if (( ! $+__borg_archives_need_update )); then
  910. comppostfuncs+=( __borg_unset_archives_need_update )
  911. typeset -gHi __borg_archives_need_update=1
  912. if (( ! $#archive_filters && ! $+opts[-n] )); then
  913. local erepo
  914. [[ -n $1 ]] && __borg_expand_path ${(Q)qrepo} erepo
  915. local -a newest_file=( $erepo/(hints|index|integrity).<1->(#qN.om[1]) )
  916. if [[ -n $newest_file ]]; then
  917. if zmodload -F zsh/stat b:zstat 2>/dev/null; then
  918. local -a stats
  919. zstat -A stats +mtime $newest_file
  920. local -i mtime=$stats[1]
  921. if [[ $__borg_prev_repo == $erepo
  922. && __borg_prev_mtime -ge mtime
  923. && $__borg_prev_order == $reversed_order
  924. && $__borg_prev_sort_by == $sort_by ]]
  925. then
  926. __borg_archives_need_update=0
  927. else
  928. typeset -gH __borg_prev_repo=$erepo
  929. typeset -gHi __borg_prev_mtime=mtime __borg_prev_order=reversed_order
  930. typeset -gHa __borg_prev_sort_by=( $sort_by )
  931. fi
  932. fi
  933. fi
  934. else
  935. unset __borg_prev_{repo,mtime,order,sort_by}
  936. comppostfuncs+=( __borg_unset_archives )
  937. fi
  938. fi
  939. if zstyle -t ":completion:${curcontext}:archives" verbose; then
  940. if (( __borg_archives_need_update || ! $+__borg_archive_names || ! $+__borg_archive_descriptions )); then
  941. __borg_archives_need_update=0
  942. typeset -gHa __borg_archive_names=() __borg_archive_descriptions=()
  943. local fmt descfmt name desc
  944. zstyle -s ":completion:${curcontext}:archives" archive-description-format descfmt ||
  945. descfmt='{archive:<36} {time} [{id}]'
  946. fmt="{barchive}{NUL}$descfmt{NUL}"
  947. _call_program -p archive-descriptions \
  948. ${(q)__borg_command:-borg} list --format=${(q)fmt} ${(q)sort_by} $archive_filters $qrepo 2>/dev/null |
  949. while IFS= read -r -d $'\0' name && IFS= read -r -d $'\0' descr; do
  950. __borg_archive_names[1,0]=( $name )
  951. __borg_archive_descriptions[1,0]=( "$descr" )
  952. done
  953. (( $pipestatus[1] )) && {
  954. _message "couldn't list repository: ${(Q)qrepo}"
  955. unset __borg_prev_{repo,mtime,order,sort_by}
  956. return 1
  957. }
  958. (( ! reversed_order )) &&
  959. __borg_archive_names=( "${(@aO)__borg_archive_names}" ) &&
  960. __borg_archive_descriptions=( "${(@aO)__borg_archive_descriptions}" )
  961. fi
  962. disp+=( -ld __borg_archive_descriptions )
  963. elif (( __borg_archives_need_update || ! $+__borg_archive_names )); then
  964. __borg_archives_need_update=0
  965. typeset -gHa __borg_archive_names=()
  966. local fmt='{barchive}{NUL}'
  967. __borg_archive_names=( ${(@0aO)"$(_call_program -p archives \
  968. ${(q)__borg_command:-borg} list --format=${(q)fmt} ${(q)sort_by} $archive_filters $qrepo 2>/dev/null)"} )
  969. (( $pipestatus[1] )) && {
  970. _message "couldn't list repository: ${(Q)qrepo}"
  971. unset __borg_prev_{repo,mtime,order,sort_by}
  972. return 1
  973. }
  974. (( ! reversed_order )) &&
  975. __borg_archive_names=( "${(@aO)__borg_archive_names}" )
  976. fi
  977. _all_labels archives expl 'ARCHIVE' compadd "$disp[@]" -a __borg_archive_names && ret=0
  978. fi
  979. (( ret )) || return 0
  980. done
  981. return 1
  982. }
  983. (( $+functions[__borg_unset_archives] )) ||
  984. __borg_unset_archives() {
  985. unset __borg_archive_names __borg_archive_descriptions
  986. }
  987. (( $+functions[__borg_unset_archives_need_update] )) ||
  988. __borg_unset_archives_need_update() {
  989. unset __borg_archives_need_update
  990. }
  991. (( $+functions[__borg_is_borg_repo] )) ||
  992. __borg_is_borg_repo() {
  993. local repo=$1
  994. __borg_expand_path $repo repo
  995. if [[ -d $repo && -d $repo/data ]]; then
  996. local -a files=( $repo/(hints|index|integrity).<1->(#qN.) )
  997. (( $#files >= 3 )) && return 0
  998. fi
  999. return 1
  1000. }
  1001. (( $+functions[__borg_expand_path] )) ||
  1002. __borg_expand_path() {
  1003. local _path=$1
  1004. local -a match mbegin mend
  1005. if [[ $_path == (#b)(\~[^/]#)(|/*) ]]; then
  1006. local etilde
  1007. etilde=$~match[1] 2>/dev/null
  1008. _path="$etilde$match[2]"
  1009. fi
  1010. _path=${(e)_path//\\\\/\\\\\\\\}
  1011. eval typeset -g ${2:-REPLY}=\$_path
  1012. }
  1013. (( $+functions[_borg_placeholder_or_archive] )) ||
  1014. _borg_placeholder_or_archive() {
  1015. local qrepo=$1
  1016. shift
  1017. _alternative \
  1018. 'placeholders: :_borg_placeholders' \
  1019. "archives: : _borg_archive ${(q)qrepo}"
  1020. }
  1021. (( $+functions[_borg_placeholders] )) ||
  1022. _borg_placeholders() {
  1023. local -a placeholders=(
  1024. 'hostname:The (short) hostname of the machine.'
  1025. 'fqdn:The full name of the machine.'
  1026. 'reverse-fqdn:The full name of the machine in reverse domain name notation.'
  1027. '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}'
  1028. '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}'
  1029. 'user:The user name (or UID, if no name is available) of the user running borg.'
  1030. 'pid:The current process ID.'
  1031. 'borgversion:The version of borg, e.g.: 1.0.8rc1'
  1032. 'borgmajor:The version of borg, only the major version, e.g.: 1'
  1033. 'borgminor:The version of borg, only major and minor version, e.g.: 1.0'
  1034. 'borgpatch:The version of borg, only major, minor and patch version, e.g.: 1.0.8'
  1035. )
  1036. __borg_complete_keys _describe -t placeholders 'placeholder' placeholders '"$copts[@]"'
  1037. }
  1038. (( $+functions[_borg_format_keys] )) ||
  1039. _borg_format_keys() {
  1040. local repo_or_arch=${(Q)1}
  1041. local -a keys=( NEWLINE NL NUL SPACE TAB CR LF )
  1042. local -a repository_keys=( archive name barchive comment bcomment id start time end hostname username )
  1043. local -a archive_keys=( type mode uid gid user group path bpath source linktarget flags size csize dsize dcsize
  1044. num_chunks unique_chunks mtime ctime atime isomtime isoctime isoatime blake2b blake2s md5 sha1 sha224 sha256 sha384
  1045. sha3_224 sha3_256 sha3_384 sha3_512 sha512 shake_128 shake_256 archiveid archivename extra health )
  1046. local akeys rkeys
  1047. akeys='archive-keys:archive keys:compadd -a archive_keys'
  1048. rkeys='repository-keys:repository keys:compadd -a repository_keys'
  1049. local -a alts=( 'keys:keys:compadd -a keys' )
  1050. if [[ $repo_or_arch == *::?* ]]; then
  1051. alts+=( $akeys )
  1052. elif [[ -n $repo_or_arch ]]; then
  1053. alts+=( $rkeys )
  1054. else
  1055. alts+=( $rkeys $akeys )
  1056. fi
  1057. __borg_complete_keys _alternative -O copts ${(q)alts}
  1058. }
  1059. (( $+functions[__borg_complete_keys] )) ||
  1060. __borg_complete_keys() {
  1061. compset -P '*[^A-Za-z]##'
  1062. compset -S '[^A-Za-z]##*'
  1063. [[ -n $ISUFFIX ]] && compstate[to_end]=''
  1064. # NOTE: `[[ -n $ISUFFIX ]]` is a workaround for a bug that causes cursor movement to the right further than it should
  1065. # NOTE: the _oldlist completer doesn't respect compstate[to_end]=''
  1066. local ipref suf
  1067. if [[ $IPREFIX[-1] != '{' ]]; then
  1068. ipref='{'
  1069. [[ $compstate[quote] != (\'|\") ]] && ipref='\{'
  1070. fi
  1071. if [[ $ISUFFIX[1] != (|\\)\} ]]; then
  1072. suf='}'
  1073. [[ $compstate[quote] != (\'|\") ]] && suf='\}'
  1074. fi
  1075. local -a copts=( -i "$ipref" -S "$suf" )
  1076. eval "$@"
  1077. }
  1078. # _borg_style_selector_or_archive_files [-e] [-p] archive default_style_selector
  1079. #
  1080. # -e apply exclusion options on the command line
  1081. # -p complete `--pattern`
  1082. # -f complete files rather than borg paths
  1083. (( $+functions[_borg_style_selector_or_archive_files] )) ||
  1084. _borg_style_selector_or_archive_files() {
  1085. local -A opts
  1086. zparseopts -A opts -D -E e p f
  1087. local arch=$1 default_style_selector=$2
  1088. shift 2
  1089. local -a match mbegin mend expl tags=( style-selectors archive-files ) ss_suf=( -S ':' -r ':' )
  1090. (( $+opts[-f] )) && tags=( style-selectors files )
  1091. local -i ret=1
  1092. if (( $+opts[-p] )); then
  1093. if ! compset -P '(#b)([RP\+\-\!])'; then
  1094. local -a pattern_rules=(
  1095. 'P:pattern style'
  1096. 'R:root path'
  1097. '+:include'
  1098. '-:exclude'
  1099. '!:exclude non-recurse'
  1100. )
  1101. _describe -t pattern-rules 'pattern rule' pattern_rules -S ''
  1102. return
  1103. else
  1104. if [[ $compstate[quote] == (\'|\") ]]; then
  1105. compset -P ' #'
  1106. else
  1107. compset -P '(\\ )#'
  1108. fi
  1109. if [[ $match[1] == 'R' ]]; then
  1110. default_style_selector='pp'
  1111. elif [[ $match[1] == 'P' ]]; then
  1112. tags=( style-selectors )
  1113. ss_suf=()
  1114. fi
  1115. fi
  1116. fi
  1117. _tags $tags
  1118. while _tags; do
  1119. if _requested style-selectors; then
  1120. _all_labels style-selectors expl 'style selector' \
  1121. __borg_style_selectors $default_style_selector "$ss_suf[@]" - && ret=0
  1122. fi
  1123. if _requested archive-files; then
  1124. _all_labels archive-files expl 'PATTERN' \
  1125. __borg_archive_files ${(k)opts} "$arch" $default_style_selector - && ret=0
  1126. fi
  1127. if _requested files; then
  1128. local -a borg_paths=( ${(Q)${(e)${~@}}} )
  1129. _all_labels files expl 'PATH' \
  1130. __borg_pattern_files ${(k)opts} borg_paths - && ret=0
  1131. fi
  1132. (( ret )) || return 0
  1133. done
  1134. return 1
  1135. }
  1136. (( $+functions[__borg_style_selectors] )) ||
  1137. __borg_style_selectors() {
  1138. local default_style_selector=$1 path_style_selector
  1139. shift
  1140. zstyle -s ":completion:${curcontext}:archive-files" path-style-selector path_style_selector ||
  1141. path_style_selector='fm'
  1142. local -a disp
  1143. local -A style_selectors
  1144. __borg_setup_style_selectors
  1145. if zstyle -T ":completion:${curcontext}:style-selectors" verbose; then
  1146. local -a style_selector_descriptions extra
  1147. local k v sep
  1148. for k v in ${(kv)style_selectors}; do
  1149. extra=()
  1150. [[ $k == $default_style_selector ]] && extra+=( 'default' )
  1151. [[ $k == $path_style_selector ]] && __borg_choose_path_or_pattern "" "$default_style_selector" &&
  1152. extra+=( 'path' )
  1153. (( $#extra )) && v+=" (${(j:, :)extra})"
  1154. style_selector_descriptions+=( "${${k//\\/\\\\}//:/\\:}:$v" )
  1155. done
  1156. zstyle -s ":completion:${curcontext}:style-selectors" list-separator sep || sep=--
  1157. zformat -a style_selector_descriptions " $sep " $style_selector_descriptions
  1158. disp=( -ld style_selector_descriptions )
  1159. fi
  1160. compadd "$disp[@]" "$@" -k style_selectors
  1161. }
  1162. (( $+functions[__borg_archive_files] )) ||
  1163. __borg_archive_files() {
  1164. local -A opts
  1165. zparseopts -A opts -D e p
  1166. local arch=$1 default_style_selector=$2
  1167. shift 2
  1168. if [[ -z $arch || $arch != *::?* ]]; then
  1169. _message 'no archive specified'
  1170. return 1
  1171. fi
  1172. local -a qargs tmp disp pref match mbegin mend archive_files descs
  1173. local -A style_selectors
  1174. local k cword fmt descfmt style_selector path_style_selector name descr
  1175. # take into account exclude options on the command line
  1176. if (( $+opts[-e] )); then
  1177. local -a exclude_options=( -e --exclude --exclude-from --pattern --pattern-from )
  1178. local -a excludes
  1179. for k in $exclude_options; do
  1180. if [[ -n $opt_args[$k] ]]; then
  1181. IFS=: read -A tmp <<<$opt_args[$k]
  1182. excludes+=( $k="${^tmp[@]}" )
  1183. fi
  1184. done
  1185. [[ -n $excludes ]] && qargs+=( "$excludes[@]" )
  1186. fi
  1187. (( $_matcher_num > 1 )) && return 1
  1188. __borg_skip_pattern_matching || return 1
  1189. cword="$PREFIX$SUFFIX"
  1190. [[ $compstate[quote] != (\'|\") ]] && cword=${(Q)cword}
  1191. [[ -z $cword ]] && return 1
  1192. if zstyle -t ":completion:${curcontext}:archive-files" verbose; then
  1193. zstyle -s ":completion:${curcontext}:archive-files" file-description-format descfmt ||
  1194. descfmt='{mode} {user:6} {group:6} {size:8d} {mtime} {path}{extra}'
  1195. fmt="{bpath}{NUL}$descfmt{NUL}"
  1196. else
  1197. fmt='{bpath}{NUL}'
  1198. fi
  1199. qargs+=( --format=${(q)fmt} )
  1200. qargs+=( $arch )
  1201. __borg_setup_style_selectors
  1202. [[ $cword == (#b)(${~${(j:|:)${(kb)style_selectors}}}):* ]] && style_selector=$match[1]
  1203. local -i path_expected=0
  1204. __borg_choose_path_or_pattern "$style_selector" $default_style_selector $cword && path_expected=1
  1205. if [[ -n $cword ]]; then
  1206. if (( path_expected )); then
  1207. [[ -n $style_selector ]] && compset -P "$style_selector:" && pref=( -P "$style_selector:" )
  1208. cword="$PREFIX$SUFFIX"
  1209. [[ $compstate[quote] != (\'|\") ]] && cword=${(Q)cword}
  1210. zstyle -s ":completion:${curcontext}:archive-files" path-style-selector path_style_selector ||
  1211. path_style_selector='fm'
  1212. cword="$path_style_selector:$cword"
  1213. else
  1214. [[ -z $style_selector ]] && cword="$default_style_selector:$cword"
  1215. fi
  1216. qargs+=( ${(q)cword} )
  1217. fi
  1218. if zstyle -t ":completion:${curcontext}:archive-files" verbose; then
  1219. _call_program -p archive-file-descriptions ${(q)__borg_command:-borg} list $qargs 2>/dev/null |
  1220. while IFS= read -r -d $'\0' name && IFS= read -r -d $'\0' descr; do
  1221. archive_files+=( $name )
  1222. descs+=( $descr )
  1223. done
  1224. (( $pipestatus[1] )) && { _message "couldn't list archive: ${(Q)arch}"; return 1 }
  1225. disp=( -ld descs )
  1226. else
  1227. archive_files=( ${(0)"$(_call_program -p archive-files ${(q)__borg_command:-borg} list $qargs 2>/dev/null)"} )
  1228. (( $pipestatus[1] )) && { _message "couldn't list archive: ${(Q)arch}"; return 1 }
  1229. fi
  1230. if (( $#archive_files )); then
  1231. if (( path_expected )); then
  1232. compstate[insert]='automenu'
  1233. else
  1234. compstate[insert]=''
  1235. compstate[list]='list force'
  1236. fi
  1237. fi
  1238. compadd "$pref[@]" -U "$disp[@]" "$@" -a archive_files
  1239. }
  1240. (( $+functions[__borg_choose_path_or_pattern] )) ||
  1241. __borg_choose_path_or_pattern() {
  1242. local ss=$1 defss=$2 cword=$3
  1243. shift 2
  1244. [[ $ss == (pp|pf) || ( -z $ss && $defss == (pp|pf) ) ]]
  1245. }
  1246. # transform borg exclude patterns into zsh ignore patterns and then complete files
  1247. (( $+functions[__borg_pattern_files] )) ||
  1248. __borg_pattern_files() {
  1249. local -A opts
  1250. zparseopts -A opts -D -E e p f
  1251. local paths_varname=$1
  1252. shift
  1253. local -a args
  1254. local -A style_selectors
  1255. __borg_setup_style_selectors
  1256. local pr_pat='[RP\+\-\!]' ss_pat="(${(j:|:)${(@kb)style_selectors}}):"
  1257. local prs_pat="$pr_pat #"
  1258. if (( $+opts[-e] )); then
  1259. local -a borg_excludes exclude_options=( -e --exclude --pattern ) tmp
  1260. local k cword
  1261. local -i i
  1262. for k in $exclude_options; do
  1263. if [[ -n $opt_args[$k] ]]; then
  1264. IFS=: read -A tmp <<<$opt_args[$k]
  1265. tmp=( ${(Q)tmp} )
  1266. # lstrip style selectors and pattern rules
  1267. [[ $+opts[-p] -gt 0 || $k == --pattern ]] && tmp=( ${tmp#$~prs_pat} )
  1268. tmp=( ${tmp#$~ss_pat} )
  1269. # don't take into account the word under the cursor
  1270. cword="$PREFIX$SUFFIX"
  1271. [[ $compstate[quote] != (\'|\") ]] && cword=${(Q)cword}
  1272. [[ $+opts[-p] -gt 0 || $k == --pattern ]] && cword=${cword#$~prs_pat}
  1273. cword=${cword#$~ss_pat}
  1274. i=$tmp[(I)$cword]
  1275. (( i )) && tmp=( "${(@)tmp[1,i-1]}" "${(@)tmp[i+1,-1]}" )
  1276. borg_excludes+=( "$tmp[@]" )
  1277. fi
  1278. done
  1279. [[ -n $borg_excludes ]] && args+=( -F borg_excludes )
  1280. fi
  1281. [[ -n ${(P)paths_varname} ]] && args+=( -W $paths_varname )
  1282. args+=( "$@" )
  1283. # lstrip style selectors and pattern rules
  1284. if (( $+opts[-p] )); then
  1285. if [[ $compstate[quote] != (\'|\") ]]; then
  1286. compset -P $pr_pat
  1287. compset -P '(\\ )#'
  1288. else
  1289. compset -P $prs_pat
  1290. fi
  1291. fi
  1292. compset -P $ss_pat
  1293. compstate[insert]=''
  1294. compstate[list]='list force'
  1295. _path_files "$args[@]"
  1296. }
  1297. (( $+functions[__borg_setup_style_selectors] )) ||
  1298. __borg_setup_style_selectors() {
  1299. typeset -gA style_selectors=(
  1300. fm 'Fnmatch'
  1301. sh 'Shell-style patterns'
  1302. re 'Regular expressions'
  1303. pp 'Path prefix'
  1304. pf 'Path full-match'
  1305. )
  1306. }
  1307. (( $+functions[__borg_skip_pattern_matching] )) ||
  1308. __borg_skip_pattern_matching() {
  1309. # unset glob_complete
  1310. [[ $compstate[pattern_match] == '*' ]] && compstate[pattern_match]=''
  1311. # skip the _match completer
  1312. [[ -n $compstate[pattern_match] ]] && return 1
  1313. return 0
  1314. }
  1315. (( $+functions[_borg_config] )) ||
  1316. _borg_config() {
  1317. local qrepo=$1
  1318. shift
  1319. if (( ! $+__borg_config_sect )); then
  1320. comppostfuncs+=( __borg_unset_config )
  1321. typeset -gH __borg_config_sect=
  1322. typeset -gHa __borg_config_keys=()
  1323. local sect line
  1324. local -a match mbegin mend
  1325. _call_program -p keys ${(q)__borg_command:-borg} config --list $qrepo 2>/dev/null | {
  1326. IFS= read -r sect
  1327. sect=${${sect#\[}%\]}
  1328. __borg_config_sect=$sect
  1329. while IFS= read -r line && [[ $line == (#b)(*)\ =\ (*) ]]; do
  1330. __borg_config_keys+=( "${${match[1]//\\/\\\\}//:/\\:}:(current: $match[2])" )
  1331. done
  1332. }
  1333. fi
  1334. local -a alts=( 'keys:key: _describe -t keys "key" __borg_config_keys' )
  1335. compset -P "${__borg_config_sect}." || alts+=( 'sections:section:compadd -S "." $__borg_config_sect' )
  1336. _alternative $alts
  1337. }
  1338. (( $+functions[__borg_unset_config] )) ||
  1339. __borg_unset_config() {
  1340. unset __borg_config_sect __borg_config_keys
  1341. }
  1342. # A simple prefix-oriented completion function for compressors. Can be improved by supporting the suffix.
  1343. (( $+functions[_borg_compression] )) ||
  1344. _borg_compression() {
  1345. local -a nolvl=(
  1346. 'none:do not compress'
  1347. 'lz4:very high speed, very low compression'
  1348. )
  1349. local -a havelvl=(
  1350. 'zstd:("zstandart")'
  1351. 'zlib:("gz") medium speed, medium compression'
  1352. 'lzma:("xz") low speed, high compression'
  1353. )
  1354. local -a auto=(
  1355. 'auto:compress compressible, otherwise "none"'
  1356. )
  1357. local -a match mbegin mend
  1358. # NOTE: Zsh's `-prefix` condition is confused by the leading parenthesis in the pattern.
  1359. # Fortunately, we simply need to show a message.
  1360. if compset -P '(#b)(|auto,)(zstd|zlib|lzma),'; then
  1361. local -i from to def
  1362. case $match[2] in
  1363. (zstd) from=1 to=22 def=3 ;;
  1364. (zlib|lzma) from=0 to=9 def=6 ;;
  1365. esac
  1366. _message -e "compression level (from $from to $to, default: $def)"
  1367. elif compset -P 'auto,'; then
  1368. _describe -t compression 'compression' nolvl -- havelvl -qS,
  1369. else
  1370. _describe -t compression 'compression' nolvl -- havelvl -qS, -- auto -S,
  1371. fi
  1372. }
  1373. (( $+functions[_borg_chunker_params] )) ||
  1374. _borg_chunker_params() {
  1375. if compset -P 'buzhash,'; then
  1376. if compset -P '*,*,*,'; then
  1377. _message -e 'HASH_WINDOW_SIZE'
  1378. elif compset -P '*,*,'; then
  1379. _message -e 'HASH_MASK_BITS (statistical medium chunk size ~= 2^HASH_MASK_BITS B)'
  1380. elif compset -P '*,'; then
  1381. _message -e 'CHUNK_MAX_EXP (maximum chunk size = 2^CHUNK_MAX_EXP B)'
  1382. else
  1383. _message -e 'CHUNK_MIN_EXP (minimum chunk size = 2^CHUNK_MIN_EXP B)'
  1384. fi
  1385. elif compset -P 'fixed,'; then
  1386. if compset -P '*,'; then
  1387. _message -e 'HEADER_SIZE (B)'
  1388. else
  1389. _message -e 'BLOCK_SIZE (B)'
  1390. fi
  1391. else
  1392. local -a algorithms=(
  1393. 'fixed:a simple, low cpu overhead, fixed blocksize chunker, optionally supporting a header block of different size'
  1394. 'buzhash:variable, content-defined blocksize, uses a rolling hash computed by the Buzhash algorithm'
  1395. )
  1396. _describe -t algorithm 'ALGO' algorithms -S ,
  1397. fi
  1398. }
  1399. (( $+functions[_borg_chunker_params_examples] )) ||
  1400. _borg_chunker_params_examples() {
  1401. local -a params=(
  1402. 'default:buzhash,19,23,21,4095'
  1403. 'buzhash,19,23,21,4095:small amount of chunks (default)'
  1404. 'buzhash,10,23,16,4095:big amount of chunks'
  1405. )
  1406. params=( ${(q)params} )
  1407. _alternative \
  1408. 'chunker-params: :_borg_chunker_params' \
  1409. "chunker-params-examples:chunker params examples:(($params))"
  1410. }
  1411. (( $+functions[_borg_statuschars] )) ||
  1412. _borg_statuschars() {
  1413. _values -s '' 'STATUSCHARS' \
  1414. 'A[regular file, added]' \
  1415. 'M[regular file, modified]' \
  1416. 'U[regular file, unchanged]' \
  1417. 'C[regular file, it changed while we backed it up]' \
  1418. 'E[regular file, an error happened while accessing/reading this file]' \
  1419. 'd[directory]' \
  1420. 'b[block device]' \
  1421. 'c[char device]' \
  1422. 'h[regular file, hardlink (to already seen inodes)]' \
  1423. 's[symlink]' \
  1424. 'f[fifo]' \
  1425. 'i[backup data was read from standard input (stdin)]' \
  1426. '-[dry run, item was not backed up]' \
  1427. 'x[excluded, item was not backed up]' \
  1428. '?[missing status code]'
  1429. }
  1430. (( $+functions[_borg_quota_suffixes] )) ||
  1431. _borg_quota_suffixes() {
  1432. if compset -P '[0-9]##'; then
  1433. local -a suffixes=(
  1434. 'K:10 ** 3 bytes'
  1435. 'M:10 ** 6 bytes'
  1436. 'G:10 ** 9 bytes'
  1437. 'T:10 ** 12 bytes'
  1438. 'P:10 ** 15 bytes'
  1439. )
  1440. # NOTE: tag `suffixes` is already in use (file extensions)
  1441. _describe -t multiplier 'suffix' suffixes
  1442. else
  1443. _message -e 'QUOTA'
  1444. fi
  1445. }
  1446. (( $+functions[_borg_timestamp] )) ||
  1447. _borg_timestamp() {
  1448. _alternative \
  1449. "dates:TIMESTAMP: _dates -f '%FT%T'" \
  1450. 'files:reference:_files'
  1451. }
  1452. (( $+functions[_borg_guard_unsigned_number] )) ||
  1453. _borg_guard_unsigned_number() {
  1454. local -A opts
  1455. zparseopts -K -D -A opts M+: J+: V+: 1 2 o+: n F: x+: X+:
  1456. _guard '[0-9]#' ${1:-number}
  1457. }
  1458. _borg() {
  1459. local -a match mbegin mend line state
  1460. local curcontext="$curcontext" state_descr
  1461. typeset -A opt_args
  1462. local -i ret=1
  1463. if [[ $service == 'borg' ]]; then
  1464. local __borg_command=$words[1]
  1465. local -a common_options
  1466. __borg_setup_common_options
  1467. _arguments -s -w -C : \
  1468. '(- :)'{-V,--version}'[show version number and exit]' \
  1469. $common_options \
  1470. '(-): :->command' \
  1471. '(-)*:: :->option-or-argument' && return
  1472. case $state in
  1473. (command)
  1474. _borg_commands && ret=0
  1475. ;;
  1476. (option-or-argument)
  1477. curcontext="${curcontext%:*:*}:borg-$words[1]:"
  1478. if ! _call_function ret _borg-$words[1]; then
  1479. _default && ret=0
  1480. fi
  1481. ;;
  1482. esac
  1483. elif [[ $service == (#b)-value-,BORG_(*),-default- ]]; then
  1484. _borg_parameters $match[1] && ret=0
  1485. elif ! _call_function ret _$service; then
  1486. _default && ret=0
  1487. fi
  1488. return ret
  1489. }
  1490. _borg "$@"