
How to Enable Autocomplete in Mac Terminal - TimLeland
https://timleland.com/how-to-enable-autocomplete-in-mac-terminal/
======
hrcxxx
Oh-my-zsh + iterm2 is the best combination out there imho

~~~
AdamGibbins
Both are horribly slow, seriously, try iTerm2 for a week then try Terminal -
you'll then notice how much latency iTerm2 adds to basic key presses.

oh-my-zsh is also horribly slow out of box, spend some time manually
configuring zsh and observe your terminals open in fractional seconds instead
of multiple seconds.

~~~
ReverseCold
I switched from iTerm+ohmyzsh to Terminal + fish.

It's basically exactly what I had before except I can't click on links in my
terminal.

~~~
yoz-y
I've tried fish for a year or two but in the end I went back to zsh. I found
that the differences in scripting languages were just not worth it.

~~~
ReverseCold
My scripts are still bash scripts, I just run them with `bash somescript.sh`.

------
TmpAccToSayThis
If you use '~/.ssh/config' with SSH, add this to your '~/.bash_profile' file
to add autocompletion for all your servers:

complete -f -d -W "$(grep '[Hh]ost ' ~/.ssh/config | grep -v '*' | awk '{print
$2}')" ssh scp

If you don't use '~/.ssh/config' but have a '~/.ssh/known_hosts' file, add
this instead:

complete -f -d -W "$(cut -d',' -f1 ~/.ssh/known_hosts | awk '{print $1}')" ssh
scp

Similarly, you can use the 'complete' command in '~/.bash_profile' to tweak
everything. Some other ways I use it are:

1\. Make 'cd' and 'ls' only autocomplete for directories: complete -d cd ls

2\. Make 'foo' autocomplete with 'bar0' and 'bar1': complete -W 'bar0 bar1'
foo

------
massysett
inputrc has nothing to do with Mac Terminal. It’s the configuration file for
GNU readline.

~~~
mrzool
Exactly! The title is inaccurate and misleading. Readline works across all
terminal emulators and is supported by a lot of applications, Bash being just
one of them.

------
aiyodev
Recently discovered the wonders of zsh and oh my zsh. If you’re like me and
never tried anything other than bash, you’re missing out.

~~~
alx_hghs
Fish and oh-my-fish is also great. I like it more than oh-my-zsh because it
requires less configuration

------
tachion
If any of you find Oh-My-ZSH bloated and slow and ZPrezto being abandonware
then check out ZIM framework that's ZPrezto fork with goal of being
maintained, workable and making ZSH great again ;)

~~~
lugg
What's the terminal boot time like using Zim?

I got omz + zgen down to sub 60ms but I had to trade some functionality to get
there.

I tried zplug but my pruned omz worked out slower than zgen.

------
hibbelig
The bash that comes with macOS is very old due to Apple sticking to GPLv2 I
believe. So I did "brew install bash" and switched my login shell from
/bin/bash to /usr/local/bin/bash and now I can use new bash things.

Just a thought.

------
megido
brew install bash-completion?

~~~
TimLeland
Thanks I’ll check that out

------
agiamas
from a comment from tfa: 'Now if you’re really tired of seventies tech you
should try fish.' Really, that's pretty much it.

~~~
_verandaguy
The problem with fish is that it's not POSIX-compliant, and it doesn't try to
be (it's a design non-goal), and it's not backwards-compatible with the
literally billions of POSIX-compliant scripts and tools already out there.

It doesn't even support `!!` since the maintainers don't seem to like it[0].

    
    
        [0] https://github.com/fish-shell/fish-shell/issues/288

~~~
ronjouch
The literally billions of POSIX-compliant scripts and tools already out there
will run just fine under fish with a hashbang/shebang (a first line that
defines what the file executed should be opened with, e.g. `/usr/bin/env sh`)
:) . And it's not as if adding a hashbang was painful, not having one is super
bad anyway as it leads to uncertainty of whether the script is bash / sh /
etc, and can lead to tricky corner cases.

I was a wary zsh user too, until I moved my zsh aliases to scripts with a
proper hashbang, then migration to fish was painless, and the benefits are
real: I get all the features I expected from my long-tuned zsh, with none of
the maintenance/performance pains.

Actually, even for one-time personal scripts I still default to writing
(ba)sh, because 1. habit/competence, 2. shellcheck, 3. what you say: examples
and resources are everywhere.

Tangentially, upcoming fish will support POSIX && and || (in addition to
maybe-even-weirder `; and` / `; or`), and already does if you build from
sources now.

~~~
prg318
So long as you don't need to "source" any of these POSIX-compliant scripts
into your environment... A shebang'd script cannot affect the environment of
the parent process

~~~
ronjouch
Indeed, thanks for the precision. Never ran into that, though; config.fish is
the only thing touching my environment.

~~~
prg318
Lucky for you. I have really come to love zsh's sh and ksh emulation features
for this very reason. I have worked in various work environments where setting
up a build environment or a testing environment required sourcing ksh scripts
that sourced even more ksh scripts. The majority of the engineers on these
teams would "deal with" ksh for this reason but a few of the "geekier"
engineers would set up zsh with ksh emulation in order to work in a more
usable shell.

------
webdevetc
But if you don't do this, you can still use <tab> \- and if there are more
than one option it'll list the possibilities. With this you just have to tab
through all the options to see what is there.

~~~
Aaargh20318
So basically it switches the behaviour to what CMD does on Windows. IMO this
is extremely annoying and I wish I could disable it on Windows.

If you have 3 options starting with the same prefix, it's fine, but if there's
hundreds (e.g. a directory with a lot of libraries starting with
lib<something>), it becomes highly annoying and it's better to just give the
list so I can type the next letter

~~~
hibbelig
For PowerShell, there is PSReadLine, and that has an option to make completion
more bash-like in that it completes common prefixes, then lists all options
afterwards.

(Say you have a directory with two subdirectories "fooabc" and "foo123". You
are in the directory and you type "cd f" and then hit tab. This will complete
to "cd foo", and if you hit tab again, then it will show the two options, and
then you have to enter "a" or "1" to disambiguate.)

------
nkcmr
what i have yet to figure out is how i can make the commands that i build work
with auto-completion. i have never been able to find a good guide. anyone have
a good resource/library (in Go) that can help me with this?

~~~
pgwhalen
Are you familiar with
[https://github.com/spf13/cobra](https://github.com/spf13/cobra)? It's used by
a few heavy hitters (kubernetes's kubectl) and it provides you a bit of help
with bash completion:
[https://github.com/spf13/cobra/blob/master/bash_completions....](https://github.com/spf13/cobra/blob/master/bash_completions.md)

I just added bash completion to a few internal tools that work with kafka,
basically just autocompleting topics. It was a little harder than I would have
liked (who wants to write all that bash), and I had to fix a bug in Cobra, but
overall it wasn't that bad.

I'm actually at Gophercon right now, if anyone wants to hack on Cobra at the
community day on Thursday to make this easier, shoot me an email (@gmail).

------
stevage
Eep, people still use MacOS Terminal? Just get iTerm2, it's vastly better.

