• Dave@lemmy.nz
    link
    fedilink
    arrow-up
    4
    ·
    14 hours ago

    Just checking, because I learnt to type before I worked this out, and because surely someone reading doesn’t know: press tab. Bash will fill in file names from your current directory.

    E.g. say you have files fred1file, fred2file, jim.

    Type f then press tab, it will fill to “fred”. Then press 2 and press tab again and it will fill the full “fred2file”.

    Have a play, it works in heaps of situations.

    • bobo@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      2 hours ago

      Bash will also do autocomplete for cli programs that have autocomplete functionality. Try typing:

      git r<tab><tab>

      you’ll see options for all the git commands that start with r. Often cli commands will have autocompletion for long (double dash) options.

      If you want to see all the commands that have auto complete available, look in:

      /usr/share/bash-completion/completions/

      There’s a few other locations they can live, notably:

      /etc/bash_completion.d/ ~/.bash_completion ~/.local/share/bash-completion/completions/

      I don’t know if there are more or if there is any variation per distro.

      You can also write your own bash completions. They can get pretty smart and context sensitive.

      Pretty good beginning tutorial:

      https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial

      edit - I should’ve mentioned that this isn’t native to bash, it requires installation of bash-completion. But bash-completion is installed by default in many distros.