Developer notes.
To set the title of a terminal tab,
$ echo -n -e "\033]0;{{title}}\007"To package as a command-line tool, add the following to the platform-specific configuration file for configuring user environments (e.g., .bash_profile, .profile, .bashrc.
tab() {
echo -n -e "\033]0;$*\007"
}which can then be invoked
$ tab titleTo generate a directory tree,
$ ls -R ./root/directory | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/--/|/'where
-R: recursively list subdirectories.s/[^-][^\/]*\//--/g: replace directory path segments with--.s/^/ /: indent.s/--/|/: replace the first--with a vertical bar.
To list changes without context,
$ git diff -U0 | grep '^[+-]' | grep -Ev '^(--- a/|\+\+\+ b/)'which selects for all lines beginning with either a + or - character and then removes lines listing the filename.
To search all commits for a particular string,
$ git rev-list --all | xargs git grep -F 'string'where -F indicates to search for a fixed string. To search using a regular expression, use -P (see git grep --help).
To exclude paths when using find, use membership inversion
$ find -type f -name foo.txt -regextype posix-extended -regex '.*/foo/([^b]+|(b([^a]|$)|ba([^r]|$)))+/.*'Note that, when passing the above regular expression through Make, the $ symbol needs to be escaped (e.g., $$).
To perform a multi-file find and replace,
$ perl -pi -w -e 's/search/replace/g;' $(find ./search/directory -type f)where
-e: execute the command-w: write warnings-p: execute for each file-i: edit in-place
If you encounter an error due to too many arguments, use xargs.
$ find ./search/directory -type f | xargs perl -pi -w -e 's/search/replace/g;'If running a search from the top-level directory, be sure to exclude any hidden directories (including .git), the top-level node_modules directory, and the ./deps directory from the search. This may require using absolute file paths.
$ find "$PWD" -type f '!' -path "$PWD/.*" '!' -path "$PWD/deps/*" '!' -path "$PWD/node_modules/*" | xargs perl -pi -w -e 's/search/replace/g;'A few comments:
- For simple cases,
sedmay be faster. - Be very careful when performing a multi-file find and in-place replace. Perform dry-runs and confirm expected results on a small file subset before performing on many files. You have been warned.
To move directories from one directory to another directory,
$ find $PWD/path/to/parent/directory -type d -depth 1 -regex ".*" | while read -r dir; do mv "${dir}" "$PWD/path/to/parent/destination/directory/$(basename ${dir})"; doneTo rename multiple directories using a pattern,
$ find $PWD/path/to/parent/directory -type d -depth 1 -regex ".*" | while read -r dir; do mv "${dir}" "$PWD/path/to/parent/destination/directory/`echo $(basename ${dir}) | sed s/search/replace/`"; done