Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: new btrfs completion



This adds a completion function for the btrfs command. I've also updated
_mount with btrfs and ext4 mount options and newer Linux mount flags.

Oliver

Index: Completion/Linux/Command/_btrfs
===================================================================
RCS file: Completion/Linux/Command/_btrfs
diff -N Completion/Linux/Command/_btrfs
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Linux/Command/_btrfs	20 Nov 2012 22:50:40 -0000
@@ -0,0 +1,144 @@
+#compdef btrfs
+
+local curcontext="$curcontext" curstate state line expl grp cmd ret=1
+local -a groups args
+
+groups=( subvolume filesystem device scrub balance inspect-internal help version )
+cmds_1=( create delete list snapshot get-default set-default find-new help )
+cmds_2=( df show sync defragment resize label balance help )
+cmds_3=( add delete scan help )
+cmds_4=( start cancel resume status help )
+cmds_5=( start pause cancel resume status )
+cmds_6=( inode-resolve logical-resolve help )
+
+[[ $words[2] = h(|e(|l(|p))) ]] && args=( '--full[display detailed help]' )
+
+_arguments -C "$args[@]" \
+  '(- *)--help[print help information]' \
+  '(- *)--version[print version information]' \
+  '(--version)1: :->groups' \
+  '2: :->cmds' \
+  '*:: :->args' && ret=0
+
+while (( $#state )); do
+  curstate=$state
+  shift state
+  case $curstate in
+    groups)
+      _wanted command-groups expl 'btrfs command group' compadd -a groups && ret=0
+    ;;
+    cmds)
+      : $words
+      local grp=${groups[(i)$words[2]*]}
+      : $grp
+      (( grp && grp < 7 )) || return 1
+      curcontext="${curcontext%:*:*}:$service-${groups[grp]}:"
+      _wanted commands expl command compadd -a cmds_$grp && ret=0
+    ;;
+    args)
+      : $words
+      local grp=${groups[(i)$words[1]*]}
+      (( grp && grp < 7 )) || return 1
+      local group=cmds_$grp
+      local cmd=${${(P)group}[(i)$words[2]*]}
+      (( cmd )) || return 1
+      curcontext="${curcontext%:*:*}:$service-${groups[grp]}-${${(P)group}[cmd]}:"
+      args=( '(-)--help[print help information]' )
+      case ${groups[grp]}:${${(P)group}[cmd]} in
+	filesystem:balance)
+	  if (( CURRENT == 3 )); then
+	    state+=cmds
+	  else
+	    shift words
+	    (( CURRENT-- ))
+	    state+=args
+	  fi
+	  continue
+	;;
+	subvolume:create) args+=( '1:destination:->mounts' );;
+	subvolume:delete) args+=( '1:subvolume:_files -/' );;
+	subvolume:snapshot) args+=( '-r[readonly snapshot]' '1:snapshot:_files -/' );;
+	subvolume:list) args+=( '-p[include parent ID in output]' '1:path:->mounts' );;
+	subvolume:set-default) args+=( '1:id:_guard "[0-9]#" id' '2:path:->mounts' );;
+	filesystem:resize) args+=( '1:size:_guart "(|+|-)[0-9]#[GKM]"' '2:path:->mounts' );;
+	filesystem:defragment)
+	  args+=(
+	    '-v[verbose]'
+	    '-c[compress files while defragmenting]'
+	    '-f[flush after defragmenting]'
+	    '-s[start position]:byte position'
+	    '-l[defragment limited number of bytes]:length (bytes)'
+	    '-t[defragment only files over a certain size]:minimum size (bytes)'
+	    '*:file:_files'
+	  )
+	;;
+	filesystem:label) args+=( '1:device:_files -g "*(d)"' '2:label' );;
+	filesystem:show) args+=( '(1 -)--all-devices[scan all devices in /dev]' '1: :_guard "^-*" uuid or label' );;
+	device:(add|delete)) args+=( '1:device:_files -g "*(d)"' '2:path:->mounts' );;
+	device:scan) args+=( '(1 -)--all-devices[scan all devices in /dev]' '1:device:_files -g "*(d)"' );;
+	scrub:(start|resume))
+	  args+=(
+	    "-B[don't background and print statistics at end]"
+	    '-d[print separate statistics for each device]'
+	    '-q[omit error message and statistics]'
+	    '-r[read only mode]'
+	    '-u[scrub unused space too]'
+	    '1:path or device:_files'
+	  )
+	;;
+	scrub:cancel) args+=( '1:path or device' );;
+	scrub:status) args+=( '-d[separate statistics for each device]' '1:path or device:_files' );;
+	balance:start)
+	  args+=(
+	    '(-m -s)-d+[act on data chunks]:filter:->filters'
+	    '(-d -s)-m+[act on metadata chunks]:filter:->filters'
+	    '(-d -m)-s+[act on system chunks (only under -f)]:filters:->filters'
+	    '-v[verbose mode]'
+	    '-f[force reducing of metadata integrity]'
+	    '1:path:_files -/'
+	  )
+	;;
+	balance:status) args+=( '-v[verbose mode]' '2:path:_files -/' );;
+	balance:(pause|cancel|resume)) args+=( '2:path:_files -/' );;
+	inspect*:inode*) args+=( '-v[verbose mode]' '1:inode:_files' '2:path:_files -/' );;
+	inspect*:logical*)
+	  args+=(
+	    '-v[verbose mode]'
+	    '-P[skip the path resolving and print the inodes instead]'
+	    '1:logical address:_files'
+	    '2:filesystem path:_files -/'
+	  )
+	;;
+	subvolume:get-default) ;&
+	*:sync) ;&
+	*:df) args+=( '1:path:->mounts' );;
+	*) args+=( '*: :_default' );; # fallback for unknown subcommands
+      esac
+      shift words
+      (( CURRENT-- ))
+      _arguments -C "$args[@]" && ret=0
+    ;;
+    mounts)
+      _wanted mount-points expl 'mount point' compadd \
+	  ${${${(M)${(f)"$(</etc/mtab)"}:#*btrfs*}#* }%% *} && ret=0
+    ;;
+    filters)
+      state=()
+      _values -s , filter \
+	'profiles[balance only block groups in given replication profiles]:profile:->profiles' \
+	'usage[balance block groups with usage below percentage]:percentage' \
+	'devid[limit by device ID]:device ID' \
+	'drange[balance block groups overlapping byte range]:range' \
+	'vrange[balance block groups overlapping byte range in virtual address space]:range' \
+	'convert[convert block groups to given profile]:profile:->profiles' \
+	'soft[leave chunks that already have target profile]' && ret=0
+      state=( $state )
+    ;;
+    profiles)
+      compset -P '*\|'
+      _values -s ',' profile raid0 raid1 raid10 dup single && ret=0
+    ;;
+  esac
+done
+
+return ret
Index: Completion/Unix/Command/_mount
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_mount,v
retrieving revision 1.32
diff -u -r1.32 _mount
--- Completion/Unix/Command/_mount	22 May 2012 08:58:41 -0000	1.32
+++ Completion/Unix/Command/_mount	20 Nov 2012 22:50:40 -0000
@@ -45,7 +45,7 @@
 _fs_hsfs _fs_advfs _fs_cdfs _fs_affs _fs_ext2 _fs_fat _fs_ext3 _fs_msdos \
 _fs_msdosfs _fs_umsdos _fs_vfat _fs_hpfs _fs_ntfs _fs_reiserfs _fs_smbfs \
 _fs_xfs _fs_std _fs_devfs _fs_fdesc _fs_kernfs _fs_linprocfs _fs_linsysfs \
-_fs_procfs
+_fs_procfs _fs_btrfs _fs_ext4
 
 typeset -A opt_args
 
@@ -306,10 +306,15 @@
     _fs_any=(
       '(sync)async[do all I/O asynchronously]'
       '(noatime)atime[update access time]'
-      '(norelatime)relatime[update atime relative to mtime/ctime]' 
+      '(norelatime)relatime[update atime relative to mtime/ctime]'
+      '(nostrictatime)strictatime[full atime updates]'
+      '(strictatime)nostrictatime[default atime update behaviour]'
       '(rw suid dev exec async)defaults[use default options]'
       '(nodev)dev[interpret devices]'
+      '(nodiratime)diratime[update directory access time]'
+      "(diratime)nodiratime[don't update directory access time]"
       '(noexec)exec[permit execution of binaries]'
+      "noiversion[don't increment i_version inode field]"
       '(nomand)mand[allow mandatory locks]'
       "(atime)noatime[don't update access time]"
       "(relatime)norelatime[update access time without regard to mtime/ctime]"
@@ -327,6 +332,10 @@
       'encryption[enable encryption]:cypher'
       'keybits[set number of bits in encryption key]:key size:(64 128 160 192 256)'
       'offset[specify data start for loopback mount]:offset (bytes)'
+      '(loud)silent' '(silent)loud'
+      '(fscontext defcontext)context:context'
+      '(context)'{fscontext,defcontext}':context'
+      'rootcontext:context'
     )
     _fs_adfs=(
       'uid[set owner of root]:user ID'
@@ -383,6 +392,7 @@
       'umask[specify umask]:umask value (octal)'
       'dmask[specify umask for directories only]:umask value (octal)'
       'fmask[specify umask for files only]:umask value (octal)'
+      'allow_utime[control permission check of mtime/atime]:value'
       'check[specify checking level]:checking level:((relaxed\:accept\ upper\ and\ lower\ case,\ truncate\ long\ name normal\:like\ '"'\`'"'relaxed'"\\'"',\ but\ reject\ special\ characters strict\:like\ '"'\`'"'normal'"\\'"',\ but\ no\ long\ parts))'
       'codepage[specify codepage for converting filenames to short form]:codepage'
       'conf[specify CR/NL conversion]:CR/NL conversion mode:((binary\:no\ translation text\:conversion\ on\ all\ files auto\:perform\ translation\ on\ file\ without\ binary\ extension))'
@@ -392,15 +402,26 @@
       'debug[debug mode]'
       'fat[specify fat type]:fat type (bit):(12 16 32)'
       'iocharset[character set to use for converting from 8 bit to unicode]:character set'
+      'tz[set timezone conversion]:zone:(UTC)'
       'quiet[quiet mode]'
     )
     _fs_ext3=(
       "$_fs_ext2[@]"
       'journal[update fs journal]:update or inode number:(update)'
+      'journal_dev[specify new journal location]:device number'
       'noload[do not load journal]'
       'data[specify mode for data]:journalling mode:(journal ordered writeback)'
+      'barrier[enable/disable barriers]:state:((0\:disabled 1\:enabled))'
       'commit[specify commit sync interval for data and metadata]:seconds'
     )
+    _fs_ext4=(
+      "$_fs_ext3[@]"
+      journal_checksum journal_sync_commit
+      inode_readahead:blocks stripe:blocks delalloc nodelalloc
+      {max,min}'_batch_time:time (usecs)' journal_ioprio:priority
+      abort {,no}auto_da_alloc {,no}discard nouid32 resize
+      {,no}block_validity dioread_{,no}lock i_version
+    )
     _fs_msdos=( "$_fs_fat[@]" )
     _fs_umsdos=( "$_fs_fat[@]" )
     _fs_vfat=( "$_fs_fat[@]"
@@ -527,6 +548,27 @@
       'sunit[specify stripe unit]:size'
       'swidth[specify stripe width]:size'
     )
+    _fs_btrfs=(
+      'subvol[mount a subvolume]:path'
+      'subvolid[mount subvolume by id]:id'
+      'device[scan device for filesystems]:device'
+      'nodatasum[disable checksums of new files]'
+      'nobarrier[disable use of device barriers]'
+      'max_inline[set maximum space for inline data]:size (bytes)'
+      'alloc_start[set where on disk allocations start]:number'
+      'thread_pool[number of worker threads to allocate]:number'
+      '(compress-force)compress[enable compression]:algorithm:(zlib lzo no)'
+      '(compress)compress-force[enable compression for all files]:algorithm:(zlib lzo no)'
+      'ssd[optimise behaviour for SSDs]'
+      'ssd_spread[be strict about finding a large unused region for new allocations]'
+      'discard[enable discard/TRIM on freed blocks]'
+      'notreelog[disable the tree logging used for fsync]'
+      metadata_ratio:number {,no}space_cache clear_cache
+      user_subvol_rm_allowed autodefrag inode_cache
+      enospc_debug recovery check_int check_int_data
+      check_int_print_mask:number skip_balance
+      'fatal_errors:action:(bug panic)'
+    )
     ;;
   freebsd*|dragonfly*)
     _fs_any=(
@@ -628,28 +670,31 @@
     deffs=efs
     ;;
   linux*)
