jbangdev / jbang

Unleash the power of Java - JBang Lets Students, Educators and Professional Developers create, edit and run self-contained source-only Java programs with unprecedented ease.
https://jbang.dev
MIT License
1.43k stars 159 forks source link

Bash completion for java file names is not always proposed #235

Open grumpyf0x48 opened 4 years ago

grumpyf0x48 commented 4 years ago

Scenario 1

When entering:

$ jbang

Bash completion does not completes any files (.java or not) found in the current directory.

Scenario 2

If using:

$ jbang h

then files starting with 'h' are proposed for completion.

Scenario 3

When adding 'run' to the scenarios 1 and 2, no completion is proposed.

maxandersen commented 4 years ago

which version of jbang are you running and what shell ? (jbang version)

with 0.36.1 here is what I get in examples when I have run source <(jbang completion)

$ jbang <tab x 2>
 .gitignore                    findmodule.java               junitrun.java                 smee.java
.idea/                        gh_fetch_release_assets.java  lang.java                     sparkjava.java
analytics.java                githubinfo.java               piping.java                   tz.adoc
asciidoc.java                 helloworld.jar                plantuml.java                 tz.html
asciidoctor.java              helloworld.java               progress.java                 tz.java
benchmark/                    helloworld.jsh                qute.java                     undertow.java
camel.java                    hibernate.java                ratpack.java                  update_catalog.java
checksum.java                 imap.java                     readme.adoc                   urldep.java
classpath_example.java        inetTest.java                 records.java                  vertx.java
classpath_example.jsh         jetty.jsh                     resteasyclient.java           webdriver.java
client_secret.json            jfx.java                      sakila.mv.db                  ytListLive.java
docker.java                   jfxtiles.java                 script.java
envdetector.java              junit-run.java                shrinkwrap.java
$ jbang
$ jbang h
helloworld.jar   helloworld.java  helloworld.jsh   hibernate.java
$ jbang h

and jbang run is the same.

Thus I can't reproduce it on my side for now - would need some more details. thanks.

grumpyf0x48 commented 4 years ago

I've reproduced on Debian 8 and 9:

$ ls \<tab> analytics.java docker.java hibernate.java lang.java sakila.mv.db undertow.java asciidoc.java envdetector.java imap.java piping.java script.java update_catalog.java asciidoctor.java findmodule.java inetTest.java plantuml.java shrinkwrap.java urldep.java benchmark gh_fetch_release_assets.java jetty.jsh progress.java smee.java vertx.java camel.java githubinfo.java jfx.java ratpack.java sparkjava.java webdriver.java checksum.java helloworld.jar jfxtiles.java readme.adoc tz.adoc classpath_example.java helloworld.java junit-run.java records.java tz.html classpath_example.jsh helloworld.jsh junitrun.java resteasyclient.java tz.java

$ jbang \<tab> or $ jbang \<tab>\<tab> alias cache completion edit init run trust version

This one looks ok as we cannot complete with commands and file names at the same time.

$ jbang h\<tab> helloworld.jar helloworld.java helloworld.jsh hibernate.java

$ jbang run\<tab> or $ jbang run h\<tab>

This one completes nothing on my environments.

$ jbang version 0.33.0

$ bash -version GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu) ...

maxandersen commented 4 years ago

can you update to latest jbang just to be sure you got the latest fixes and reproduce ?

grumpyf0x48 commented 4 years ago

With Debian 10:

$ jbang version 0.36.1

and

$ bash --version GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu) ...

i have the same results.

I have noticed that jbang completion script still refers to Picocli 4.3.2:

$ more /etc/bash_completion.d/jbang

#!/usr/bin/env bash
#
# jbang Bash Completion
# =======================
#
# Bash completion support for the `jbang` command,
# generated by [picocli](http://picocli.info/) version 4.3.2.
#
...

It is wanted ?

maxandersen commented 4 years ago

we could update to more recent picocli version but not sure that will fix the issue you are seeing ?

grumpyf0x48 commented 4 years ago

What puzzles me is that i've seen in the commit log that jbang now uses Picoli 4.5.0. So where does comes this 4.3.2 reference from ?

maxandersen commented 4 years ago

Good question - my guess is you have an older jbang for some reason ?

here is output of jbang completion v0.38.0:

   6   │ # Bash completion support for the `jbang` command,
   7   │ # generated by [picocli](http://picocli.info/) version 4.5.0.
grumpyf0x48 commented 4 years ago

Yes with 0.38 version, 4.5.0 is displayed.

maxandersen commented 4 years ago

but still same completion issue from your shell?

grumpyf0x48 commented 4 years ago

yes :-(

grumpyf0x48 commented 3 years ago

With the following Dockerfile:

FROM ubuntu:20.04

RUN apt-get -q update && \
    apt-get --no-install-recommends -y install bash-completion ca-certificates curl sudo && \
    useradd jbang -m -d /home/jbang -s /bin/bash && \
    adduser jbang sudo && \
    sed -i "s/ALL$/NOPASSWD: ALL/" /etc/sudoers

USER jbang
WORKDIR /home/jbang

RUN curl -Ls https://sh.jbang.dev | bash -s - && \
    echo 'PATH=$HOME/.jbang/bin:$PATH' | tee -a .bashrc

You can reproduce the behavior i have:

jbang init Script.java

# completion occurs
ls <TAB><TAB>

source <(jbang completion)

# completion does not occur in any case
jbang <TAB><TAB>
jbang run <TAB><TAB>

source <(jbang completion | sed "s/+o default/-o default/")

# completion occurs in both cases
jbang <TAB><TAB>
jbang run <TAB><TAB>

So i think it is the Picocli completion script that disable default Bash completion for some Jbang commands.