_borg 56 KB

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