+    local excl='-V --version -h --help'
     args=( -s
-      '(- :)-h[show help]'
-      '(- :)-V[show version]'
-      '(-V -h)-v[verbose mode]'
-      '(-V -h)-p[specify file descriptor from which to read passphrase]:file descriptor:_file_descriptors'
-      '(-V -h -o :)-a[mount all filesystems in fstab]'
-      '(-V -h)-F[fork off one child per device]'
-      '(-V -h)-f[fake mount]'
-      "(-V -h)-i[don't call /sbin/mount.<fs> helper]"
-      '(-V -h)-l[output ext2, ext3 and XFS labels]'
-      "(-V -h)-n[don't write /etc/mtab]"
-      '(-V -h)-s[tolerate sloppy mount options]'
-      '(-V -h -w)-r[mount read-only]'
-      '(-V -h -r)-w[mount read/write]'
-      '(-V -h)-L[mount partition with specified label]:label'
-      '(-V -h)-U[mount partition with specified uuid]:uuid'
-      '(-V -h)-t[specify file system type]:file system type:->fslist'
-      '(-V -h)-O[with -a, restrict filesystems by options]:file system option:->fsopt'
-      '(-V -h -a -O)-o[specify file system options]:file system option:->fsopt'
-      '(: -)--bind[remount part of filesystem elsewhere]:old directory:_directories:new directory:_directories'
-      '(: -)--rbind[remount part of filesystem including submounts elsewhere]:old directory:_directories:new directory:_directories'
-      '(: -)--move[move part of filesystem elsewhere]:old directory:_directories:new directory:_directories'
+      '(- :)'{-h,--help}'[show help]'
+      '(- :)'{-V,--version}'[show version]'
+      "($excl -v --verbose)"{-v,--verbose}'[verbose mode]'
+      "($excl -p --pass-fd)"{-p+,--pass-fd=}'[specify file descriptor from which to read passphrase]:file descriptor:_file_descriptors'
+      "($excl -o : -a --all)"{-a,--all}'[mount all filesystems in fstab]'
+      "($excl -F --fork)"{-F,--fork}'[fork off one child per device]'
+      "($excl -f --fake)"{-f,--fake}'[fake mount]'
+      "($excl -i --internal-only)"{-i,--internal-only}"[don't call /sbin/mount.<fs> helper]"
+      "($excl)-l[output ext2, ext3, ext4 and XFS labels]"
+      "($excl -n --no-mtab)"{-n,--no-mtab}"[don't write /etc/mtab]"
+      "($excl)--no-canonicalize[don't convert paths to canonical form]"
+      "($excl)-s[tolerate sloppy mount options]"
+      "($excl -w -r --read-only)"{-r,--read-only}'[mount read-only]'
+      "($excl -r -w --rw)"{-w,--rw}'[mount read/write]'
+      "($excl)-L+[mount partition with specified label]:label:->labels"
+      "($excl)-U+[mount partition with specified uuid]:uuid"
+      "($excl -t --types)"{-t+,--types=}'[specify file system type]:file system type:->fslist'
+      "($excl -O --test-opts)"{-O+,--test-opts=}'[with -a, restrict filesystems by options]:file system option:->fsopt'
+      "($excl -a -O -o --options)"{-o+,--options=}'[specify file system options]:file system option:->fsopt'
+      '(: -)'{-B,--bind}'[remount part of filesystem elsewhere]:old directory:_directories:new directory:_directories'
+      '(: -)'{-R,--rbind}'[remount part of filesystem including submounts elsewhere]:old directory:_directories:new directory:_directories'
+      '(: -)'{-M,--move}'[move part of filesystem elsewhere]:old directory:_directories:new directory:_directories'
+      '(: -)--make-'{r,}{shared,slave,private,unbindable}':mount point:->udevordir'
       ':dev or dir:->devordir'
       ':mount point:_files -/'
     )
@@ -749,19 +794,20 @@
       )
     ;;  
     linux*)
+      local excl='-V --version -h --help'
       args=(
-	'(- *)-h[show help]'
-	'(- *)-V[show version]'
-	'(-V -h)-v[verbose mode]'
-	"(-V -h)-n[don't write /etc/mtab]"
-	'(-V -h)-r[remount read-only on failure]'
-	'(-V -h)-d[for loopback mount, free loop device]'
-        "(-V -h)-i[don't call /sbin/umount.<fs> helper]"
-	'(-V -h *)-a[unmount all file systems from /etc/mtab]'
-	'(-V -h)-t[specify file system type]:file system type:_file_systems'
-	'(-V -h *)-O[with -a, restrict filesystems by options]:file system option:->fsopt'
-	'(-V -h)-f[force unmount]'
-	'(-V -h)-l[lazy unmount]'
+	'(- *)'{-h,--help}'[show help]'
+	'(- *)'{-V,--version}'[show version]'
+	"($excl -v --verbose)"{-v,--verbose}'[verbose mode]'
+	"($excl -n --no-mtab)"{-n,--no-mtab}"[don't write /etc/mtab]"
+	"($excl)-r[remount read-only on failure]"
+	"($excl)-d[for loopback mount, free loop device]"
+	"($excl)-i[don't call /sbin/umount.<fs> helper]"
+	"($excl *)-a[unmount all file systems from /etc/mtab]"
+	"($excl)-t[specify file system type]:file system type:_file_systems"
+	"($excl *)-O[with -a, restrict filesystems by options]:file system option:->fsopt"
+	"($excl)-f[force unmount]"
+	"($excl)-l[lazy unmount]"
 	'*:dev or dir:->udevordir'
       )
     ;;
@@ -945,6 +991,9 @@
     'device-paths: device path:_canonical_paths -A dpath_tmp -N device-paths device\ path' \
     'directories:mount point:_canonical_paths -A mp_tmp -N directories mount\ point' && ret=0
   ;;
+labels)
+  _wanted labels expl 'disk label' compadd /dev/disk/by-label/*(:t) && ret=0
+  ;;
 esac
 
 return ret



Messages sorted by: Reverse Date, Date, Thread, Author