lib/dots/functions.zsh in zsh_dots-0.5.7 vs lib/dots/functions.zsh in zsh_dots-0.5.8
- old
+ new
@@ -88,5 +88,46 @@
# Source a hidden configuration file, usually with the same name as
# the file it's in, but we set it here explicitly.
function hidden_config_for() {
source "$DOTS/config/$1.zsh"
}
+
+# Find and replace in a directory.
+gg_replace() {
+ if [[ "$#" == "0" ]]; then
+ echo 'Usage:'
+ echo ' gg_replace term replacement file_mask'
+ echo
+ echo 'Example:'
+ echo ' gg_replace cappuchino cappuccino *.html'
+ echo
+ else
+ find=$1; shift
+ replace=$1; shift
+
+ ORIG_GLOBIGNORE=$GLOBIGNORE
+ GLOBIGNORE=*.*
+
+ if [[ "$#" = "0" ]]; then
+ set -- ' ' $@
+ fi
+
+ while [[ "$#" -gt "0" ]]; do
+ for file in `git grep -l $find -- $1`; do
+ sed -i -e "s/$find/$replace/g" -i'' $file
+ done
+ shift
+ done
+
+ GLOBIGNORE=$ORIG_GLOBIGNORE
+ fi
+}
+
+# Turn underscores into dashes.
+gg_dasherize() {
+ gg_replace $1 `echo $1 | sed -e 's/_/-/g'` $2
+}
+
+# Wrap a Ruby binary in the global GEM_HOME.
+function globalize() {
+ GEM_HOME=$GLOBAL_GEM_HOME $@
+}