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

Autocomplete for file names doesn't work (partially) [bash] #1923

Closed
belskikh opened this issue Apr 24, 2019 · 19 comments · Fixed by #3360 or #3374
Closed

Autocomplete for file names doesn't work (partially) [bash] #1923

belskikh opened this issue Apr 24, 2019 · 19 comments · Fixed by #3360 or #3374
Assignees
Labels
bug Did we break something? p2-medium Medium priority, should be done, but less important ui user interface / interaction

Comments

@belskikh
Copy link

Hello!
When I use autocompletion script from here https://github.com/iterative/dvc.org/blob/master/static/docs/user-guide/autocomplete.md it doesn't complete file and directory names from current directory for the command dvc repro ....
But if I add some flag, for example dvc repro --force ... then it works fine.
What should be changed in bash autocomplete script to allow autocompletion for dvc repro ... without any flags?

@efiop efiop transferred this issue from iterative/dvc.org Apr 24, 2019
@efiop
Copy link
Member

efiop commented Apr 24, 2019

Hi @belskikh !

Thanks for the feedback! I suppose you'd like to contribute a fix for it? @MrOutis should be able to help with it.

For the record: moved issue from dvc.org repo to dvc repo.

@belskikh
Copy link
Author

Hi, @efiop
Yes, I will fix it, if someone helps me

@ghost
Copy link

ghost commented Apr 24, 2019

@belskikh , are you using the latest version of the script?
It should be working (or at least it does for me), the line that deals with this is the following:

"*:Stages:_files -g '(*.dvc|Dvcfile)'"

@belskikh
Copy link
Author

belskikh commented Apr 25, 2019

@MrOutis I am using this version

#!/usr/bin/env bash

@ghost
Copy link

ghost commented Apr 25, 2019

check this out, @belskikh :

asciicast

@belskikh
Copy link
Author

@MrOutis that's awesome, and I will definetly try zsh , but for standard Ubuntu bash terminal it doesn't work.
Can you help me to understand, what I should add/change in dvc.bash script to fix it?

@ghost
Copy link

ghost commented Apr 25, 2019

ohh my bad, @belskikh ! 🙈

I don't have a good understanding of Bash's completion engine, but you'll need to add something like compgen -f -X '!*.dvc' over here

if [ "${COMP_CWORD}" -eq 1 ]; then
case "$word" in
-*) COMPREPLY=($(compgen -W "$_dvc_options" -- "$word")) ;;
*) COMPREPLY=($(compgen -W "$_dvc_commands" -- "$word")) ;;
esac
elif [ "${COMP_CWORD}" -eq 2 ]; then
local options_list="_dvc_${COMP_WORDS[1]}"

Be aware that some commands accepts something more than just stage files (the ones ending in .dvc).

The script itself have some references that you can look up to understand how the file was created, I'll leave you with one more: https://www.linuxjournal.com/content/more-using-bash-complete-command

By the way, installing Zsh is not that hard:

# Download and install from the package repository 
sudo apt-get install zsh

#[ch]ange [sh]ell to Zsh
chsh -s $(which zsh)

And you are all set!

If you want colors and stuff like that, I can recommend you the pure prompt

I'm currently using spaceship-prompt but requires a little bit more of configuration.

There's also geometry prompt

Those are my favorites 😅 .

Anyways, if you manage to make completion work with bash it would be awesome! good luck 🦆

@ghost ghost changed the title Autocomplete for file names doesn't work (partially) Autocomplete for file names doesn't work (partially) [bash] Apr 26, 2019
@efiop efiop added bug Did we break something? p3-nice-to-have It should be done this or next sprint labels Jul 23, 2019
@casperdcl casperdcl self-assigned this Dec 10, 2019
@casperdcl
Copy link
Contributor

this is annoying. doesn't work for me for dvc add in the latest version either

@casperdcl casperdcl added the ui user interface / interaction label Dec 10, 2019
@ghost
Copy link

ghost commented Dec 10, 2019

@casperdcl , Bash, right?

@casperdcl
Copy link
Contributor

@MrOutis if it was zsh I'd assign you :D

@ghost
Copy link

ghost commented Dec 10, 2019

@casperdcl, please feel free 🙂

@g-simmons2
Copy link

Not having the completions is definitely annoying, I switched to zsh just to have them :)

Would it be possible to make the completions work for 3-token commands (not sure if this is the right terminology) - for example dvc pipeline show <tab to choose a file>?

The current behavior for dvc pipeline show <tab> is to list the available options:

 -- option --
--help     -h  -- Show help message related to the command.                                                                                             
--quiet    -q  -- Be quiet.                                                                                                                             
--verbose  -v  -- Be verbose. 

And the output for dvc pipeline show incomplete_filename<tab> is

-- no more arguments --

meaning one has to type the complete filename by hand.

Would certainly be a nice to have!

@casperdcl
Copy link
Contributor

casperdcl commented Dec 19, 2019

@g-simmons2 definitely possible but you're talking about #1924 (zsh).

I'll submit a bash PR soon...

@g-simmons2
Copy link

@casperdcl If it works on bash I'll switch back 😄

@efiop efiop added p2-medium Medium priority, should be done, but less important and removed p3-nice-to-have It should be done this or next sprint labels Dec 26, 2019
@verasativa
Copy link
Contributor

+1 on the annoyed crew here, I'm looking forward for @casperdcl PR 🙄

@casperdcl
Copy link
Contributor

looking forward for @casperdcl PR

hah me too :D

casperdcl added a commit to casperdcl/dvc that referenced this issue Feb 18, 2020
@casperdcl casperdcl mentioned this issue Feb 18, 2020
4 tasks
@casperdcl
Copy link
Contributor

Fix coming soon (#3360)!

efiop pushed a commit that referenced this issue Feb 19, 2020
* completion: safer function names

* completion: fix missing expansions

Fixes #1923

* complete: bash: all filenames

* complete: bash: DVC-files

* complete: bash: safer and quicker opts
@efiop
Copy link
Member

efiop commented Feb 19, 2020

@casperdcl Should we create a ticket for subdir support?

@casperdcl
Copy link
Contributor

definitely will do it soon :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Did we break something? p2-medium Medium priority, should be done, but less important ui user interface / interaction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants