kellyjonbrazil/jtbl

Add bash completion

Closed this issue · 9 comments

Hi!

Can you add bash completion as in the jc project?

Definitely possible. I'll see on the level of effort. It was very difficult to figure out how to do it for jc but I should be able to use a lot of lessons learned there for jtbl.

I have added some simple bash and zsh completions in the dev branch. I can push out a new release if these look ok.

https://github.com/kellyjonbrazil/jtbl/blob/dev/completions/jtbl_bash_completion.sh

https://github.com/kellyjonbrazil/jtbl/blob/dev/completions/jtbl_zsh_completion.sh

I'm getting this error:

root@ubuntu-2004-clean-01:~# wget https://github.com/kellyjonbrazil/jtbl/blob/dev/completions/jtbl_bash_completion.sh
--2023-12-11 10:00:35--  https://github.com/kellyjonbrazil/jtbl/blob/dev/completions/jtbl_bash_completion.sh
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8316 (8.1K) [text/plain]
Saving to: ‘jtbl_bash_completion.sh’

jtbl_bash_completion.sh          100%[=========================================================>]   8.12K  --.-KB/s    in 0s      

2023-12-11 10:00:35 (39.8 MB/s) - ‘jtbl_bash_completion.sh’ saved [8316/8316]

root@ubuntu-2004-clean-01:~# chmod +x jtbl_bash_completion.sh
root@ubuntu-2004-clean-01:~# mv jtbl_bash_completion.sh /etc/bash_completion.d/
root@ubuntu-2004-clean-01:~# exit
logout
sysadmin@ubuntu-2004-clean-01:~$ sudo -i
[sudo] password for sysadmin: 
-bash: COMP_WORDS: bad array subscript
payload:allShortcutsEnabled:false: command not found
root@ubuntu-2004-clean-01:~# 

Strange - I was trying to be backwards compatible for older versions of Bash, but it seems that doesn't work and nobody else bothers so I used the 4.x completion commands in the new version. Can you try with the new script?

sysadmin@ubuntu-2004-clean-01:~$ sudo -i
[sudo] password for sysadmin: 
payload:allShortcutsEnabled:false: command not found
root@ubuntu-2004-clean-01:~# sha1sum /etc/bash_completion.d/jtbl_bash_completion.sh
26045bc503ff8061fedf670d543673fdc6b8149d  /etc/bash_completion.d/jtbl_bash_completion.sh
root@ubuntu-2004-clean-01:~# 

for older versions of Bash

I have ubuntu 14.04. I can put it there and check it out.

I can't tell - is that working now with the fix or is it broken? It's working on my Ubuntu 16.04 VM.

Here is the new sha1:

$ sha1sum /etc/bash_completion.d/jtbl_completion.sh 
121bb98b27eea4fa6f37a71eb3f57cdd3c2f7243  /etc/bash_completion.d/jtbl_completion.sh
sysadmin@pxe:/tmp/jtbl$ LC_ALL=C git status                                                                                        
On branch dev
Your branch is up to date with 'origin/dev'.

nothing to commit, working tree clean
sysadmin@pxe:/tmp/jtbl$ sha1sum completions/jtbl_bash_completion.sh
69c58b7aedb6d6b04321d27c013321fa970ea7a0  completions/jtbl_bash_completion.sh
sysadmin@pxe:~$ jtbl --
--cols      --dokuwiki  --help      --markdown  --quiet     --truncate  
--csv       --fancy     --html      --no-wrap   --rotate    --version   
sysadmin@pxe:~$ jtbl --
sysadmin@pxe:~$ LC_ALL=C bash --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
sysadmin@pxe:~$ lsb_release --all
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.6 LTS
Release:        14.04
Codename:       trusty

It works!

Wow, it works on 20.04 too!