All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 07/10] bash-completion: sys-utils
Date: Mon, 1 Apr 2013 17:32:53 +0100	[thread overview]
Message-ID: <20130401163233.GA22182@gmail.com> (raw)
In-Reply-To: <20130329163335.GI24678@x2.net.home>

On Fri, Mar 29, 2013 at 05:33:35PM +0100, Karel Zak wrote:
> On Wed, Mar 27, 2013 at 10:07:49PM +0000, Sami Kerola wrote:
> > @@ -0,0 +1,25 @@
> > +_blkdiscard_module()
> > +{
> > +	local cur prev OPTS
> > +	COMPREPLY=()
> > +	cur="${COMP_WORDS[COMP_CWORD]}"
> > +	prev="${COMP_WORDS[COMP_CWORD-1]}"
> > +	case $prev in
> > +		'-o'|'--offset'|'-l'|'--length')
> > +			COMPREPLY=( $(compgen -W "num" -- $cur) )
> > +			return 0
> > +			;;
> > +	esac
> > +	case $cur in
> > +		-*)
> > +			OPTS="-o --offset -l --length -s --secure -v --verbose -h --help -V --version"
> > +			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
> > +			return 0
> > +			;;
> > +	esac
> > +	local DEVS
> > +	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
> 
> It does not look like the right way how to generate the paths, because
> /sys/class/block/ contains also paths to unassociated loop devices and
> all the paths are based on kernel device names (e.g. dm-X).
> 
> I have add --paths to lsblk(8), so now you can use:
> 
>  lsblk -p -o NAME -n -l
> 
> to list the paths, for exmaple:
>  
>  /dev/sda
>  /dev/sda1
>  /dev/sda2
>  /dev/sda3
>  /dev/sda4
>  /dev/sda5
>  /dev/sda6
>  /dev/mapper/luks-10d813de-fa82-4f67-a86c-23d5d0e7c30e
>  /dev/sdb
>  /dev/sr0
> 
> it would be nice to use this solution everywhere.

I think I found all references to block devices, and replaced them with
lsblk which is using Dave's while loop.

> > +_eject_module()
> > +{
>  ....
> > +	DEVS="$(for I in /sys/class/block/*/removable; do
> > +		if [ $(cat $I) -ne 0 ]; then
> > +			OLD_IFS=$IFS
> > +			IFS='/';
> > +			ARR=($I)
> > +			echo "/dev/${ARR[4]}"
> > +			IFS=$OLD_IFS
> > +		fi
> > +	done)"
> 
>  lsblk -rpn -o RM,NAME | awk '/^1/ { print $2 }'
> 
>  The common rule is to not read data from /sys if possible.
> 
> > diff --git a/shell-completion/fstrim b/shell-completion/fstrim
> > new file mode 100644
> > index 0000000..87cb050
> > --- /dev/null
> > +++ b/shell-completion/fstrim
> > @@ -0,0 +1,25 @@
> > +_fstrim_module()
> > +{
> > +	local cur prev OPTS
> > +	COMPREPLY=()
> > +	cur="${COMP_WORDS[COMP_CWORD]}"
> > +	prev="${COMP_WORDS[COMP_CWORD-1]}"
> > +	case $prev in
> > +		'-o'|'--offset'|'-l'|'--length'|'-m'|'--minimum')
> > +			COMPREPLY=( $(compgen -W "num" -- $cur) )
> > +			return 0
> > +			;;
> > +	esac
> > +	case $cur in
> > +		-*)
> > +			OPTS="-o --offset -l --length -m --minimum -v --verbose -h --help -V --version"
> > +			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
> > +			return 0
> > +			;;
> > +	esac
> > +	local MPOINTS
> > +	MPOINTS=$(awk '{if ($1 ~ /^\//){print $2}}' /etc/mtab 2>/dev/null)
> 
>  The same problem, don't read mtab directly (for example because
>  some chars could be escaped...). Use:
> 
>    findmnt -rno SOURCE | grep '/dev'

With this I had a small whoops.  The diff I sent moment ago did not have
findmnt v.s. /etc/mtab fixes, which are now in my git.

What comes to principle of using helper commands rather than /sys or
/proc files I fully agree this is better.

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/

  reply	other threads:[~2013-04-01 16:33 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-27 22:07 [PATCH 00/10] [pull] bash-completion Sami Kerola
2013-03-27 22:07 ` [PATCH 01/10] bash-completion: add bash completetion configure option Sami Kerola
2013-03-28 11:22   ` Sami Kerola
2013-03-29  9:42     ` Karel Zak
2013-03-27 22:07 ` [PATCH 02/10] bash-completion: disk-utils Sami Kerola
2013-03-28  1:42   ` Dave Reisner
2013-04-01 15:54     ` Sami Kerola
2013-03-28  9:54   ` Karel Zak
2013-04-01 17:00     ` Sami Kerola
2013-03-27 22:07 ` [PATCH 03/10] bash-completion: fdisks Sami Kerola
2013-03-28 10:01   ` Karel Zak
2013-03-27 22:07 ` [PATCH 04/10] bash-completion: login-utils Sami Kerola
2013-03-28  1:42   ` Dave Reisner
2013-04-01 16:05     ` Sami Kerola
2013-03-28 10:05   ` Karel Zak
2013-04-01 16:06     ` Sami Kerola
2013-03-27 22:07 ` [PATCH 05/10] bash-completion: misc-utils Sami Kerola
2013-03-28  1:42   ` Dave Reisner
2013-04-01 16:52     ` Sami Kerola
2013-03-27 22:07 ` [PATCH 06/10] bash-completion: schedutils Sami Kerola
2013-03-27 22:07 ` [PATCH 07/10] bash-completion: sys-utils Sami Kerola
2013-03-29 16:33   ` Karel Zak
2013-04-01 16:32     ` Sami Kerola [this message]
2013-04-05 14:44   ` Karel Zak
2013-03-27 22:07 ` [PATCH 08/10] bash-completion: term-utils Sami Kerola
2013-03-28 10:06   ` Karel Zak
2013-03-27 22:07 ` [PATCH 09/10] bash-completion: text-utils Sami Kerola
2013-03-27 22:07 ` [PATCH 10/10] bash-completion: add completion files to Makefile.am Sami Kerola
2013-03-28  1:42 ` [PATCH 00/10] [pull] bash-completion Dave Reisner
2013-03-28  9:37 ` Karel Zak
2013-03-31 23:49   ` Sami Kerola
2013-04-01 15:44   ` Sami Kerola
2013-04-05 14:11 ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130401163233.GA22182@gmail.com \
    --to=kerolasa@iki.fi \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.