Re: [PATCH 03/10] bash-completion: fdisks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 27, 2013 at 10:07:45PM +0000, Sami Kerola wrote:
> +++ b/shell-completion/fdisk
> @@ -0,0 +1,41 @@
> +_fdisk_module()
> +{
> +	local cur prev OPTS
> +	COMPREPLY=()
> +	cur="${COMP_WORDS[COMP_CWORD]}"
> +	prev="${COMP_WORDS[COMP_CWORD-1]}"
> +	case $prev in
> +		'-s')
> +			local PARTITIONS
> +			PARTITIONS="$(for I in /sys/block/*/*/partition; do IFS='/'; DIR_ARR=($I); echo "/dev/${DIR_ARR[4]}"; done)"
> +			COMPREPLY=( $(compgen -W "$PARTITIONS" -- $cur) )
> +			return 0
> +			;;
> +		'-b')
> +			COMPREPLY=( $(compgen -W "512 1024 2048 4096" -- $cur) )
> +			return 0
> +			;;
> +		'-c')
> +			COMPREPLY=( $(compgen -W "dos nondos" -- $cur) )

 optional arguments, it means the result has to be "-c=dos" or
 "-c=nondos" and no blank spaces.

 I guess you need to use -o nospace for compgen or so.

> +			return 0
> +			;;
> +		'-u')
> +			COMPREPLY=( $(compgen -W "cylinders sectors" -- $cur) )
> +			return 0

 the same situation, -u=

> +			;;
> +		'-C'|'-H'|'-S')
> +			COMPREPLY=( $(compgen -W "number" -- $cur) )
> +			return 0
> +			;;
> +	esac
> +	case $cur in
> +		-*)
> +			OPTS="-l -s -b -c -h -u -v -C -H -S"
> +			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
> +			return 0
> +			;;
> +	esac
> +	COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')" -- $cur) )
> +	return 0
> +}

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux