1

In my GNU bash, version 4.3.11 I am using git and sometimes in comments I want to mention the files I changed. When doing so, I try to use the tab completion, so that I just have to type the first characters of the file name and then get it auto completed with the tab:

So I say:

git add README.md 

And then

git commit -m "Modified RE
#                         ^
#                         here I press tab and nothing happens

However, it doesn't get expanded because it is within quotes. Instead, this does work:

git commit -m "Modified" RE
#                          ^
#                          here I press tab so that I get README.md

So is what I end up doing: closing the quotes, completing with Tab, removing the previous quote and appending it to the end of the comment I wrote. This is a bit tiring, so I wonder:

Is there any way to get the tab completion working within quotes?

fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • 1
    How should the tab completion distinguish between `"Modified Re` and `"Read M` when completing inside quotes? Where a file in cwd is called `Read Me.txt` and another called `Modules`? – Andreas Louv Jun 02 '16 at 11:43
  • @andlrc uhms, this is a good point I hadn't thought about, and probably the reason why tab-completion within quotes is not possible. – fedorqui Jun 02 '16 at 11:48
  • 2
    I think it already works inside quotes, but not on a word basic, but rater on the whole thing: `"Modified RE` -> searches cwd for files matching `"Modified RE"*` – Andreas Louv Jun 02 '16 at 11:49
  • @andlrc true. So the workaround may be to open the quotes, use tab-completion with the name, move back and prepend the comment. That is, `git commit -m "RE` to get `git commit -m "README.md"` and then move back to write before README.md. – fedorqui Jun 02 '16 at 11:52
  • That is a workaround, but I don't like it to much: `git commit -m "Modified" RE` – Andreas Louv Jun 02 '16 at 12:00
  • 1
    What about writing your command from within a text editor with an omni completion feature and then sending the command to the shell? – Adrien Horgnies Jun 02 '16 at 12:31
  • @andlrc what does `` mean? – fedorqui Jun 02 '16 at 12:53
  • @LittleNooby what I later on thought on is to use a variable for the file, since this is expanded within double quotes: `file="README.md"; git add "$file"; git commit -m "Something done in $file"`. – fedorqui Jun 02 '16 at 12:54
  • @StefanHegny the `git commit -m "Modified "RE` approach doesn't work to me :/ I need to add a space after the last `"` and then I enter in the backspace orgia again. – fedorqui Jun 02 '16 at 13:20
  • When you install `git` a set of functions are installed into a directory that can be used by the common `bash-completion` package (if it is installed). If you are using this package, you could try modifying one of those functions. – Anthony Geoghegan Jun 02 '16 at 13:52
  • Oops hadn't tried it actually, sorry – Stefan Hegny Jun 02 '16 at 14:20
  • 1
    M-b is backward-word; M aka meta is commonly alt or, on really old systems Esc. – tripleee Jun 02 '16 at 14:25
  • @tripleee ah right, now I see [Commands For Moving in the Bash reference manual](https://www.gnu.org/software/bash/manual/html_node/Commands-For-Moving.html). For this I do ` + `. – fedorqui Jun 02 '16 at 14:30
  • @tripleee Or with i3 where is bound to other stuff. aka ftw :-) – Andreas Louv Jun 02 '16 at 21:13
  • Yeah, I use Esc just because of habit. There was a trme when I used Emacs over a genuine VT220 every day. But I was beginning to think I was alone in the world. – tripleee Jun 03 '16 at 03:44

0 Answers0