Find & Replace within an Entire Directory or Git Repo with sed
If replacing within a directory:
grep -rl 'apples' /dir_to_search_under | xargs sed -i 's/apples/oranges/g'Or, within an entire git repository:
| /** | |
| * Safety detection for passive support | |
| * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support | |
| */ | |
| initPassiveSupport = (): boolean => { | |
| let supported = false; | |
| let options = {}; | |
| try { |
| /** In case your linter gives you a problem attempting to register listeners to `testEvent` */ | |
| declare global { | |
| interface WindowEventMap { | |
| testEvent: CustomEvent<{ event: any, options: any }>; | |
| } | |
| } | |
| /** Inspired by: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support */ | |
| export const isPassiveSupported = () => { | |
| let passiveSupported = false; |
| let x = 30.039853244; | |
| Number(Math.round(x + 'e2') + 'e-2); // 30.04 | |
| const round = (num, digits) => { | |
| return Number(Math.round(num + 'e' + digits) + 'e-' + digits); | |
| } | |
| let y = 3.141592653589793238; | |
| round(y, 3); // 3.142 |
| <cfscript> | |
| public string function getRandomPassword(numeric length=10, string charSet='special') { | |
| var charLower = 'a|c|e|g|i|k|m|o|q|s|u|w|y|b|d|f|h|j|l|n|p|r|t|v|x|z' | |
| var charUpper = 'A|C|E|G|I|K|M|O|Q|S|U|W|Y|B|D|F|H|J|L|N|P|R|T|V|X|Z'; | |
| var charNumbers = '0|2|4|6|8|9|7|5|3|1'; | |
| var charSpecial = "@|!|$|%|^|&|+|=|,'"; | |
| var charList = ''; | |
| var thisChar = ''; | |
| var randomPassword = ''; | |
| git log --graph --decorate --pretty=oneline --abbrev-commit |
If replacing within a directory:
grep -rl 'apples' /dir_to_search_under | xargs sed -i 's/apples/oranges/g'Or, within an entire git repository:
| <script> | |
| function execPolyfill() { | |
| (function(){ | |
| // CustomElementsV1.min.js v1 polyfill from https://github.com/webcomponents/webcomponentsjs/tree/v1/src/CustomElements/v1. | |
| /* | |
| Copyright (c) 2016 The Polymer Project Authors. All rights reserved. | |
| This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | |
| The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| compare(a: number, b: number): number { | |
| return a > b | |
| ? 1 | |
| : a < b | |
| ? -1 | |
| : 0; | |
| } |
| // arbitrary js object: | |
| var myJsObj = {a:'foo', 'b':'bar', c:[false,2,null, 'null']}; | |
| // using JSON.stringify pretty print capability: | |
| var str = JSON.stringify(myJsObj, undefined, 4); | |
| // Kudos: <https://stackoverflow.com/questions/26320525/prettify-json-data-in-textarea-input/26324037> |