Skip to content

Instantly share code, notes, and snippets.

@beefjelly
Created November 6, 2019 17:06
Show Gist options
  • Save beefjelly/695615bf78de5cda4e06dfa5c9fc6224 to your computer and use it in GitHub Desktop.
Save beefjelly/695615bf78de5cda4e06dfa5c9fc6224 to your computer and use it in GitHub Desktop.
#!/bin/bash
# not shopt but in the same vein
bind 'set completion-ignore-case on'
####
# You can always try out shopt options and revert to normal state
# Also useful for scripting, to avoid unintended side effects
SHOPT_SETTING=""
SHOPT_SETTING_ORIGINAL=$(shopt -p ${SHOPT_SETTING})
shopt -s ${SHOPT_SETTING}
## The setting is now enabled ##
shopt -u ${SHOPT_SETTING}
## The setting is now disabled ##
eval ${SHOPT_SETTING_ORIGINAL}
## The setting is now back to its original state ##
####
#### useful for .bashrc
shopt -s autocd
# A command that is a directory is treated as a cd argument
# $ /tmp -> $ cd /tmp
shopt -s cdable_vars
# cd to a directory stored in a variable
# $ t="/tmp"; cd $t -> $ t="/tmp"; cd t
shopt -s cdspell
# Ignore minor errors in spelling of directories
# $ cd /vaar: No such file or directory -> $ cd /vaar: /var
shopt -s dirspell
shopt -s direxpand
# When using TAB for word expansion, minor spelling errors are ignored.
# $ /tamp/ <TAB>: nothing -> $ /tamp/ <TAB>: /tmp/
#### Useful for scripting
shopt -s globstar
# `**` matches all files, directories, and subdirectories
# `**/` matches only directories and subdirectories
shopt -s globasciiranges
# Use C locale for comparisons in regex [ranges]
shopt -s dotglob
# Match dotfiles and dotdirs in expansion
shopt -s extglob
# Use regex in pattern matching
shopt -s nullglob
# non-matching patterns are treated as null, rather than a literal string
# $ ls *: No such file or directory -> $ ls *: total 0
shopt -s nocaseglob
shopt -s nocasematch
# Case insensitive expansion/matching
# The distinction is pretty in-the-weeds, so usually set both
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment