5

In trying to make Bash for OSX TAB-Auto-Completion to be Case-insensitive, I followed a suggestion to run these commands:

shopt -s nocaseglob
bind 'set completion-ignore-case on'

How do I restore the above settings to the OS X default?

3 Answers 3

2

Are you saying that you added these commands in a script or in one of your dotfiles (.bash_profile, etc.), or that you simply ran the commands in the Terminal itself?

If you just ran the commands in the Terminal, simply start a new session, and the defaults should be restored. Open a new Terminal tab or Window and see if the normal functionality is restored, which it should be.

These settings should not affect the entire system unless they get automatically loaded in a file that is sourced when each session loads, in which case, you can simply remove the entry from your .bash_profile or wherever it was added in the first place.

You can double-check to see if the settings are getting automatically loaded in your .bash_profile by executing sudo -s to become root, at which point root's dotfiles get loaded, which take precedence over the previous user. If it works normally as root, go digging in your own ~/.bash_profile or ~/.bashrc and remove these commands/settings. Default functionality should be restored the next time you load a shell session.

2
+50

A first solution
To restore a situation you have to know the previous one.
The commands bind and shopt are so cosy that among the few options they present, there is one (-p for the first and -v for the second) that give the output in a format usable, almost directly, to restore them:

shopt -p   | grep nocaseglob               # shopt -u nocaseglob
bind  -v   | grep completion-ignore-case   # set completion-ignore-case off

The output is reported above after the # sign.
Once you know the starting value you can create a couple of alias to go in the Ignore More (IgnoreGo) and to come out (IgnoreExit) from it:

alias IgnoreGo="shopt -s nocaseglob; bind 'set completion-ignore-case on'"
alias IgnoreExit="shopt -u nocaseglob; bind 'set completion-ignore-case off'"

You can put this alias with the other of your configuration shell (typically in ~/.bash_aliases or ~/.bashrc) and use when you want. Problem is that those are blind, they will not see the actual situation of your shell.

A better solution
Just to make all this independent from your knowledge of those variable values, and a little bit more complex, you can create a function (Store) to create an alias (ReStore) to go back, whatever was the initial situation.

 Store(){ alias ReStore="$(shopt -p|grep nocaseglob); \
          bind '$(bind -v|grep completion-ignore-case)'"; }

Even this can be written in the configuration file for your shell (see above). Each time with Store you freeze the actual situation and with ReStore you re-establish the last one freezed.
Note that the \ has to be the last character of the line to split the command in a more readable format on two lines.

Note
On my system to complete a command (e.g. to navigate with cd) it is enough to give the bind 'set completion-ignore-case on' to enable the ignore case, even when nocaseglob is off. The nocaseglob on is needed for the pathname expansion. It exists even the nocasematch for the patterns. help bash to read more...

Help on the commands
The commands bind and shopt are built in of the shell. It means that to ask the manual for their use you need to use help instead of man.
To have only a human readable output you can use

shopt    | grep nocaseglob               # nocaseglob      on 
bind -V  | grep completion-ignore-case   # completion-ignore-case is set to `off'
1

As read in Bash manual # 4.3.2 The Shopt Builtin, this is the way to enable/disable shopt values:

-s → Enable (set) each optname.

-u → Disable (unset) each optname.

Similarly, you can disable the completion-ignore-case option with:

bind 'set completion-ignore-case off'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .