yadm-dev / yadm

Yet Another Dotfiles Manager
https://yadm.io/
GNU General Public License v3.0
5.15k stars 176 forks source link

shell completion issues (zsh & fish) #359

Open xenoterracide opened 3 years ago

xenoterracide commented 3 years ago

when typing yadm add <tab> files are never listed, and my shell seems to hang. This may be related to #292 but I don't know.

❯ yadm --version && zsh --version && uname -a                                                   # ~
yadm 3.1.0
zsh 5.8 (x86_64-pc-linux-gnu)
Linux CarbonX1-8-Manjaro 5.10.49-1-MANJARO #1 SMP PREEMPT Sun Jul 11 12:59:43 UTC 2021 x86_64 GNU/Linux
primeapple commented 3 years ago

Having the same issue with fish shell on MacOS.

> yadm --version && fish --version && uname -a
yadm 3.1.0
fish, version 3.3.1
Darwin my-mbpro.local 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64
kkga commented 3 years ago

Same problem on yadm 3.1.0, fish 3.3.1, Linux

Animeshz commented 3 years ago

Same problem yadm 3.1.0, fish 3.3.1.

moritzreiter commented 2 years ago

Is there really no fix or workaround in sight for this?

I read through two closed issues in the fish repo to try and find a hint for a solution.

One of the main fish developers (@faho) seems to basically say that tab completion to be very slow is to be expected when using $HOME as a git repo, because $HOME is usually very large (as in a huge number files).

I tried multiple variations of a ~/.gitignore to ignore most of $HOME as a workaround. One of the variations seemed to speed things up a little bit, but it was still way too slow to be pleasantly usable. I wonder if all yadm users who also use fish or zsh have this problem or just some?

Also I just tried, and the path completion works just fine with bash.

kkga commented 2 years ago

yeah, I still have the same issue.

I did manage to speed it up significantly by putting almost everything in ~/.gitignore though:

~ 1.7s » cat .gitignore
/notes
/tmp
/downloads
/sync
/repos
/projects
/pictures
/videos
/.local/share/fish
/.local/share/kak
/.config/chromium
.terminfo
.npm
.mozilla
.cargo
.local/cargo
.local/go
.local/lib
.local/share/Trash
.local/share/trash
.cache/
joshzcold commented 2 years ago

how about this work around? For me when I want to yadm add something its because I added a new config file that's untracked. for everything else that is tracked I use yadm add -u. unless there is a more supported way to manage our dotfiles that keeps the git add completion intact I would think it would be better to make this the functionality by default because the freeze on yadm add is confusing for new users.

# ~/.zshrc
function _yadm-add(){ _ls }

Peek 2021-12-20 11-15

Edit: with a bit more trickery we could have the best of both worlds.

function _yadm-add(){
  yadm_path="$(yadm rev-parse --show-toplevel)"
  yadm_options=$(yadm status --porcelain=v1 |
      awk -v yadm_path=${yadm_path} '{printf "%s/\"%s\"\\:\"%s\" ",  yadm_path, $2, $1 }' )
  _alternative \
    "args:custom arg:(($yadm_options))" \
    'files:filename:_files'
}

(anything better to do the formatting than awk?)

https://user-images.githubusercontent.com/36175703/146833803-4729f8fa-bb6c-4723-ab9e-457b33b173fd.mp4

kvokka commented 2 years ago

Same problem with MacOs 12.1, yadm 3.1.1 & zsh 5.8

yxnan commented 2 years ago

Same on Fedora 35, yadm 3.1.1, fish 3.3.1

However on fish there is a workaround to only use Ctrl+F to complete, which is a built-in functionality of the fish shell.

joshzcold commented 2 years ago

To move this along I made a pull request https://github.com/TheLocehiliosan/yadm/pull/417 From there we can look into improving the completion script to something ideal for everyone.

cmer commented 1 year ago

I can confirm that Fish tab completion is still broken in 3.2.2.

