Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 490882 - app-admin/eselect-1.3.8: parsing the output of eselect is hard since it wraps at 80 chars
Summary: app-admin/eselect-1.3.8: parsing the output of eselect is hard since it wraps...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: eselect (show other bugs)
Hardware: All Linux
: Normal enhancement
Assignee: Gentoo eselect Team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2013-11-09 21:53 UTC by Jelte Fennema
Modified: 2013-12-07 13:33 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Possible fix: Wrapping does not occur when stdout is not a tty (output.bash,6.29 KB, text/plain)
2013-11-09 22:06 UTC, Jelte Fennema
Details
Screenshot of what tab completion looks like in Fish (fishcomp_screenshat.png,108.49 KB, image/png)
2013-11-10 11:09 UTC, Jelte Fennema
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jelte Fennema 2013-11-09 21:53:28 UTC
I am trying to write completions for eselect for the fish shell. It would be very usefull to be able to parse it like this:
'  module\t info\n'
Right now that is not possible.

I'm not sure what severity to put this in since I see two possible solutions.
- Disable wrapping when stdout isn't a tty. In that case it's trivial. 
- A new feature could be added, like a flag to disable automatic wrapping.

Reproducible: Always

Steps to Reproduce:
1. have mesa intalled
2. run: eselect modules list | grep '^  '
Actual Results:  
there will be these two lines in the output
  mesa                      Manage the OpenGL driver architecture used by
                            media-libs/mesa



Expected Results:  
A line with this should be the output:
  mesa                      Manage the OpenGL driver architecture used by media-libs/mesa
Comment 1 Jelte Fennema 2013-11-09 22:06:39 UTC
Created attachment 362924 [details]
Possible fix: Wrapping does not occur when stdout is not a tty

Line 130 has been changed from:
	if [[ $(( ${n} + ${#text} )) -ge ${cols} ]] ; then
to:
	if [[ -t 1 ]] && [[ $(( ${n} + ${#text} )) -ge ${cols} ]] ; then
Comment 2 Jelte Fennema 2013-11-10 00:55:02 UTC
On another note, right now my completion scripts for fish are in this repository: https://github.com/JelteF/fish_completions

Is there a way I might be able to provide them in the same manner to other users as the completion scripts for bash and zsh?
Comment 3 Ulrich Müller gentoo-dev 2013-11-10 06:17:36 UTC
Output of "eselect help" or "eselect modules list" is designed to be human readable. That it wraps lines is not a bug, but a feature.

If you want machine readable output, you should use "eselect --brief modules list" (which is also much faster).


(In reply to Jelte Fennema from comment #1)
> Created attachment 362924 [details] [details, diff]
> Possible fix: Wrapping does not occur when stdout is not a tty

No, this would break "eselect help | less" which is not acceptable.

However, adding an option (globally, or locally to the "eselect modules list" action) might be feasible. But can you please explain what is your exact usage case?


(In reply to Jelte Fennema from comment #2)
> Is there a way I might be able to provide them in the same manner to other
> users as the completion scripts for bash and zsh?

Sure, write an ebuild for it. But please file a separate bug for this.
Comment 4 Jelte Fennema 2013-11-10 11:05:15 UTC
(In reply to Ulrich Müller from comment #3)

> If you want machine readable output, you should use "eselect --brief modules 
> list" (which is also much faster).

This will not work, since it also removes the information that I want to parse in some cases. And even if that was not the case it also wraps when the output is piped.

> No, this would break "eselect help | less" which is not acceptable.

That's indeed a use case I wouldn't want to break.

> However, adding an option (globally, or locally to the "eselect modules
> list" action) might be feasible. But can you please explain what is your
> exact usage case?

One of the advantages of the fish shell over bash is that you can add descriptions to the shown completions (if there is more than one possibility of completing). I would like to use the description displayed by the help and list options of the modules as descriptions. (I will upload an attachment to show what I mean)


> Sure, write an ebuild for it. But please file a separate bug for this.
Ok, I will when I have a working one.
Comment 5 Jelte Fennema 2013-11-10 11:09:57 UTC
Created attachment 362972 [details]
Screenshot of what tab completion looks like in Fish

The first block is pressing tab after you've typed cp --. As you can see it will show the possible flags with their explanation.
After that you will see what some of the different levels of completion for eselect look like when the help and list options get parsed.
Comment 6 Ulrich Müller gentoo-dev 2013-11-10 18:53:27 UTC
I have to think about what is the least invasive solution for this.
Comment 7 Jelte Fennema 2013-11-14 02:06:21 UTC
It seems to me like an extra option is the only way to implement this as to keep the current less functionality and the parsing functionality.

This doesn't seem so hard as well.

When I have the chance again I will try to create that.
Comment 8 Ulrich Müller gentoo-dev 2013-11-14 23:42:35 UTC
I've created a branch "nolinewrap" in eselect's git repository:
http://git.overlays.gentoo.org/gitweb/?p=proj/eselect.git;a=shortlog;h=refs/heads/nolinewrap

It contains the following changes (see ChangeLog or git log for details):
- "eselect modules list --only-names" will output the names of modules
  without description. This is the same output that was produced by
  "eselect --brief modules list" before.
- The --brief option now suppresses line wrapping in key/value lists.
  Especially, "eselect --brief modules list" will output a list of modules
  with description, but without any line wrapping.

Please test if this suits your needs.
Comment 9 Ulrich Müller gentoo-dev 2013-11-19 08:19:13 UTC
(In reply to Ulrich Müller from comment #8)
> I've created a branch "nolinewrap" in eselect's git repository:

This has been merged into master now.
Comment 10 Jelte Fennema 2013-11-19 10:45:19 UTC
I've just tried it and it works great.
The only problem is that I also try to parse help output and because of line 98 in default.bash that doesn't work:
set_output_mode default

If I remove it everything is fine. Why does it exist, since I can't imagine a reason for changing the output mode to the default for help output?
Comment 11 Ulrich Müller gentoo-dev 2013-11-19 12:57:43 UTC
(In reply to Jelte Fennema from comment #10)
> The only problem is that I also try to parse help output and because of
> line 98 in default.bash that doesn't work:
> set_output_mode default

Right, I removed it from es_do_help() and earlier from do_usage(), but looks like I've missed the instance in do_help().

Gone now: http://git.overlays.gentoo.org/gitweb/?p=proj/eselect.git;a=commit;h=8a49c1aac6f1f1824059513360f2abc8aece1cd3
Comment 12 Jelte Fennema 2013-11-20 08:25:38 UTC
The parsing works great now. Thanks for adding this feature. I have added my completions as a pull request to fish-shell, so others will be able to use them as well. https://github.com/fish-shell/fish-shell/pull/1131
Comment 13 Ulrich Müller gentoo-dev 2013-11-20 08:48:42 UTC
Please leave this bug open. I'll close it after the next release.
Comment 14 Ulrich Müller gentoo-dev 2013-12-07 13:33:20 UTC
Fixed in eselect-1.4.