aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-01 02:05:44 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-01 02:05:44 +1300
commit8f84b03390c5ecd25a8e693d011283ee67a4a609 (patch)
treed71ac9f1ecfd7fa2286c4b100a2076ab2b9d29b2
parentd7f8465d51306c2e1539117e0d7f1dc066bbe1e3 (diff)
downloaddotfiles-8f84b03390c5ecd25a8e693d011283ee67a4a609.tar.gz
dotfiles-8f84b03390c5ecd25a8e693d011283ee67a4a609.zip
Overhaul text filename generation
-rw-r--r--bash/bash_completion.d/_text_filenames.bash189
1 files changed, 132 insertions, 57 deletions
diff --git a/bash/bash_completion.d/_text_filenames.bash b/bash/bash_completion.d/_text_filenames.bash
index a9d767b7..52bb80a1 100644
--- a/bash/bash_completion.d/_text_filenames.bash
+++ b/bash/bash_completion.d/_text_filenames.bash
@@ -14,11 +14,8 @@ _text_filenames() {
# Exclude blanks
[[ -n $item ]] || continue
- # Accept directories
- if [[ -d $item ]] ; then
- COMPREPLY[${#COMPREPLY[@]}]=$item
- continue
- fi
+ # Exclude nonexistent (some sort of error)
+ [[ -e $item ]] || continue
# Exclude files with block, character, pipe, or socket type
[[ ! -b $item ]] || continue
@@ -26,59 +23,137 @@ _text_filenames() {
[[ ! -p $item ]] || continue
[[ ! -S $item ]] || continue
- # Check the filename extension to know what to exclude
- case $item in
-
- # Binary image file formats
- *.bmp|*.gif|*.ico|*.jpeg|*.jpg|*.png|*.tif|*.xcf) ;;
- *.BMP|*.GIF|*.ICO|*.JPEG|*.JPG|*.PNG|*.TIF|*.XCF) ;;
-
- # Video file formats
- *.avi|*.gifv|*.mkv|*.mov|*.mpg|*.rm|*.webm) ;;
- *.AVI|*.GIFV|*.MKV|*.MOV|*.MPG|*.RM|*.WEBM) ;;
-
- # Lossy audio file formats
- *.au|*.m4a|*.mp[34]|*.ogg|*.snd|*.wma) ;;
- *.AU|*.M4A|*.MP[34]|*.OGG|*.SND|*.WMA) ;;
-
- # Lossless/source audio file formats
- *.aup|*.flac|*.mid|*.h2song|*.nwc|*.s3m|*.wav) ;;
- *.AUP|*.FLAC|*.MID|*.H2SONG|*.NWC|*.S3M|*.WAV) ;;
-
- # Compressed/archived file formats
- *.cab|*.deb|*.lzm|*.pack|*.tar|*.tar.bz2|*.tar.gz|*.tar.xz|*.zip) ;;
- *.CAB|*.DEB|*.LZM|*.PACK|*.TAR|*.TAR.BZ2|*.TAR.GZ|*.TAR.XZ|*.ZIP) ;;
-
- # Document formats
- # (Not .doc, it's a plaintext format sometimes)
- *.cbr|*.docx|*.epub|*.odp|*.odt|*.pdf|*.xls|*.xlsx) ;;
- *.CBR|*.DOCX|*.EPUB|*.ODP|*.ODT|*.PDF|*.XLS|*.XLSX) ;;
-
- # Filesystems/disk images
- *.bin|*.cue|*.hdf|*.img|*.iso|*.mdf|*.raw) ;;
- *.BIN|*.CUE|*.HDF|*.IMG|*.ISO|*.MDF|*.RAW) ;;
-
- # Font files
- *.ttf) ;;
- *.TTF) ;;
-
- # Index file formats
- *.idx) ;;
- *.IDX) ;;
-
- # Encrypted file formats
- *.gpg) ;;
- *.GPG) ;;
-
- # Other 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|*.drv|*.exe|*.o|*.torrent|*.wad|*.rom) ;;
- *.A|*.DRV|*.EXE|*.O|*.TORRENT|*.WAD|*.ROM) ;;
+ # Accept directories
+ if [[ -d $item ]] ; then
+ COMPREPLY[${#COMPREPLY[@]}]=$item
+ continue
+ fi
- # Complete everything else; some of it will still be binary
- *) COMPREPLY[${#COMPREPLY[@]}]=$item ;;
+ # Check the filename extension to know what to exclude
+ (
+ # Case-insensitive matching available since 3.1-alpha
+ shopt -qs nocasematch 2>/dev/null
+
+ # Match against known binary patterns
+ case $item in
+
+ # Archives
+ (*.7z) ;;
+ (*.bz2) ;;
+ (*.gz) ;;
+ (*.jar) ;;
+ (*.rar) ;;
+ (*.tar) ;;
+ (*.xz) ;;
+ (*.zip) ;;
+
+ # Bytecode
+ (*.class) ;;
+ (*.pyc) ;;
+
+ # Databases
+ (*.db) ;;
+ (*.dbm) ;;
+ (*.sdbm) ;;
+ (*.sqlite) ;;
+
+ # Disk
+ (*.adf) ;;
+ (*.bin) ;;
+ (*.hdf) ;;
+ (*.iso) ;;
+
+ # Documents
+ (*.docx) ;;
+ (*.djvu) ;;
+ (*.odp) ;;
+ (*.ods) ;;
+ (*.odt) ;;
+ (*.pdf) ;;
+ (*.ppt) ;;
+ (*.xls) ;;
+ (*.xlsx) ;;
+
+ # Encrypted
+ (*.asc) ;;
+ (*.gpg) ;;
+
+ # Executables
+ (*.exe) ;;
+
+ # Fonts
+ (*.ttf) ;;
+
+ # Images
+ (*.bmp) ;;
+ (*.gd2) ;;
+ (*.gif) ;;
+ (*.ico) ;;
+ (*.jpeg) ;;
+ (*.jpg) ;;
+ (*.pbm) ;;
+ (*.png) ;;
+ (*.psd) ;;
+ (*.tga) ;;
+ (*.xbm) ;;
+ (*.xcf) ;;
+ (*.xpm) ;;
+
+ # Incomplete
+ (*.filepart) ;;
+
+ # Objects
+ (*.a) ;;
+ (*.o) ;;
+
+ # Sound
+ (*.au) ;;
+ (*.aup) ;;
+ (*.flac) ;;
+ (*.mid) ;;
+ (*.m4a) ;;
+ (*.mp3) ;;
+ (*.ogg) ;;
+ (*.opus) ;;
+ (*.s3m) ;;
+ (*.wav) ;;
+
+ # System-specific
+ (.DS_Store) ;;
+
+ # Translation
+ (*.gmo) ;;
+
+ # Version control
+ (.git) ;;
+ (.hg) ;;
+ (.svn) ;;
+
+ # Video
+ (*.avi) ;;
+ (*.gifv) ;;
+ (*.mp4) ;;
+ (*.ogv) ;;
+ (*.rm) ;;
+ (*.swf) ;;
+ (*.webm) ;;
+
+ # Vim
+ (*~) ;;
+ (*.swp) ;;
+
+ # Not binary that we can tell; maybe editable
+ (*) exit 0 ;;
+
+ esac
+
+ # Known usually-binary extension; flag failure
+ exit 1
+
+ ) || continue
+
+ # Complete everything else; some of it will still be binary
+ COMPREPLY[${#COMPREPLY[@]}]=$item
- esac
done < <(compgen -A file -- "${COMP_WORDS[COMP_CWORD]}")
}