Skip to content

This is a collection of reusable scripts, functions and aliases related to development.

License

Notifications You must be signed in to change notification settings

ali-kamalizade/scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 

Repository files navigation

Utilities to make my (and your?) life easier

This is a collection of reusable scripts, functions and aliases related to software development.

Bash & Zsh

Open .bash_profile in Visual Studio Code

alias edit-bash-profile="code ~/.bash_profile"

Apply changes made in .bash_profile without restarting your terminal

alias refresh-bash="source ~/.bash_profile"

Open .zshrc in Visual Studio Code

alias edit-zsh='code ~/.zshrc'

Apply changes made in .zshrc without restarting your terminal

alias refresh-zsh='source ~/.zshrc'

View pretty-printed JSON response using fx

curl_json_pretty() {
    curl $1 | npx fx .
}

Work with JSON response using fx

curl_json() {
    curl $1 | npx fx
}

Execute a command multiple times

run_multiple_times() {
  echo "Executing" "the following command" $1 "times:" $2
  for i in $(seq 1 $1);
    do $2;
  done;
}

Shortcut for home directory

alias home="cd ~"

Say please and you shall receive

alias please="sudo"

Rerun last command

alias rerun="!!"

Use rainbow

run_with_rainbow() {
    $1 | npx lolcatjs
}

Highlight syntax of a file

highlight_syntax() {
    npx cli-highlight $1
}

JavaScript

List globally installed NPM packages

alias npm-global-packages="npm list -g --depth 0"

Run security audit for Node projects (omit --production to consider devDependencies as well)

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 a local HTTP server

run_http_server() {
  echo "Running HTTP server on port" $1 ". Serving the following directory:" $2
  npx http-server -p $1 -c-1 $2
}

Start Cypress test runner

open_cypress() {
    npx cypress open $1
}

Determine download stats for all the NPM packages by user

get_npm_download_stats() {
    npx https://gist.github.com/kentcdodds/8eea6d7365f46ddd2f2760bb44d164c0 $1
}

Start server, test and terminate

start_server_and_test() {
    npx start-server-and-test $1 $2 $3
}

Invoke Angular CLI / nx.dev CLI if you don't have them installed globally

alias ng="npx ng"
alias nx="npx nx"

Update Angular to latest version

ng_update_to_latest() {
    ng update @angular/cli --allow-dirty
    ng update @angular/core --allow-dirty
    ng update @angular/cdk --allow-dirty 
}

Run accessibility tests on a provided page

test_website_a11y() {
    npx pa11y $1
}

Format files using Prettier (must be installed in the current directory)

alias browserslist="prettier --write ."

Run ESLint and check which rules take the longest

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"
} 

Clear cache in node_modules

alias clear_node_modules_cache="rm -rf node_modules/.cache"

Jest

Clear cache of Jest test runner

alias jest-clear-cache="npx jest --clearCache"

Debug issues when using Jest test runner (e.g. when Jest is stuck and not logging the root issue)

alias jest-debug='npx jest --detectOpenHandles'

Start Jest in watch mode

alias jest-watch="npx jest --watch"

Open Jest coverage report (run tests with --coverage)

open_jest_coverage_report() {
    open ./coverage/lcov-report/index.html
}

TypeScript

Find unused exports in your source files (+ ignore exceptions)

alias ts-dead-code="npx ts-prune -p ./tsconfig.json | grep -v 'jest.config'"

Generate a tsconfig.json file

alias ts-init="npx tsc --init"

Execute TypeScript code using ts-node

alias ts-node="npx ts-node"

Compile TypeScript

compile_typescript() {
  echo "Compiling TypeScript using the following configuration file:" $1
  npx tsc -p $1
}

Git

Stash single file

alias git-stash-single-file="git stash push "

Print current branch name

alias git-branch-name='git rev-parse --abbrev-ref HEAD'

Remove committed file from Git version control but keep it locally

git_remove() {
    "Removing the following file from version control (it's still available locally: " $1
    git rm --cached $1
}

Amend staged files

alias git-amend='git commit --amend'

Undo last commit while keeping the changes

alias git-undo-last-commit='git reset --soft HEAD~1'

Revert all local changes

alias git-revert-changes='git fetch --prune && git reset --hard'

Checkout previous branch

alias git-previous-branch='git checkout -'

Show contributors sorted by commits

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'

Utilities & Miscellaneous

Count lines of code

sloc() {
  npx sloc -f cli-table $1
}

Kill process running on a specific port

kill_process_by_port() {
  lsof -i TCP:$1 | grep LISTEN | awk '{print $2}' | xargs kill -9
  echo "Port" $1 "found and killed."
}

Convert a post on Medium.com to a Markdown document

medium_post_to_markdown() {
    cd ~/Desktop
    npx mediumexporter "$1" > medium_post.md
}

Execute a JAR file

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'

About

This is a collection of reusable scripts, functions and aliases related to development.

Topics

Resources

License

Stars

Watchers

Forks