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

Shell buffer get polluted when completing by TAB #21

Open
Yevgnen opened this issue Jul 6, 2022 · 15 comments
Open

Shell buffer get polluted when completing by TAB #21

Yevgnen opened this issue Jul 6, 2022 · 15 comments

Comments

@Yevgnen
Copy link
Contributor

Yevgnen commented Jul 6, 2022

When one press TAB in (! means cursor) a shell buffer with the following input

User@macOS: ~ (python-3.8.13)
 $ yes > /!

the buffer content becomes

User@macOS: ~ (python-3.8.13)
 $ User@macOS: ~ (python-3.8.13)
 $ yes > /!

then choose dev in mini buffer, and enter / then press TAB again with the following content in the buffer

User@macOS: ~ (python-3.8.13)
 $ User@macOS: ~ (python-3.8.13)
 $ yes > /dev/!

the buffer content becomes

User@macOS: ~ (python-3.8.13)
 $ User@macOS: ~ (python-3.8.13)

 $ dev/ptyr4 /dev/ptyr5 /dev/ptyr6 /dev/ptyr7 /dev/ptyr8
/dev/ptyr9 /dev/ptyra /dev/ptyrb /dev/ptyrc /dev/ptyrd /dev/ptyre
/dev/ptyrf /dev/ptys0 /dev/ptys1 /dev/ptys2 /dev/ptys3 /dev/ptys4
/dev/ptys5 /dev/ptys6 /dev/ptys7 /dev/ptys8 /dev/ptys9 /dev/ptysa
/dev/ptysb /dev/ptysc /dev/ptysd /dev/ptyse /dev/ptysf /dev/ptyt0
/dev/ptyt1 /dev/ptyt2 /dev/ptyt3 /dev/ptyt4 /dev/ptyt5 /dev/ptyt6
/dev/ptyt7 /dev/ptyt8 /dev/ptyt9 /dev/ptyta /dev/ptytb /dev/ptytc
/dev/ptytd /dev/ptyte /dev/ptytf /dev/ptyu0 /dev/ptyu1 /dev/ptyu2
/dev/ptyu3 /dev/ptyu4 /dev/ptyu5 /dev/ptyu6 /dev/ptyu7 /dev/ptyu8
/dev/ptyu9 /dev/ptyua /dev/ptyub /dev/ptyuc /dev/ptyud /dev/ptyue
/dev/ptyuf /dev/ptyv0 /dev/ptyv1 /dev/ptyv2 /dev/ptyv3 /dev/ptyv4
/dev/ptyv5 /dev/ptyv6 /dev/ptyv7 /dev/ptyv8 /dev/ptyv9 /dev/ptyva
/dev/ptyvb /dev/ptyvc /dev/ptyvd /dev/ptyve /dev/ptyvf /dev/ptyw0
/dev/ptyw1 /dev/ptyw2 /dev/ptyw3 /dev/ptyw4 /dev/ptyw5 /dev/ptyw6
/dev/ptyw7 /dev/ptyw8 /dev/ptyw9 /dev/ptywa /dev/ptywb /dev/ptywc
/dev/ptywd /dev/ptywe /dev/ptywf /dev/random /dev/rdisk0
/dev/rdisk0s1 /dev/rdisk0s2 /dev/rdisk1 /dev/rdisk1s1
/dev/rdisk1s2 /dev/rdisk1s3 /dev/rdisk1s4 /dev/rdisk1s5
/dev/rdisk1s5s1 /dev/rdisk1s6 /dev/sdt /dev/stderr /dev/stdin
/dev/stdout /dev/systrace /dev/tty /dev/tty.BLTH
/dev/tty.Bluetooth-Incoming-Port /dev/ttyp0 /dev/ttyp1 /dev/ttyp2
/dev/ttyp3 /dev/ttyp4 /dev/ttyp5 /dev/ttyp6 /dev/ttyp7 /dev/ttyp8
/dev/ttyp9 /dev/ttypa /dev/ttypb /dev/ttypc /dev/ttypd /dev/ttype
/dev/ttypf /dev/ttyq0 /dev/ttyq1 /dev/ttyq2 /dev/ttyq3 /dev/ttyq4
/dev/ttyq5 /dev/ttyq6 /dev/ttyq7 /dev/ttyq8 /dev/ttyq9 /dev/ttyqa
/dev/ttyqb /dev/ttyqc /dev/ttyqd /dev/ttyqe /dev/ttyqf /dev/ttyr0
/dev/ttyr1 /dev/ttyr2 /dev/ttyr3 /dev/ttyr4 /dev/ttyr5 /dev/ttyr6
/dev/ttyr7 /dev/ttyr8 /dev/ttyr9 /dev/ttyra /dev/ttyrb /dev/ttyrc
/dev/ttyrd /dev/ttyre /dev/ttyrf /dev/ttys0 /dev/ttys000
/dev/ttys001 /dev/ttys002 /dev/ttys003 /dev/ttys004 /dev/ttys1
/dev/ttys2 /dev/ttys3 /dev/ttys4 /dev/ttys5 /dev/ttys6 /dev/ttys7
/dev/ttys8 /dev/ttys9 /dev/ttysa /dev/ttysb /dev/ttysc /dev/ttysd
/dev/ttyse /dev/ttysf /dev/ttyt0 /dev/ttyt1 /dev/ttyt2 /dev/ttyt3
/dev/ttyt4 /dev/ttyt5 /dev/ttyt6 /dev/ttyt7 /dev/ttyt8 /dev/ttyt9
/dev/ttyta /dev/ttytb /dev/ttytc /dev/ttytd /dev/ttyte /dev/ttytf
/dev/ttyu0 /dev/ttyu1 /dev/ttyu2 /dev/ttyu3 /dev/ttyu4 /dev/ttyu5
/dev/ttyu6 /dev/ttyu7 /dev/ttyu8 /dev/ttyu9 /dev/ttyua /dev/ttyub
/dev/ttyuc /dev/ttyud /dev/ttyue /dev/ttyuf /dev/ttyv0 /dev/ttyv1
/dev/ttyv2 /dev/ttyv3 /dev/ttyv4 /dev/ttyv5 /dev/ttyv6 /dev/ttyv7
/dev/ttyv8 /dev/ttyv9 /dev/ttyva /dev/ttyvb /dev/ttyvc /dev/ttyvd
/dev/ttyve /dev/ttyvf /dev/ttyw0 /dev/ttyw1 /dev/ttyw2 /dev/ttyw3
/dev/ttyw4 /dev/ttyw5 /dev/ttyw6 /dev/ttyw7 /dev/ttyw8 /dev/ttyw9
/dev/ttywa /dev/ttywb /dev/ttywc /dev/ttywd /dev/ttywe /dev/ttywf
/dev/uart.BLTH /dev/urandom /dev/xcpm /dev/zero

 User@macOS: ~ (python-3.8.13)
 $ yes > /dev/!

