Skip to content

Instantly share code, notes, and snippets.

View robCrawford's full-sized avatar

Rob Crawford robCrawford

View GitHub Profile
#!/usr/bin/env zsh
# Replace strings in a source file from an array of replacements
# The output file is named with `-edit` appended e.g. `src-edit.txt`
# Example:
# `replace-array src.txt replacements.sh --verbose`
# - The first file is the source
# - The second file defines single and global replacement arrays e.g.
# ```
# #!/usr/bin/env zsh
#!/usr/bin/env zsh
chrome-e2e() {
# Opens Chrome with web security turned off
# `$1` is the url to visit on launch
# `$2` is optional Chrome app name override e.g. Chromium
browser="${2:-Google Chrome}"
set -x
open -n -a "$browser" "$1" --args --ignore-certificate-errors --ignore-urlfetcher-cert-requests --disable-web-security --allow-insecure-localhost --user-data-dir=/tmp/chrome
}
@robCrawford
robCrawford / wip.sh
Last active October 18, 2022 09:40
Open modified and new files in working directory using VSCode
#!/usr/bin/env zsh
# Opens modified and new files in working directory using VSCode
wip() {
cd $(git rev-parse --show-toplevel) &&
code $(git diff $1 $2 --diff-filter=d --name-only) $(git status -s | grep '??' | grep -v '/$' | cut -c 4-) &&
cd -;
}
# Opens modified and new files in the previous commit using VSCode
@robCrawford
robCrawford / cp-dep.sh
Last active October 16, 2020 12:56
Copies a directory from the current package into node_modules of a parent package
cp-dep() {
# Copy directory named $1 in current package to node_modules of package named $2
# e.g. `cp-dep lib my-parent-app`
cd $(git rev-parse --show-toplevel)
package=$(node -p -e "require('./package.json').name")
dependency="$(cd .. && pwd)/$2/node_modules/$package"
to="$dependency/$1"
if [ -d $1 ] && [ -d $dependency ]; then
rm -rf $to && cp -r $1 $to
echo "Copied '$1' to '$to'"
@robCrawford
robCrawford / code-pr.sh
Last active May 10, 2022 09:01
Open a PR in VS Code
# Loads a feature branch as unstaged changes to master (or `$2`) and opens the files in VS Code.
# Usage: `code-pr feature-branch`
# Does not run if working directory is not clean.
# `code-pr -r` resets working directory and returns to previous branch/directory
code-pr() {
base="${2:-master}"
if [ "$1" = "-r" ]; then
code-pr-r
else