Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alter history sub-command handling #3386

Closed
wants to merge 5 commits into from
Closed

alter history sub-command handling #3386

wants to merge 5 commits into from

Conversation

krader1961
Copy link
Contributor

This deprecates the use of long options for history sub-commands (e.g.,
history --delete) in favor of proper sub-commands (e.g., history delete). It also eliminates the short options for those sub-commands.

Also change option processing to allow options anywhere on the command
line to match how the vast majority of fish builtins handle flags.

Fixes #3367

This deprecates the use of long options for history sub-commands (e.g.,
`history --delete`) in favor of proper sub-commands (e.g., `history
delete`). It also eliminates the short options for those sub-commands.

Also change option processing to allow options anywhere on the command
line to match how the vast majority of fish builtins handle flags.

Fixes #3367
@krader1961
Copy link
Contributor Author

@faho, Please review the completion changes. I personally think file name completions should be disabled for history but couldn't figure out how to do so. Similarly it would be nice if flag completion was only enabled for the search and delete subcommands once they are seen.

@floam
Copy link
Member

floam commented Sep 18, 2016

@krader1961 thanks for doing this!

Wiping the current completions out and then using -x (required argument, and no files) seemed to work for me:

complete -c history -x -a "merge clear save delete search"

thxx

Not sure if if -a is right.

I don't know how to build it up properly, or if it's worth suggesting looking at what string does. I'm sure @faho has some ideas.

@floam
Copy link
Member

floam commented Sep 18, 2016

string has it right, at least on UI, though IMO. And I would not offer completions for deprecated usages.

In fish when you hit a completion where nothing brings any columns, and there are no files, it's a treat to encounter; but surprisingly rare. I think autoloading muddies it up a little.

@floam floam added this to the fish 2.4.0 milestone Sep 18, 2016
@floam
Copy link
Member

floam commented Sep 18, 2016

@krader1961 If you're changing -t - I think it may be an opportunity to change the entire option name. I really do not like "with-" here -- particularly if we will be letting people give that an argument with date format strings in the future.

The problem is it looks like it's a predicate, and not a output option. (Like maybe history search --prefix=ls --with-time=5:31PM shows ls entires with a time of 5:31.)

If -t is gone - could that be --time or --show-times? I'd prefer dropping the long and keeping the short -t option, though.

# --save is not completed; it is for internal use
# We don't include a completion for the "save" subcommand because it should not be used
# interactively.
complete -c history -f -n '__fish_history_no_subcommand' -a search \
Copy link
Member

@faho faho Sep 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want __fish_seen_subcommand_from $__fish_history_all_commands here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (although it needs a not prefix for the logic to be correct). FWIW, I was simply following the pattern used by a couple of other command completions. It would be good for someone to take a few minutes and normalize all the completions to use this idiom.

not __fish_history_cmd_in_array $__fish_history_all_commands
end

complete -c history -l prefix -s p --description "Match items beginning with the string"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-n '__fish_seen_subcommand_from search delete'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, yes. That gives the effect I wanted but I didn't see how to do it despite having used -n below.

complete -c history -l clear --description "Clears history file"
complete -c history -l merge -s m --description "Incorporate history changes from other sessions"
complete -c history -l exact -s e --description "Match items in the history that are identicial"
set -g __fish_history_all_commands search delete save merge clear
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a global if you expand it directly - use double-quotes where you use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the scoping rules it will be global even without the -g. I vaguely recall a discussion about enhancing this so that there is a "file" scope analogous to python's module scope. The other option is to wrap all of this inside

function __fish_history_completions
...
end
__fish_history_completions
functions -e __fish_history_completions

That allows using set -l. The fix seems worse than simply making it a private global var.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, when you do set -l in the toplevel of a completion script, it doesn't leak. I'm not sure why it doesn't, though.

@krader1961
Copy link
Contributor Author

@floam, -t is still valid. I simply removed it from the list of flags in the "synopsis" section of the man page for clarity and to reduce the length of those lines. The descriptions of each long option also mentions the short option equivalent. If something other than that change to the man page caused you to think I was changing -t behavior please let me know what that is.

As for renaming --with-time I have no objection and now is the time to do so (obviously keeping but deprecating --with-time). I like --show-time (singular) so I'll add that.

@krader1961
Copy link
Contributor Author

Closed by squash merge of 76c73aa. I'd normally leave this PR open a few more days but I've got two more changes to the same blocks of code pending review for inclusion in the 2.4.0 release.

@krader1961 krader1961 closed this Sep 19, 2016
@floam
Copy link
Member

floam commented Sep 19, 2016

. If something other than that change to the man page caused you to think I was changing -t behavior please let me know what that is.

Nope, that was it.

@krader1961 krader1961 deleted the history-sub-commands branch September 19, 2016 04:37
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replace history --command with history command
3 participants