Test config:

(add-to-list 'load-path "/Users/User/.emacs.d/straight/repos/emacs-native-shell-complete")
(require 'native-complete)
(native-complete-setup-bash)

(defun native-complete-shell-setup ()
  (add-to-list 'completion-at-point-functions #'native-complete-at-point ))
(add-hook 'shell-mode-hook #'native-complete-shell-setup)
@CeleritasCelery
Copy link
Owner

So if I understand, you have two line prompt like this:

 User@macOS: ~ (python-3.8.13)
 $ yes > 

and when you try and complete on /dev/ it is printing the results to the buffer instead collecting them into the candidate list?

@Yevgnen
Copy link
Contributor Author

Yevgnen commented Jul 6, 2022

@CeleritasCelery Hi, I do have a two line prompt(The second line ends with '$'). But the 'yes' part is a shell command.

when you try and complete on /dev/ it is printing the results to the buffer instead collecting them into the candidate list?

Yes. But the issue seems happen only when with output redirection like '> /dev...'.

@CeleritasCelery
Copy link
Owner

So I think there are two separate issues here (correct me if I am wrong). The first is that the prompt is being reprinted and the second is the output is going to the buffer. For the first, look at this part of the docs and #5 :

prompt components in completion list

Also what shell are you using? Is this bash or zsh?

@Yevgnen
Copy link
Contributor Author

Yevgnen commented Jul 8, 2022

The first is that the prompt is being reprinted

Yes.

Also what shell are you using? Is this bash or zsh?

I'm using GNU bash, version 5.1.16(1)-release (x86_64-apple-darwin21.1.0).

I remove the fancy settings from .bashrc, the prompts become bash-5.1$ . I also add the following settings but the issue still exists.

(setq native-complete-style-regex-alist '(("[-.a-z0-9]+\\$ " . bash)))

Screen Shot 2022-07-08 at 08 35 54


Updated:

The example in README also causes this issue for me. I don't see the shell prompt is showing up as completion candidate.

Screen Shot 2022-07-08 at 08 43 31

@CeleritasCelery
Copy link
Owner

Okay, I am using the same shell and and OS as you. Have you run native-complete-check-config?

Check the config

@Yevgnen
Copy link
Contributor Author

Yevgnen commented Jul 11, 2022

Hi, it says Success: native-complete setup for ’bash’ completion.

@CeleritasCelery
Copy link
Owner

Thanks. So to make sure I understand, the issue you are seeing is that the completions for yes > /dev/ are being sent to the shell buffer instead of being collected in the candidate list? The last screenshot you posted seems to indicate they are being used for completion correctly.

@Yevgnen
Copy link
Contributor Author

Yevgnen commented Jul 12, 2022

Sorry, I should have be more clearer.

the issue you are seeing is that the completions for yes > /dev/ are being sent to the shell buffer instead of being collected in the candidate list?

My original issue is, although the mini buffer is pop up properly, the prompt or the candidates are inserted into the shell buffer. The first time I press TAB, the prompt is inserted, and the buffer becomes

User@macOS: ~ (python-3.8.13)
 $ User@macOS: ~ (python-3.8.13)
 $ yes > /!                                                                 '!' = current cursor

The second time I press TAB, the candidates are inserted, and the buffer becomes

User@macOS: ~ (python-3.8.13)
 $ User@macOS: ~ (python-3.8.13)

 $ dev/ptyr4 /dev/ptyr5 /dev/ptyr6 /dev/ptyr7 /dev/ptyr8
/dev/ptyr9 /dev/ptyra /dev/ptyrb /dev/ptyrc /dev/ptyrd /dev/ptyre
/dev/ptyrf /dev/ptys0 /dev/ptys1 /dev/ptys2 /dev/ptys3 /dev/ptys4
/dev/ptys5 /dev/ptys6 /dev/ptys7 /dev/ptys8 /dev/ptys9 /dev/ptysa
/dev/ptysb /dev/ptysc /dev/ptysd /dev/ptyse /dev/ptysf /dev/ptyt0
/dev/ptyt1 /dev/ptyt2 /dev/ptyt3 /dev/ptyt4 /dev/ptyt5 /dev/ptyt6
/dev/ptyt7 /dev/ptyt8 /dev/ptyt9 /dev/ptyta /dev/ptytb /dev/ptytc
/dev/ptytd /dev/ptyte /dev/ptytf /dev/ptyu0 /dev/ptyu1 /dev/ptyu2
/dev/ptyu3 /dev/ptyu4 /dev/ptyu5 /dev/ptyu6 /dev/ptyu7 /dev/ptyu8
/dev/ptyu9 /dev/ptyua /dev/ptyub /dev/ptyuc /dev/ptyud /dev/ptyue
/dev/ptyuf /dev/ptyv0 /dev/ptyv1 /dev/ptyv2 /dev/ptyv3 /dev/ptyv4
/dev/ptyv5 /dev/ptyv6 /dev/ptyv7 /dev/ptyv8 /dev/ptyv9 /dev/ptyva
/dev/ptyvb /dev/ptyvc /dev/ptyvd /dev/ptyve /dev/ptyvf /dev/ptyw0
/dev/ptyw1 /dev/ptyw2 /dev/ptyw3 /dev/ptyw4 /dev/ptyw5 /dev/ptyw6
/dev/ptyw7 /dev/ptyw8 /dev/ptyw9 /dev/ptywa /dev/ptywb /dev/ptywc
/dev/ptywd /dev/ptywe /dev/ptywf /dev/random /dev/rdisk0
/dev/rdisk0s1 /dev/rdisk0s2 /dev/rdisk1 /dev/rdisk1s1
/dev/rdisk1s2 /dev/rdisk1s3 /dev/rdisk1s4 /dev/rdisk1s5
...

In both case, the mini buffer is pop up properly.

The last screenshot you posted seems to indicate they are being used for completion correctly.

When I test the example in RAEDME with a plain user> prompt, as you see in the screenshot, the prompt is inserted into the buffer, although the mini buffer is pop up properly too.

@CeleritasCelery
Copy link
Owner

Okay, let's solve the issue with the plain prompt first. Does this only happen with the very first prompt or does it happen every time? (for example if you start a new shell and press enter a few times then try completion does it still duplicate the prompt?)

@Yevgnen
Copy link
Contributor Author

Yevgnen commented Jul 12, 2022

Hi, a quick test showed that it could happen after many times of Enter.

Screen Shot 2022-07-13 at 00 00 48

@CeleritasCelery
Copy link
Owner

Interesting. I am not able to reproduce that.
image

What is your comint-prompt-regexp?

@Yevgnen
Copy link
Contributor Author

Yevgnen commented Jul 13, 2022

It's "[a-z]+> " in this case, the same as

(setq native-complete-style-regex-alist '(("[a-z]+> " . bash)))

@Yevgnen
Copy link
Contributor Author

Yevgnen commented Jul 13, 2022

I also tried to remove .bashrc, .profile, and .bash_profile and keep only export PS1="user > ", but no miracle.

@CeleritasCelery
Copy link
Owner

hmm, I am not sure what the issue could be.

Can you run this command in your shell?

(comint-redirect-send-command "ls" (get-buffer-create "test") nil)

That will tell us if it the redirection or something shell specific.

@Yevgnen
Copy link
Contributor Author

Yevgnen commented Jul 18, 2022

Hi, I run the command in a shell buffer in my home directory and here is its output

�[?2004l
Applications		PDF			def
Books			Pictures		dotfiles
Desktop			Public			git
Documents		Zotero			org
Downloads		abc			output
Library			backups			pretrained_models
Movies			bin			tmp
Music			datasets		xyz

Screen Shot 2022-07-18 at 09 57 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants