romkatv / zsh4humans

A turnkey configuration for Zsh
MIT License
1.78k stars 114 forks source link

Include bash completions support #27

Closed 3v1n0 closed 4 years ago

3v1n0 commented 4 years ago

I've been trying z4h and I quite loved it, maybe given the purpose of it it may also include support for bash completions as fallback, I've written a small plugin that handles it, which you may be interested in including by default, as it will only provide quite a lot more completions without much initialization time (just sourcing it takes something like ~10ms).

romkatv commented 4 years ago

Thanks for the info, I'll keep it in mind.

80ms is over 10x higher than what I could include by default but it should be easy for z4h users to load your plugin if they want to.

3v1n0 commented 4 years ago

80ms is over 10x higher than what I could include by default but it should be easy for z4h users to load your plugin if they want to.

Ok, fair enough, although the loading time is actually a lot smaller, I probably I computed it wrongly before:

time (source zsh-bash-completions-fallback/zsh-bash-completions-fallback.plugin.zsh)
 0,14s user 0,03s system 99% cpu 0,168 tota

And stays the same repeating the value, but this is when I've almost 900 bash completions locally.

And similar is when running it in the zsh4humans docker image:

image

However, given that these completions include many commands that are not available until installed, I've changed it not to load what is not available on startup and this leads to basically unnoticeable time:

image

While in a system with many more programs may lead to something like 8-9ms when adding something like 300 completions.


All these without zcompiling the file.

3v1n0 commented 4 years ago

@romkatv FYI I've added further updates to make the plugin to use lazy-loading all the times, and now the loading time is always unnoticeable, so I hope you could reconsider this decision.

❯ time (source zsh-bash-completions-fallback/zsh-bash-completions-fallback.plugin.zsh)
( source ; )  0,00s user 0,01s system 93% cpu 0,013 total
romkatv commented 4 years ago

13ms is still too much but maybe this is an artifact of measurement.

What are the drawbacks of using your plugin? Can you describe when using your plugin would result in user experience that's worse than not using it?

3v1n0 commented 4 years ago

13ms is still too much but maybe this is an artifact of measurement.

Well as per my configuration using zpmod source-study, it's never taking more than 3ms. But in fact as per the recent refactor, and lazy loading is just no overhead:

image

What are the drawbacks of using your plugin? Can you describe when using your plugin would result in user experience that's worse than not using it?

Well, in a standard unix system, bash provides nowadays more than 900 completions, now, when loading them all in z4h will introduce support for 580+ new completions.

