Skip to content

Commit b93ed4d

Browse files
author
Gregory Assasie
committed
Switch node version automatically
1 parent bc515f9 commit b93ed4d

9 files changed

Lines changed: 4128 additions & 1900 deletions

File tree

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"rules": {
99
"prettier/prettier": "error",
1010
"arrow-parens": ["error", "as-needed"],
11-
"comma-dangle": ["error", "always-multiline"],
11+
"comma-dangle": "off",
1212
"object-curly-newline": "off",
1313
"function-paren-newline": "off",
1414
"no-console": "off",

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
11.10.1
1+
13.7.0

gatsby-node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ exports.createPages = ({ graphql, actions }) => {
3737
`).then(result => {
3838
if (result.errors) {
3939
console.log(result.errors);
40-
reject(result.errors);
40+
return reject(result.errors);
4141
}
4242

4343
_.each(result.data.allMarkdownRemark.edges, edge => {
@@ -86,7 +86,7 @@ exports.createPages = ({ graphql, actions }) => {
8686
}
8787
});
8888

89-
resolve();
89+
return resolve();
9090
});
9191
});
9292
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"license": "MIT",
2626
"dependencies": {
2727
"bluebird": "^3.5.5",
28-
"gatsby": "^2.15.3",
28+
"gatsby": "2.30.2",
2929
"gatsby-plugin-catch-links": "^2.1.7",
3030
"gatsby-plugin-feed": "^2.3.11",
3131
"gatsby-plugin-google-analytics": "^2.1.13",
@@ -56,10 +56,10 @@
5656
"devDependencies": {
5757
"babel-eslint": "^10.0.3",
5858
"eslint": "^6.3.0",
59-
"eslint-config-airbnb": "^18.0.1",
59+
"eslint-config-airbnb": "18.2.1",
6060
"eslint-config-prettier": "^6.1.0",
6161
"eslint-import-resolver-alias": "1.1.2",
62-
"eslint-plugin-import": "2.18.2",
62+
"eslint-plugin-import": "2.22.1",
6363
"eslint-plugin-jsx-a11y": "^6.2.3",
6464
"eslint-plugin-module-resolver": "0.15.0",
6565
"eslint-plugin-prettier": "3.1.0",
-1.28 MB
Binary file not shown.

src/pages/articles/algorithm-intro-big-o/index.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/pages/articles/how-the-internet-works/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ path: '/posts/components-of-the-internet-and-how-it-works'
88
description: 'A high level overview of how the internet works, and the respective infrastructure that makes it all tick'
99
featuredImage: ./hero.jpg
1010
tags:
11-
- 'Software development'
11+
- 'Software Development'
1212
- 'Backend Development'
1313
---
1414

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Change node version automatically with nvm and zsh
3+
date: '2021-02-14T22:01:39.990Z'
4+
layout: post
5+
draft: false
6+
category: 'Software Development'
7+
path: '/posts/change-node-version-automatically-zsh'
8+
description: 'Change node version automatically with zsh Hook Functions when working directory changes'
9+
tags:
10+
- 'Web development'
11+
- 'Software Development'
12+
13+
---
14+
15+
I have been a zsh user for a while now, for those who do not know zsh, it is a unix shell and command language based on bash with improvements.
16+
Recently, I found myself with a very slow terminal. It took a good 3 to 5 seconds to launch a new terminal session in any directory, which got
17+
increasingly annoying. The major culprit was a bash script I nicked of stackoverflow 😅 (you know you do it too). I decided to remove that piece of
18+
code, write my own (hopefully a simple and improved version of it).
19+
20+
### Let's modify the zsh profile
21+
22+
```bash
23+
open ~/.zshrc
24+
```
25+
To begin, open your zshrc file located here `~/.zshrc` (this is platform dependent), in your favourite editor.
26+
27+
We will be tapping into zsh hook functions to make this work, specifically `chpwd`, which is executed whenever the current working directory is
28+
changed.
29+
30+
```bash
31+
chpwd_functions=(change_nvm_version)
32+
```
33+
34+
Let's define the `change_node_version` function. We first check if the file exits with the `-f` flag, it also checks that `./.nvmrc` is nothing but a
35+
file. We `cat` the file and save the content in `$version`. Lastly, switch the node version with nvm (`nvm use $version`). I will assume you
36+
have `nvm` installed, otherwise [check here](https://github.com/nvm-sh/nvm) for the installation.
37+
38+
```bash
39+
function change_node_version {
40+
nvmrc="./.nvmrc"
41+
if [ -f "$nvmrc" ]; then
42+
version="$(cat "$nvmrc")"
43+
nvm use $version
44+
fi
45+
}
46+
47+
chpwd_functions=(change_node_version)
48+
```
49+
50+
The last step is to source your zshrc profile and voila
51+
52+
```bash
53+
source ~/.zshrc
54+
```
55+
56+
---
57+
58+
This solution works for my needs and my terminal is faster again 🚀, feel free to suggest improvements. Until next time, stay curious !
59+
60+
61+
62+
63+

0 commit comments

Comments
 (0)