jamesob / desk

A lightweight workspace manager for the shell
MIT License
2.54k stars 111 forks source link

Format list like a table #46

Closed cmbankester closed 8 years ago

cmbankester commented 8 years ago

I updated the cmd_list function to output the available desks as a table instead of hyphen-delimiting them. See, e.g.:

Before:

 desk git:(master) ✗ desk list
bid-manager - desk for working with the Bid Manager application
dotnet - desk for doing work on a .NET project
elm - Desk for working with Elm projects
fooooooooooooooooooooooooooooooooooooooo - A desk with an exceedingly long name
node.js - Desk for doing Node.js things
rails - desk for doing work on rails projects
timenator - desk for doing work on a .NET project

After:

 desk git:(master) ✗ ./desk list
NAME                                        DESCRIPTION
bid-manager                                 desk for working with the Bid Manager application
dotnet                                      desk for doing work on a .NET project
elm                                         Desk for working with Elm projects
fooooooooooooooooooooooooooooooooooooooo    A desk with an exceedingly long name
node.js                                     Desk for doing Node.js things
rails                                       desk for doing work on rails projects
timenator                                   desk for doing work on a .NET project

Currently no way to take the terminal width into consideration when listing, but I honestly don't see that being much of an issue these days.

I have also been considering attenuating the list command with an option for outputting only the names of the desks (for better integration into other systems, for instance). Thoughts?

cmbankester commented 8 years ago

Hmm, I'll have to find an alternative to the column command for the fish shell.

jamesob commented 8 years ago

@cmbankester also, make sure whatever you come up with is amenable to cut.

cmbankester commented 8 years ago

@jamesob Is the purpose of that for extracting name/description pairs?

jamesob commented 8 years ago

I'd like to keep desk's output as machine-friendly as possible while still remaining practical for human readability.

jamesob commented 8 years ago

I have also been considering attenuating the list command with an option for outputting only the names of the desks (for better integration into other systems, for instance). Thoughts?

:+1:

Probably best in a separate PR though.

jamesob commented 8 years ago

I'd like to hear what other users think about a display change of this sort (@ofsaleem @rnewton @jonashaag @unixorn @eush77 @mblarsen @paulmolluzzo)

jamesob commented 8 years ago

@cmbankester note that you'll also need to take the shell completion functions into consideration, e.g. https://github.com/jamesob/desk/blob/master/shell_plugins/bash/desk#L18

rnewton commented 8 years ago

I like it, but I'd prefer if the standard output was default and this was toggled via a flag.

cmbankester commented 8 years ago

@jamesob Really good point. I'll take a look at the completion functions that reference list. I'll also see about adding some tests to cover the completion functions (or at least the ones that I change).

@rnewton That's a good idea. Are you thinking with an ENV variable or with a command-line flag. Personally, I'd prefer the ENV var, but I can also understand if anyone would have reservations to that idea.

eush77 commented 8 years ago

I like this change, this looks much more readable to me and parseable, too (you split by \s{2,} instead of -).

jonashaag commented 8 years ago

I like it, but I'd prefer if the standard output was default and this was toggled via a flag.

It should be the other way round. First, humans will type desk ls many times, so it should very easy to type and have nice human-readable output. Secondly, if desk is integrated in another program, it doesn't hurt to add --machine-readable to that program's source code. So -- and this is a general rule for programs that are used by humans most of the time -- make human friendly by default and machine friendly by choice. See also Git's porcelain commands and the --porcelain flag. Example: git status is human-readable. git status --porcelain is machine-readable.

rnewton commented 8 years ago

@cmbankester I was thinking a flag + alias to your preferred output.

@jonashaag I can get behind that argument as well. I guess the biggest thing for me is the ability to toggle the type of output you get.

cmbankester commented 8 years ago

I went with @jonashaag's recommendation and set the default to be human readable. Let me know if I need to make any changes:

cbankester@Christians-iMac ~/P/c/desk> ./desk list
NAME    DESCRIPTION
desk    Desk for working on desk
dotnet  Desk for working on .NET projects

cbankester@Christians-iMac ~/P/c/desk> ./desk list --machine-readable
desk - Desk for working on desk
dotnet - Desk for working on .NET projects

cbankester@Christians-iMac ~/P/c/desk> ./desk list --only-names
desk
dotnet

cbankester@Christians-iMac ~/P/c/desk> ./desk list --only-descriptions
Desk for working on desk
Desk for working on .NET projects

I implemented the --only-names (/--only-descriptions) flag before doing the --machine-readable flag (to use with the completion code), so I figured I'd leave it in. Let me know if you want me to cherry pick it out.

paulmolluzzo commented 8 years ago

Pretty nice idea @cmbankester! Certainly easier to know what's going on. That said, I don't know that the window width won't ever be an issue. I made a ridiculously long file name and description just to illustrate the point. The screenshot is using the "default" window size for my terminal. Granted, I expand it to full width just about every single time I open the window, but not everyone does, and if you use tmux or screen and have small panes you will probably see a similar issue.

Other than that edge case I'd say this is great!

Long Names

jamesob commented 8 years ago

@cmbankester thanks for your continued work here, especially on keeping the tests current. A few things:

We'll want to think about applying this same sort of tabulation to cmd_current. My preference would be to include that change in this PR so that we maintain some consistency in the UI.

cmbankester commented 8 years ago

I'd recommend against using --no-tabulate simply because we're not actually using any tabs, just spaces. Perhaps --columnize?

jamesob commented 8 years ago

@cmbankester maybe just --no-format?

cmbankester commented 8 years ago

@jamesob I believe that make sense.

cmbankester commented 8 years ago

Alright, everything should be in order. Here's a sample of output from desk (without a subcommand):

cbankester@Christians-iMac ~/P/c/desk> ./desk
desk - Desk for working on desk

  foooooooooooooo  Alias to echo the word 'foo'
  bar              Alias to echo the word 'bar'

and with the --no-format option:

desk - Desk for working on desk

  foooooooooooooo - Alias to echo the word 'foo'
  bar - Alias to echo the word 'bar'

Also, my apologies for the strangely dense collection of git commits at the bottom of this PR. I rebased on your recent changes and force-pushed onto my master.

jamesob commented 8 years ago

@cmbankester cool; just a few minor things. After you've pushed the changes, I'll pull and test manually. Would greatly appreciate it if you could condense this down either into a single commit or three or four meaningful segments with git rebase -i origin/master; if you'd rather, I can do that.

cmbankester commented 8 years ago

@jamesob No problem, I'll squash after I make those changes.

jamesob commented 8 years ago

@cmbankester looks great, thanks for the good work. Do you have a bitcoin wallet QR where I might be able to send a bit of gratitude?

cmbankester commented 8 years ago

@jamesob Thanks so much, but the usage of desk is gratitude enough! Thanks again for open-sourcing this fine piece of software!

Feel free to @-ping me anytime you want some input on other PRs or have ideas you'd like me to implement.