Here's a list (in an ubuntu installation) ``` 2to3 _bash_completer 7za _bash_completer 7z _bash_completer a2x _bash_completer abicompat _bash_completer abidiff _bash_completer abidw _bash_completer abilint _bash_completer abinilint _bash_completer abipkgdiff _bash_completer abisym _bash_completer abook _bash_completer aclocal-1.10 _bash_completer aclocal-1.11 _bash_completer aclocal-1.12 _bash_completer aclocal-1.13 _bash_completer aclocal-1.14 _bash_completer aclocal-1.15 _bash_completer aclocal-1.16 _bash_completer aclocal _bash_completer add_members _bash_completer addpart _bash_completer alpine _bash_completer alternatives _bash_completer appdata-validate _bash_completer apt-build _bash_completer aptitude-curses _bash_completer arch _bash_completer arm-koji _bash_completer arpspoof _bash_completer asciidoc _bash_completer asciidoc.py _bash_completer aspell _bash_completer autoconf _bash_completer autoheader _bash_completer automake-1.10 _bash_completer automake-1.11 _bash_completer automake-1.12 _bash_completer automake-1.13 _bash_completer automake-1.14 _bash_completer automake-1.15 _bash_completer automake-1.16 _bash_completer automake _bash_completer autoreconf _bash_completer autorpm _bash_completer autoscan _bash_completer autossh _bash_completer autoupdate _bash_completer avctrl _bash_completer badblocks _bash_completer bash _bash bind _bash_completer bk _bash_completer blkdiscard _bash_completer blkid _bash_completer blkzone _bash_completer blockdev _bash_completer brz _bash_completer btdownloadcurses.py _bash_completer btdownloadgui.py _bash_completer btdownloadheadless.py _bash_completer build-rdeps _bash_completer bwrap _bash_completer cancel _bash_completer cardctl _bash_completer carton _bash_completer ccze _bash_completer cfagent _bash_completer cfdisk _bash_completer cfrun _bash_completer change_pw _bash_completer chcpu _bash_completer chdist _bash_completer checkbashisms _bash_completer check_db _bash_completer check_perms _bash_completer checksec _bash_completer chmem _bash_completer chpasswd _bash_completer chrome _bash_completer chromium-browser _bash_completer chronyc _bash_completer chrpath _bash_completer ciptool _bash_completer civclient _bash_completer civserver _bash_completer cksfv _bash_completer clang-10 _bash_completer clang-11 _bash_completer clang-8 _bash_completer clang-9 _bash_completer cleanarch _bash_completer clisp _bash_completer clone_member _bash_completer clzip _bash_completer colormake _bash_completer colormgr _bash_completer compare _bash_completer compgen _bash_completer complete _bash_completer config_list _bash_completer conjure _bash_completer cowbuilder _bash_completer cpack _bash_completer cpan2dist _bash_completer ctest _bash_completer ctrlaltdel _bash_completer cvsps _bash_completer dconf-editor _bash_completer dd-list _bash_completer debc _bash_completer debconf _bash_completer debconf-show _bash_completer debi _bash_completer debsnap _bash_completer deja-dup _bash_completer delpart _bash_completer desktop-file-validate _bash_completer dfutool _bash_completer dmypy _bash_completer dnssec-keygen _bash_completer dnsspoof _bash_completer dot _bash_completer dscextract _bash_completer dscverify _bash_completer dselect _bash_completer dsniff _bash_completer dumpdb _bash_completer dumpe2fs _bash_completer e2freefrag _bash_completer ebtables _bash_completer ecryptfs-migrate-home _bash_completer edquota _bash_completer eject _bash_completer ether-wake _bash_completer etherwake _bash_completer f77 _bash_completer f95 _bash_completer faillog _bash_completer fallocate _bash_completer fbgs _bash_completer fbi _bash_completer fdformat _bash_completer fdisk _bash_completer file _bash_completer filebucket _bash_completer filefrag _bash_completer file-roller _bash_completer filesnarf _bash_completer fincore _bash_completer findfs _bash_completer find_member _bash_completer fio _bash_completer flake8 _bash_completer flock _bash_completer freeciv _bash_completer freeciv-gtk2 _bash_completer freeciv-gtk3 _bash_completer freeciv-sdl _bash_completer freeciv-server _bash_completer freeciv-xaw _bash_completer fsck _bash_completer fsck.cramfs _bash_completer fsck.minix _bash_completer fsfreeze _bash_completer fstrim _bash_completer g4 _bash_completer g++-5 _bash_completer g++-6 _bash_completer g77 _bash_completer g++-7 _bash_completer g++-8 _bash_completer g95 _bash_completer gapplication _bash_completer gcc-5 _bash_completer gcc-6 _bash_completer gcc-7 _bash_completer gcc-8 _bash_completer gccgo-5 _bash_completer gccgo-6 _bash_completer gccgo-7 _bash_completer gccgo-8 _bash_completer gcj _bash_completer gcl _bash_completer gdbus _bash_completer genaliases _bash_completer gendiff _bash_completer geoiplookup6 _bash_completer geoiplookup _bash_completer getbuildlog _bash_completer gfortran-5 _bash_completer gfortran-6 _bash_completer gfortran-7 _bash_completer gfortran-8 _bash_completer gfortran _bash_completer gio _bash_completer gitlab-api-v4 _bash_completer gkrellm2 _bash_completer gkrellm _bash_completer gnatmake _bash_completer gnokii _bash_completer gnome-control-center _bash_completer gnome-extensions _bash_completer gnome-mplayer _bash_completer gnome-screenshot _bash_completer gnumake _bash_completer google-chrome _bash_completer google-chrome-stable _bash_completer gpc _bash_completer gpgv2 _bash_completer gresource _bash_completer groupmems _bash_completer grpck _bash_completer gssdp-discover _bash_completer hciattach _bash_completer hciconfig _bash_completer hcitool _bash_completer hddtemp _bash_completer hid2hci _bash_completer hping2 _bash_completer hping3 _bash_completer hping _bash_completer hstr _bash_completer htpasswd _bash_completer hunspell _bash_completer hwclock _bash_completer ibus.bash _bash_completer idn _bash_completer ifquery _bash_completer ifstat _bash_completer ifstatus _bash_completer influx _bash_completer inject _bash_completer inotifywait _bash_completer inotifywatch _bash_completer insmod.static _bash_completer ipcmk _bash_completer ipcrm _bash_completer ipcs _bash_completer iperf3 _bash_completer iperf _bash_completer ipmitool _bash_completer ipv6calc _bash_completer iscsiadm _bash_completer isort _bash_completer isosize _bash_completer isql _bash_completer iwlist _bash_completer iwpriv _bash_completer iwspy _bash_completer javaws _bash_completer jpegoptim _bash_completer jps _bash_completer jshint _bash_completer jsonschema _bash_completer json_xs _bash_completer k3b _bash_completer kcov _bash_completer kmod _bash_completer koji _bash_completer kplayer _bash_completer ktutil _bash_completer l2ping _bash_completer larch _bash_completer lastlog _bash_completer lbzip2 _bash_completer ldapadd _bash_completer ldapcompare _bash_completer ldapdelete _bash_completer ldapmodify _bash_completer ldapmodrdn _bash_completer ldappasswd _bash_completer ldapsearch _bash_completer ldapvi _bash_completer ldapwhoami _bash_completer ldattach _bash_completer lftpget _bash_completer licensecheck _bash_completer lilo _bash_completer lisp _bash_completer list_admins _bash_completer list_lists _bash_completer list_members _bash_completer list_owners _bash_completer list-unreleased _bash_completer locale-gen _bash_completer logger _bash_completer lrzip _bash_completer lscpu _bash_completer lsipc _bash_completer lslocks _bash_completer lslogins _bash_completer lsmem _bash_completer lsns _bash_completer lsscsi _bash_completer luac _bash_completer luseradd _bash_completer luserdel _bash_completer lusermod _bash_completer lvchange _bash_completer lvcreate _bash_completer lvdisplay _bash_completer lvextend _bash_completer lvm _bash_completer lvmdiskscan _bash_completer lvreduce _bash_completer lvremove _bash_completer lvrename _bash_completer lvresize _bash_completer lvs _bash_completer lvscan _bash_completer lzip _bash_completer macof _bash_completer mailmanctl _bash_completer mailsnarf _bash_completer mass-bug _bash_completer mc _bash_completer mcookie _bash_completer mcrypt _bash_completer mdecrypt _bash_completer mdtool _bash_completer medusa _bash_completer mencoder _bash_completer mesg _bash_completer micropython _bash_completer mii-diag _bash_completer minicom _bash_completer mk-build-deps _bash_completer mkfs _bash_completer mkfs.bfs _bash_completer mkfs.cramfs _bash_completer mkfs.minix _bash_completer mkinitrd _bash_completer mk-origtargz _bash_completer mkswap _bash_completer mmcli _bash_completer mmsitepass _bash_completer mock _bash_completer modules _bash_completer monodevelop _bash_completer more _bash_completer mount.linux _bash_completer mountpoint _bash_completer mplayer2 _bash_completer msgsnarf _bash_completer msynctool _bash_completer mtx _bash_completer munindoc _bash_completer munin-node-configure _bash_completer munin-run _bash_completer munin-update _bash_completer muttng _bash_completer mypy _bash_completer namei _bash_completer nethogs _bash_completer netplan _bash_completer newlist _bash_completer newusers _bash_completer nproc _bash_completer nsenter _bash_completer nsupdate _bash_completer ntpdate _bash_completer ocamlfind _bash_completer op _bash_completer optipng _bash_completer pack200 _bash_completer partx _bash_completer pbuilder-dist _bash_completer pbzip2 _bash_completer pccardctl _bash_completer pdlzip _bash_completer perlcritic _bash_completer perltidy _bash_completer pivot_root _bash_completer pkg_deinstall _bash_completer pkg-get _bash_completer pkgnames _bash_completer pkgutil _bash_completer plague-client _bash_completer plotchangelog _bash_completer plzip _bash_completer pm-hibernate _bash_completer pm-is-supported _bash_completer pm-powersave _bash_completer pm-suspend _bash_completer pm-suspend-hybrid _bash_completer pngfix _bash_completer portinstall _bash_completer portupgrade _bash_completer postalias _bash_completer postcat _bash_completer postfix _bash_completer postmap _bash_completer povray _bash_completer ppc-koji _bash_completer prelink _bash_completer pristine-tar _bash_completer prlimit _bash_completer pts-subscribe _bash_completer pts-unsubscribe _bash_completer puppet _bash_completer puppetca _bash_completer puppetd _bash_completer puppetdoc _bash_completer puppetmasterd _bash_completer puppetqd _bash_completer puppetrun _bash_completer pvchange _bash_completer pvcreate _bash_completer pvdisplay _bash_completer pvmove _bash_completer pvremove _bash_completer pvs _bash_completer pvscan _bash_completer pwck _bash_completer pwd _bash_completer pxz _bash_completer pycodestyle _bash_completer pydoc3 _bash_completer pydoc _bash_completer pydocstyle _bash_completer pyflakes _bash_completer pylint-2 _bash_completer pylint-3 _bash_completer pylint _bash_completer pypy3 _bash_completer pypy _bash_completer py.test-2 _bash_completer pytest-2 _bash_completer py.test-3 _bash_completer pytest-3 _bash_completer py.test _bash_completer pytest _bash_completer python2 _bash_completer python3 _bash_completer python _bash_completer pyvenv-3.4 _bash_completer pyvenv-3.5 _bash_completer pyvenv-3.6 _bash_completer pyvenv-3.7 _bash_completer pyvenv-3.8 _bash_completer pyvenv _bash_completer qemu _bash_completer qemu-kvm _bash_completer qemu-system-i386 _bash_completer qemu-system-x86_64 _bash_completer qrunner _bash_completer quota _bash_completer quotacheck _bash_completer quotaoff _bash_completer quotaon _bash_completer radvdump _bash_completer ralsh _bash_completer raw _bash_completer rc-alert _bash_completer rdict _bash_completer readprofile _bash_completer remove_members _bash_completer repomanage _bash_completer repquota _bash_completer reptyr _bash_completer resizepart _bash_completer resolvconf _bash_completer rev _bash_completer rfcomm _bash_completer rlog _bash_completer rmlist _bash_completer rpcdebug _bash_completer rpm2targz _bash_completer rpm2tgz _bash_completer rpm2txz _bash_completer rpmbuild-md5 _bash_completer rpmcheck _bash_completer rtcwake _bash_completer runuser _bash_completer s390-koji _bash_completer salsa _bash_completer sbcl _bash_completer sbcl-mt _bash_completer sbopkg _bash_completer sdptool _bash_completer setarch _bash_completer setpriv _bash_completer setquota _bash_completer setterm _bash_completer sfdisk _bash_completer shellcheck _bash_completer sidedoor _bash_completer sitecopy _bash_completer slackpkg _bash_completer slapt-get _bash_completer slapt-src _bash_completer smbcacls _bash_completer smbcquotas _bash_completer smbget _bash_completer smbpasswd _bash_completer smbtar _bash_completer smbtree _bash_completer snap _bash_completer snownews _bash_completer source-highlight _bash_completer sparc-koji _bash_completer spovray _bash_completer sshmitm _bash_completer sshow _bash_completer stream _bash_completer svk _bash_completer svnlook _bash_completer swaplabel _bash_completer swapoff _bash_completer swapon _bash_completer synclient _bash_completer sync_members _bash_completer sysbench _bash_completer systemd-path _bash_completer taskset _bash_completer tc _bash_completer tcpkill _bash_completer tcpnice _bash_completer tightvncviewer _bash_completer tipc _bash_completer transition-check _bash_completer tshark _bash_completer tx _bash_completer ua _bash_completer umount.linux _bash_completer unpack200 _bash_completer unshare _bash_completer unshunt _bash_completer update-initramfs _bash_completer urlsnarf _bash_completer utmpdump _bash_completer uupdate _bash_completer vgcfgbackup _bash_completer vgcfgrestore _bash_completer vgchange _bash_completer vgck _bash_completer vgconvert _bash_completer vgcreate _bash_completer vgdisplay _bash_completer vgexport _bash_completer vgextend _bash_completer vgimport _bash_completer vgmerge _bash_completer vgmknodes _bash_completer vgreduce _bash_completer vgremove _bash_completer vgrename _bash_completer vgs _bash_completer vgscan _bash_completer vgsplit _bash_completer vigr _bash_completer vipw _bash_completer wall _bash_completer wdctl _bash_completer webmitm _bash_completer what-patch _bash_completer whiptail _bash_completer whodepends _bash_completer who-uploads _bash_completer wine _bash_completer wine-development _bash_completer wine-stable _bash_completer withlist _bash_completer wnpp-alert _bash_completer wnpp-check _bash_completer wol _bash_completer wsimport _bash_completer wtf _bash_completer wvdial _bash_completer xdg-mime _bash_completer xdg-settings _bash_completer xgamma _bash_completer xm _bash_completer xmlwf _bash_completer xmms _bash_completer xpovray _bash_completer xvfb-run _bash_completer xzdec _bash_completer yum-arch _bash_completer zopfli _bash_completer zopflipng _bash_completer zramctl _bash_completer ```

