diff options
-rw-r--r-- | README.markdown | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/_text_filenames.bash | 61 | ||||
-rw-r--r-- | bash/bash_completion.d/awk.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/cat.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/ed.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/ex.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/grep.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/head.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/m4.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/sed.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/source.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/tail.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/vi.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/view.bash | 5 | ||||
-rw-r--r-- | bash/bash_completion.d/vim.bash | 5 |
15 files changed, 131 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown index 559244a7..66c83a55 100644 --- a/README.markdown +++ b/README.markdown @@ -237,6 +237,11 @@ files, for things I really do get tired of typing repeatedly: * `pass(1)` entries * `ssh(1)` hostnames from `~/.ssh/config` +For commands that pretty much always want to operate on text, such as text file +or stream editors, I exclude special file types and extensions I know are +binary. I don't actually read the file, so this is more of a heuristic thing, +and sometimes it will get things wrong. + I also add completions for my own scripts and functions where useful. The completions are dynamically loaded if Bash is version 4.0 or greater. Otherwise, they're all loaded on startup. diff --git a/bash/bash_completion.d/_text_filenames.bash b/bash/bash_completion.d/_text_filenames.bash new file mode 100644 index 00000000..d12dce7f --- /dev/null +++ b/bash/bash_completion.d/_text_filenames.bash @@ -0,0 +1,61 @@ +# Exclude files by filesystem type and extension that likely aren't +# viewable/editable in plain text +# +# I've seen some very clever people figure out ways to actually read the files +# or run something like file(1) over them to make an educated guess as to +# whether they're binary or not, but I don't really want to go that far. It's +# not supposed to be perfect, just a bit more likely to complete singly with +# the thing I want, and I want it to stay fast. +# +_text_filenames() { + while IFS= read -r item ; do + + # Exclude blanks + [[ -n $item ]] || return + + # Exclude files with block, character, pipe, or socket type + [[ ! -b $item ]] || return + [[ ! -c $item ]] || return + [[ ! -p $item ]] || return + [[ ! -S $item ]] || return + + # Check the filename extension to know what to exclude + case $item in + + # Binary image file formats + *.bmp|*.gif|*.jpeg|*.jpg|*.png|*.xcf) ;; + *.BMP|*.GIF|*.JPEG|*.JPG|*.PNG|*.XCF) ;; + + # Video file formats + *.avi|*.gifv|*.mkv|*.mov|*.mpg|*.rm|*.webm) ;; + *.AVI|*.gifv|*.MKV|*.MOV|*.MPG|*.RM|*.WEBM) ;; + + # Audio file formats + *.au|*.aup|*.flac|*.mid|*.h2song|*.mp[34]|*.ogg|*.wav) ;; + *.AU|*.AUP|*.FLAC|*.MID|*.H2SONG|*.MP[34]|*.OGG|*.WAV) ;; + + # Document formats + *.cbr|*.doc|*.docx|*.odp|*.odt|*.pdf|*.xls|*.xlsx) ;; + *.CBR|*.DOC|*.DOCX|*.ODP|*.ODT|*.PDF|*.XLS|*.XLSX) ;; + + # Compressed/archived file formats + # (Yes I know Vim can read these) + *.bz2|*.deb|*.gz|*.tar|*.xz|*.zip) ;; + *.BZ2|*.DEB|*.GZ|*.TAR|*.XZ|*.ZIP) ;; + + # Known binary extensions + # (I haven't included .com; on UNIX, that's more likely to be + # something I saved from a website and named after the domain) + *.a|*.dat|*.drv|*.exe|*.o) ;; + *.A|*.DAT|*.DRV|*.EXE|*.O) ;; + + # Filesystems + *.bin|*.cue|*.img|*.iso|*.raw) ;; + *.BIN|*.CUE|*.IMG|*.ISO|*.RAW) ;; + + # Complete everything else; some of it will still be binary + *) COMPREPLY[${#COMPREPLY[@]}]=$item ;; + + esac + done < <(compgen -A file -- "${COMP_WORDS[COMP_CWORD]}") +} diff --git a/bash/bash_completion.d/awk.bash b/bash/bash_completion.d/awk.bash new file mode 100644 index 00000000..6c6f4b72 --- /dev/null +++ b/bash/bash_completion.d/awk.bash @@ -0,0 +1,5 @@ +# Completion for awk(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames awk + diff --git a/bash/bash_completion.d/cat.bash b/bash/bash_completion.d/cat.bash new file mode 100644 index 00000000..894b18ea --- /dev/null +++ b/bash/bash_completion.d/cat.bash @@ -0,0 +1,5 @@ +# Completion for cat(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames cat + diff --git a/bash/bash_completion.d/ed.bash b/bash/bash_completion.d/ed.bash new file mode 100644 index 00000000..9bc2bf59 --- /dev/null +++ b/bash/bash_completion.d/ed.bash @@ -0,0 +1,5 @@ +# Completion for ed(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames ed + diff --git a/bash/bash_completion.d/ex.bash b/bash/bash_completion.d/ex.bash new file mode 100644 index 00000000..6e2ac9fb --- /dev/null +++ b/bash/bash_completion.d/ex.bash @@ -0,0 +1,5 @@ +# Completion for ex(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames ex + diff --git a/bash/bash_completion.d/grep.bash b/bash/bash_completion.d/grep.bash new file mode 100644 index 00000000..dec9f7d3 --- /dev/null +++ b/bash/bash_completion.d/grep.bash @@ -0,0 +1,5 @@ +# Completion for grep(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames grep + diff --git a/bash/bash_completion.d/head.bash b/bash/bash_completion.d/head.bash new file mode 100644 index 00000000..65a32628 --- /dev/null +++ b/bash/bash_completion.d/head.bash @@ -0,0 +1,5 @@ +# Completion for head(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames head + diff --git a/bash/bash_completion.d/m4.bash b/bash/bash_completion.d/m4.bash new file mode 100644 index 00000000..4cf27e63 --- /dev/null +++ b/bash/bash_completion.d/m4.bash @@ -0,0 +1,5 @@ +# Completion for m4(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames m4 + diff --git a/bash/bash_completion.d/sed.bash b/bash/bash_completion.d/sed.bash new file mode 100644 index 00000000..4e27d34f --- /dev/null +++ b/bash/bash_completion.d/sed.bash @@ -0,0 +1,5 @@ +# Completion for sed(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames sed + diff --git a/bash/bash_completion.d/source.bash b/bash/bash_completion.d/source.bash new file mode 100644 index 00000000..3dba710f --- /dev/null +++ b/bash/bash_completion.d/source.bash @@ -0,0 +1,5 @@ +# Completion for source(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames source + diff --git a/bash/bash_completion.d/tail.bash b/bash/bash_completion.d/tail.bash new file mode 100644 index 00000000..e72d0d8d --- /dev/null +++ b/bash/bash_completion.d/tail.bash @@ -0,0 +1,5 @@ +# Completion for tail(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames tail + diff --git a/bash/bash_completion.d/vi.bash b/bash/bash_completion.d/vi.bash new file mode 100644 index 00000000..8e385318 --- /dev/null +++ b/bash/bash_completion.d/vi.bash @@ -0,0 +1,5 @@ +# Completion for vi(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames vi + diff --git a/bash/bash_completion.d/view.bash b/bash/bash_completion.d/view.bash new file mode 100644 index 00000000..ce381ecf --- /dev/null +++ b/bash/bash_completion.d/view.bash @@ -0,0 +1,5 @@ +# Completion for view(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames view + diff --git a/bash/bash_completion.d/vim.bash b/bash/bash_completion.d/vim.bash new file mode 100644 index 00000000..4d3355aa --- /dev/null +++ b/bash/bash_completion.d/vim.bash @@ -0,0 +1,5 @@ +# Completion for vim(1) with files that look editable +declare -F _text_filenames >/dev/null || + source "$HOME"/.bash_completion.d/_text_filenames.bash +complete -F _text_filenames -o filenames vim + |