You can achieve what you want by modifying the bash-completion for the cat command.
Here's a bash function that does what you want:
Code:
$ cat cat_no_dir
_cat_no_dirs ()
{
COMPREPLY=()
cur=($(compgen -o plusdirs -f -- "${COMP_WORDS[COMP_CWORD]}"))
for ((i=0; i < ${#cur[@]}; i++)); do
[ -d "${cur[$i]}" ] && continue
COMPREPLY+=(${cur[$i]})
done
return 0
}
complete -F _cat_no_dirs cat
A test:
Code:
$ ls -lgG
-rw-r--r-- 1 377 Apr 6 18:19 cat_no_dir
drwxr-xr-x 2 4096 Apr 6 18:32 dir_1
drwxr-xr-x 2 4096 Apr 6 18:32 dir_2
drwxr-xr-x 2 4096 Apr 6 18:32 dir_3
-rw-r--r-- 1 0 Apr 6 18:32 file_1
-rw-r--r-- 1 0 Apr 6 18:32 file_2
-rw-r--r-- 1 0 Apr 6 18:32 file_3
$ source cat_no_dir
$ cat # tab tab
cat_no_dir file_1 file_2 file_3
If you want this action to be permanent copy the file containing the function (cat_no_dir) to "/etc/bash_completion.d" and it will be sourced when you start a shell. For occasional use just source the file as I did here.
Bookmarks