nv://make/?title=Bash%20completion%20for%20defaults%20domains&txt=%5BSource%5D%28http%3A%2F%2Fbrettterpstra.com%2F2012%2F06%2F16%2Fbash-completion-for-defaults-domains%2F%20%22Permalink%20to%20Bash%20completion%20for%20defaults%20domains%22%29%0A%0A%23%20Bash%20completion%20for%20defaults%20domains%0A%0AThere%20are%20a%20lot%20of%20things%20you%20can%20do%20with%20the%20OS%20X%20%60defaults%60%20command.%20This%20post%20isn%27t%20intended%20to%20detail%20them%2C%20but%20a%20little%20searching%20can%20turn%20up%20%5Ba%20lot%20of%20neat%20tricks%5D%5B1%5D.%20%0A%0ABasically%2C%20%60defaults%60%20reads%20and%20writes%20system%20and%20application%20preferences%20from%20the%20command%20line.%20Using%20it%20requires%20knowing%20the%20%22domain%22%20of%20the%20preference%20file%20%28e.g.%20%22com.apple.Safari%22%29%2C%20or%20using%20the%20%22-app%22%20parameter.%20I%20generally%20stick%20with%20the%20domain%2C%20especially%20when%20I%27m%20writing%20or%20deleting%20preferences%2C%20just%20to%20make%20sure%20I%27m%20doing%20it%20where%20I%20think%20I%27m%20doing%20it.%0A%0AThis%20code%E2%80%93when%20added%20to%20your%20%60~%2F.bash_profile%60%E2%80%93will%20allow%20tab%20completion%20of%20domain%20names.%20You%20can%20type%20%60defaults%20read%20com.brett%3Ctab%3E%60%20to%20see%20any%20preference%20files%20in%20a%20domain%20starting%20with%20%22com.brett%22%20%28which%20would%20bring%20up%20Marked%27s%20preferences%29.%20It%27s%20not%20overly%20complex%20and%20doesn%27t%20do%20any%20handling%20of%20the%20command%20type%20%28read%2C%20write%2C%20delete%2C%20etc.%29%2C%20but%20it%27s%20handy%20if%20you%20toy%20with%20preferences%20much%3A%0A%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20%23%23%20Bash%20completion%20for%20%60defaults%60%20domains%0A%20%20%20%20%23%23%20e.g.%20%60defaults%20read%20com.apple%5BTAB%5D%60%0A%20%20%20%20%0A%20%20%20%20_complete_domain%20%28%29%0A%20%20%20%20%7B%0A%20%20%20%20%09local%20cur%0A%20%20%20%20%09local%20LC_ALL%3D%27C%27%0A%20%20%20%20%09cur%3D%24%7BCOMP_WORDS%5BCOMP_CWORD%5D%7D%0A%20%20%20%20%09cur%3D%24%7Bcur%2F%2F.%2F%5C.%7D%20%23%20escape%20dots%20for%20grep%0A%20%20%20%20%09local%20IFS%3D%22%0A%20%20%20%20%22%0A%20%20%20%20%09COMPREPLY%3D%28%20%24%28defaults%20domains%20%7C%20tr%20%27%2C%27%20%27n%27%20%7C%20sed%20%27s%2F%5E%5B%20t%5D%2A%2F%2F%3Bs%2F%5B%20t%5D%2A%24%2F%2F%27%7Cgrep%20-i%20%22%5E%24cur%22%29%20%29%0A%20%20%20%20%09return%200%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20complete%20-o%20bashdefault%20-o%20default%20-o%20nospace%20-F%20_complete_domain%20defaults%202%3E%2Fdev%2Fnull%20%7C%7C%20complete%20-o%20default%20-o%20nospace%20-F%20_complete_domain%20defaults%0A%20%20%20%20%0A%0AIf%20you%20want%20to%20complete%20on%20the%20%22app%22%20parameter%2C%20you%20could%20add%20a%20check%20for%20%22-app%22%20as%20the%20previous%20item%20in%20the%20sequence%20and%20include%20something%20along%20the%20lines%20of%20the%20%5Bapplication%20completions%5D%5B2%5D%20I%20posted%20a%20while%20back.%0A%0AYou%20may%20commence%20deriding%20me%20for%20not%20using%20zsh%20now.%0A%0AAlso%2C%20shortly%20after%20figuring%20this%20out%20I%20found%20the%20%5Bdefaults%20completion%20plugin%20in%20bash-it%5D%5B3%5D.%20It%27s%20better.%0A%0A%5B1%5D%3A%20https%3A%2F%2Fgithub.com%2Fmathiasbynens%2Fdotfiles%2Fblob%2Fmaster%2F.osx%0A%5B2%5D%3A%20http%3A%2F%2Fbrettterpstra.com%2Fshare%2Fapp_completions%0A%5B3%5D%3A%20https%3A%2F%2Fgithub.com%2Frevans%2Fbash-it%2Fblob%2Fmaster%2Fcompletion%2Favailable%2Fdefaults.completion.bash%0A%0A&tags=