This is a collection of reusable scripts, functions and aliases related to software development.
alias edit-bash-profile="code ~/.bash_profile"
alias refresh-bash="source ~/.bash_profile"
alias edit-zsh='code ~/.zshrc'
alias refresh-zsh='source ~/.zshrc'
curl_json_pretty() {
curl $1 | npx fx .
}
curl_json() {
curl $1 | npx fx
}
run_multiple_times() {
echo "Executing" "the following command" $1 "times:" $2
for i in $(seq 1 $1);
do $2;
done;
}
alias home="cd ~"
alias please="sudo"
alias rerun="!!"
run_with_rainbow() {
$1 | npx lolcatjs
}
highlight_syntax() {
npx cli-highlight $1
}
alias npm-global-packages="npm list -g --depth 0"
alias npm-audit-prod="npm audit --production"
Find unused NPM dependencies using depcheck
alias npm-depcheck="$ npx depcheck"
Check JavaScript bundles for ES5 compatibility using es-check
check_es_bundles() {
echo "Checking bundles in" $1 "for ES5 compatibility."
npx es-check es5 $1 --verbose
}
Find publicly known security vulnerabilities in a GitHub project using Snyk (provide URL)
run_snyk_github_project_check() {
echo "Running Snyk check for GitHub project:" $1
npx snyk test $1
}
Find publicly known security vulnerabilities in a website's frontend JavaScript libraries using Snyk
run_snyk_website_check() {
echo "Running Snyk check for website:" $1
npx is-website-vulnerable $1
}
run_http_server() {
echo "Running HTTP server on port" $1 ". Serving the following directory:" $2
npx http-server -p $1 -c-1 $2
}
open_cypress() {
npx cypress open $1
}
get_npm_download_stats() {
npx https://gist.github.com/kentcdodds/8eea6d7365f46ddd2f2760bb44d164c0 $1
}
start_server_and_test() {
npx start-server-and-test $1 $2 $3
}
alias ng="npx ng"
alias nx="npx nx"
ng_update_to_latest() {
ng update @angular/cli --allow-dirty
ng update @angular/core --allow-dirty
ng update @angular/cdk --allow-dirty
}
test_website_a11y() {
npx pa11y $1
}
Format files using Prettier (must be installed in the current directory)
alias browserslist="prettier --write ."
eslint_with_timing() {
TIMING=1 eslint $1
}
List browsers which are supported by your project (needs a browerslist file)
alias browserslist="npx browserslist"
Set the provided Node version as default using nvm
nvm_set_default_version() {
echo "Set the following version as default:" $1
nvm alias default $1
}
Use Node version based on .node-version
file in a repository using nvm
nvm-project-node-version(){
value=$(<.node-version)
nvm use "$value"
}
alias clear_node_modules_cache="rm -rf node_modules/.cache"
alias jest-clear-cache="npx jest --clearCache"
alias jest-debug='npx jest --detectOpenHandles'
alias jest-watch="npx jest --watch"
open_jest_coverage_report() {
open ./coverage/lcov-report/index.html
}
alias ts-dead-code="npx ts-prune -p ./tsconfig.json | grep -v 'jest.config'"
alias ts-init="npx tsc --init"
alias ts-node="npx ts-node"
compile_typescript() {
echo "Compiling TypeScript using the following configuration file:" $1
npx tsc -p $1
}
alias git-stash-single-file="git stash push "
alias git-branch-name='git rev-parse --abbrev-ref HEAD'
git_remove() {
"Removing the following file from version control (it's still available locally: " $1
git rm --cached $1
}
alias git-amend='git commit --amend'
alias git-undo-last-commit='git reset --soft HEAD~1'
alias git-revert-changes='git fetch --prune && git reset --hard'
alias git-previous-branch='git checkout -'
alias git-contributors='git shortlog -sn --all'
Push with force to repository but do not overwrite changes on the remote branch which you don't have locally yet (see here)
alias git-safe-force-push='git push --force-with-lease'
sloc() {
npx sloc -f cli-table $1
}
kill_process_by_port() {
lsof -i TCP:$1 | grep LISTEN | awk '{print $2}' | xargs kill -9
echo "Port" $1 "found and killed."
}
medium_post_to_markdown() {
cd ~/Desktop
npx mediumexporter "$1" > medium_post.md
}
run_jar() {
"Running the following JAR file: " $1
java -jar $1
}
Fix xcrun: error: invalid active developer path, missing xcrun
error (this can occur after a Mac OS update)
alias fix-macos-xcrun='xcode-select --install'