So, this would add support for and tools like snap, flatpak other than popular tools as aws, without much effort or the need to port them.

Given that z4h is a perfect tool for people who are new to zsh (and normally coming from bash), I imagine it's a quick way to make these users feel at home quite easily.

romkatv commented 4 years ago

Thanks for the improvements.

What are the drawbacks of using your plugin? Can you describe when using your plugin would result in user experience that's worse than not using it?

Could you answer this?

romkatv commented 4 years ago

Just to save me and you some time. I took a look at the source code of https://github.com/3v1n0/zsh-bash-completions-fallback and it doesn't appear it's at the point where I can enable it by default in zsh4humans. Some issues can likely be fixed (see below), others require intelligent fallbacks.

I haven't tried it but it seems like this would fail:

zsh-bash-completions-fallback can be manually enabled by zsh4humans if they so desire. If or when it acquires a larger user base and matures, I'll consider enabling it by default. Not yet though.

3v1n0 commented 4 years ago

What are the drawbacks of using your plugin? Can you describe when using your plugin would result in user experience that's worse than not using it? Could you answer this?

Well, I can't imagine something like that honestly, the only thing, when using the lazy loading, could be that the first time you hit the TAB key it may lead to some slowdown (but really, always something under 10-15ms) to load the completions, but other than that, I can't see anything different from normal behavior if not better when a completion is available.

Type git clon -, position the cursor after clon and trigger bash completion. It won't complete.

By default git completion isn't provided if there's a zsh completion available, however, in case it's enabled, however sure, the issues you've mentioned are present as it's not always possible to simulate what a real interactive bash expects. However I have some ideas about those, so maybe I can reiterate.

My whole point however, is better a not-perfect (but reliable) completion than no completion, no?

romkatv commented 4 years ago

By default git completion isn't provided if there's a zsh completion available

I realize that. I used it as an example. It's not important that the command is git.

My whole point however, is better a not-perfect (but reliable) completion than no completion, no?

I think the default completion (that essentially just completes files) is better than incorrect completion.

3v1n0 commented 4 years ago

I realize that. I used it as an example. It's not important that the command is git.

@romkatv sure, I see the point, and now both the issues are fixed. So the completions are per the actual word under cursor, it was in my TODO already but as it started as a draft, I didn't had time to finish it.

romkatv commented 4 years ago

Great! Thanks for the speedy fixes.

My point still stands. Get more people to use your plugin. Once others start using your code, you get invaluable feedback and bug reports that allows you to iron out bugs and improve usability.