jc00ke commented 1 year ago

@TheLocehiliosan I somehow missed your comment, just happened to see it now.

❯ yadm --version && fish --version && uname -a
bash version 5.2.2(1)-release
 git version 2.37.2
yadm version 3.2.2
fish, version 3.5.1
Linux igor 5.19.0-45-generic #46-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 7 09:08:58 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Is there any other information I can provide that would be helpful?

lkirkwood commented 1 year ago

Bump on this — love yadm (3.1.1) but tab completion hangs with fish (3.3.1) is a big deal when adding previously untracked files. Anybody found a fix for this in fish?

matt-oakes commented 9 months ago

This appears to be an issue with the git completions bundles inside fish and not an issue with yadm.

You can see this behaviour by creating a new repo in your home with git init then entering git add and pressing tab. It will hang, likely due to the number of files which are untracked from your home directory.

joshzcold commented 9 months ago

I fixed this in zsh for yadm by just overwriting the default completions and putting in completion based on yadm status and ls

https://github.com/TheLocehiliosan/yadm/blob/0a5e7aa353621bd28a289a50c0f0d61462b18c76/completion/zsh/_yadm#L10

I'm sure we can just copy a fish equivalent function over

matt-oakes commented 9 months ago

The autocomplete for the git commands in fish come from telling complete that it's wrapping all of git, which passes through all of the git autocompletes which are bundled inside fish itself.

https://github.com/TheLocehiliosan/yadm/blob/0a5e7aa353621bd28a289a50c0f0d61462b18c76/completion/fish/yadm.fish#L74-L77

I tried adding my own autocomplete for add but it still seemed to use the git one for some reason. It's the first time I've tried to create autocompletions though.

joshzcold commented 9 months ago

This is what I have so far

function __fish_yadm_status_options
    # set -l fish_trace on
    set -l yadm_path (yadm rev-parse --show-toplevel)
    set -l yadm_status (yadm status --porcelain=v1 | awk '{print $2}')
    set -l yadm_options (echo "$yadm_status" | awk -v yadm_path="$yadm_path" '{printf "%s/%s%s\n",  yadm_path, $2, $1}' )
    echo $yadm_options
end

complete -e yadm --wraps 'git --git-dir=/home/joshua/.local/share/yadm/repo.git'
complete -c yadm -n "__fish_seen_subcommand_from add" -a "(__fish_yadm_status_options)"
complete -c yadm -n "__fish_seen_subcommand_from add" -F
complete -c yadm -n "__fish_seen_subcommand_from checkout" -a "(__fish_yadm_status_options)"
complete -c yadm -n "__fish_seen_subcommand_from checkout" -F

The part I haven't fixed yet is that when applied complete -e yadm --wraps 'git --git-dir=/home/joshua/.local/share/yadm/repo.git' will delete all the completions, but what I want is just to overwrite specific completions for git add and git checkout

I think the solution would be to wrap git completions for specific command and not everything.

Put into .config/fish/completions/yadm.fish to test, but will remove the default completions.

I don't think fish has to ability to wrap specific completions from git but ignore a couple. To fully fix this I think you would have to loop through the git completion file and ignore specific lines, which is ugly.

matt-oakes commented 8 months ago

Thanks for looking into this @joshzcold. It looks like we got to the same point in deciding that it wasn't possible to wrap a command but overwrite just some of the completions.

I have posted on the Fish Shell mailing list to ask if there is the ability to do this currently. Hopefully someone who knows more about Fish completions can provide some help from there.

kleutzinger commented 7 months ago

A slight workaround I do for yadm add ... on fish is to type the first couple characters of the file I want, then use ctrl + e or right arrow key to complete the filename. Not quite as powerful as true tab completion, but it's something.

You can also do yadm add (ls <tab>) for hacky tab completion.

radutomy commented 2 months ago

This bug is ridiculously annoying. It freezes my terminal for 20sec :(