A Bash Completion Tip
October 25th, 2007 mysurface Posted in Bash, complete | Hits: 24969 | 4 Comments »
Bash Completion is a powerful CLI magic for bash user, it allows users to hit tabs and have auto completions on command lines. If you have no idea what is bash completion, check out CLI magic: programmable bash completion.
One of the features bash completion gives you is to hide the unknown file format from tab completions. For example, If I want to untar something, I type
tar -zxvf (tab)(tab)
I do not expect to see others file listed besides those files with file extension .tar.gz. Therefore, bash completion intelligently filter it off. So what is the tip I wanna share here?
What if I want a command to list some specific file extension which by default it doesn’t? Ok, here I give you an example. I have kaffeine to play video files. I like to trigger kaffeine from terminal, so that I can browse the files and play it instantly.
By default, bash completion on kaffeine does not support .flv ( flash video file format which downloads from youtube.com ). So, how am I suppose to add flv into kaffeine bash completion?
sudo vi /etc/bash_completion
Edit /etc/bash_completion , it doesn’t matter what editor you use, as long as you can search “kaffeine”.
The line will looks as below, with changes in bold.
complete -f -X '!*.@(mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|vcd|ps|pes|fli|flv|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp3|MP3|ogg|OGG|ogm|OGM|mp4|MP4|wav|WAV|asx|ASX|mng|MNG|srt)' xine aaxine fbxine kaffeine
Restart my terminal, and now bash completion on kaffeine supports .flv.







October 25th, 2007 at 3:40 am
sweet tip man :)
I have been using bash completion for awhile. life saver ;)
April 14th, 2008 at 3:27 am
however, on the next update /etc/bash_completion will be overwritten and you’ll lose all your changes. Therefore it is better to make all the custom changes in ~/.bash_completion
April 14th, 2008 at 8:18 am
aten: emm.. you are right, but I have tried to copy /etc/bash_completion to ~/.bash_completion, I make the changes in ~/.bash_completion, when I restart my terminal, it doesn’t work.
April 29th, 2011 at 7:58 pm
My wife and i have been really lucky that Raymond managed to do his investigations through the entire ideas he received while using the web site. It is now and again perplexing to simply happen to be giving out secrets and techniques which the others might have been trying to sell. So we take into account we’ve got the website owner to give thanks to for that. Most of the illustrations you made, the easy blog menu, the friendships you assist to foster – it’s all awesome, and it is assisting our son in addition to us consider that this article is amusing, and that is wonderfully fundamental. Thank you for everything!