Just one of the things I'm learning. https://github.com/hchiam/learning
A nice article on key things to know: https://www.joshwcomeau.com/javascript/terminal-for-js-devs (my own summary notes are below)
To enable running a script upon click, you need to edit permissions. For example, for chrome-incognito-shortcut.app:
chmod 744 chrome-incognito-shortcut.apphttps://github.com/hchiam/learning-powershell
https://github.com/hchiam/learning-dependency-cruiser
https://github.com/hchiam/learning-https-server
>= redirect output = "(over)write to", e.g.:echo 'hello' > file.txt<= redirect input = "read", e.g.:cat < file.txt(same as justcat file.txt)>>= append to end of file, e.g.:echo 'new last line of text' >> file.txtcat << EOF >> file.txt= "start multiline input session that ends when you typeEOFand hit Enter" (but personally,nanoseems to do this simpler)
-
git commit --amend -
git reset HEAD~1to "un-commit" -
git pull origin dev(if you want to merge commits intodevbranch into your local branch) and then type:qaand hit enter. Now you cangit push. -
git tag <name-of-tag>; git push --tags(and then you can draft a new release on the same tag name to add details to it on GitHub)
git update-index --skip-worktree your-file-to-ignore-future-revisions-for.txtgit update-index --no-skip-worktree your-file-to-start-watching-revisions-for.txt
From https://www.smashingmagazine.com/make-life-easier-when-using-git/ :
git status -sb- git hooks
- Try using git
bisectwith "binary search" automation to find the breaking change
git bisect start
git bisect good c5ba734 # if c5ba734 is a commit without the bug
git bisect bad 6c093f4 #if 6c093f4 is a commit with the bug
# run test: git bisect run ./test-bug (or: git bisect run jest)
git bisect bad # if the current commit has the bug
git bisect good # if current commit does not have the bug
# (repeats until find the first commit with the bug)
git bisect reset # or: git bisect reset HEAD (or: git bisect reset <commit-id>)git rebase -i --exec "yarn test" d294ae9 # test all commits from d294ae9 to HEAD, until hit first failing commitFrom https://dev.to/g_abud/advanced-git-reference-1o9j#git-commands :
-
git rm --cached <file-name>to stop tracking<file-name>in version control -
git diff --staged -
git diff branch1..branch2 -
git commit --amendto add more changes to the last commit -
git cherry-pick <commit-sha>to bring in a commit from a different branch -
git checkout <branch-name> <file-name>to bring in a file from a differnt branch -
git reset <commit-sha> -
git reset --hard HEAD~1= undo last commit and rewrite history (thengit push -fto push rewritten history) -
git reset --hard HEAD~n # where n is the last n commits= undo last n commit and rewrite history (thengit push -fto push rewritten history) -
git reset --hard <commit-sha>= undo comments and rewrite history (thengit push -fto push rewritten history) -
--soft= uncommit but still staged;--mixed= uncommit+unstage, but changes kept locally;--hard= uncommit+unstage+delete changes -
git stashto save your changes to top of stash stack (add-uto stash untracked files as well) -
git stash listto see what's in your stash -
git stash save "message to go along with changes" -
git stash pop
From https://www.youtube.com/watch?v=ecK3EnyGD8o :
-
git stash save nameforlater- and then later
git stash list(note the index) - and then
git stash apply <index>to use<index>
- and then later
-
git branch -M mainto rename branch to main, and thengit push -u origin main(more info) -
git log --graph --oneline --decoratefor a pared-down git log -
lots more git tips at a Fireship.io YouTube video
This shows the commit hash: (looks like l0ngStr1ng0fL3t7er5AndNum83rz)
git logthen use the hash of the commit you want to revert: (and when you're in the in-CLI editor, type :qa and then hit Enter)
git revert l0ngStr1ng0fL3t7er5AndNum83rzhttps://stackoverflow.com/a/34954852
git checkout --orphan <name_you_choose_for_orphan_branch>
git commit
git push <remote-name> <branch-name>https://stackoverflow.com/questions/45400361/why-is-gitignore-not-ignoring-my-files
For example, if I accidentally git added in dist/index.html, then changes on it will be tracked, so I'd need to run one of these:
git rm --cached dist/index.html
git rm -r --cached dist
# -r is for recursive
# and then add and commit the new change(s) to untrackGet file info like edit date: stat filename
Example of script used by Travis CI npm run build to copy files to /public folder: copy-to-public-folder.sh
Example of script used to generate and insert a package SemVer number for a JS file: package.sh
Exit/quit:
exityarn global list
npm list -g --depth 0 for just top-level
npm list -g browser-sync or a specific package (this example checks if browser-sync is installed globally)
Examples I set up in package.json:
{
"test": "tsc $npm_config_name.ts --lib es6,dom && node $npm_config_name.js",
"demo": "echo \"HELLO $npm_config_file_name.ts GOODBYE (\\$npm_config_whatever will match --whatever=...)\""
}So you can do this:
npm run demo --file_name=someFileName
# prints out: HELLO someFileName.ts GOODBYE [...]and:
npm run test --name=sameFileName
# will run: tsc sameFileName.ts --lib es6,dom && node sameFileName.jsnpm install <package-name> --save-exactso you get 1.2.3 instead of ^1.2.3 in your package.json
You can upgrade to the latest npm with npm install -g npm@latest
But installing node manually doesn't always work, and using n or clean cache didn't seem to work for me. https://stackoverflow.com/questions/23940172/not-seeing-latest-version-when-updating-node-js-via-installer-msi-windows-7/31229369#31229369
For Mac/OSX, try this first:
brew install nodeOtherwise this:
nvm install node --lts
node -vIf you accidentally installed the latest but want to downgrade to the last stable instead:
nvm install 14.15.0 # whatever the latest unstable versioni on https://nodejs.org/en/
nvm use 14.15.0https://github.com/hchiam/learning-zsh
prettier --write .or
npx prettier --write .https://stackoverflow.com/questions/7244321/how-do-i-update-or-sync-a-forked-repository-on-github
git remote add upstream https://github.com/<owner>/<repo>.git
git fetch upstreamhttps://github.com/hchiam/learning-gh
For gh CLI: copy your PAT, run gh auth login, and paste your PAT when prompted to.
For npm pkg: copy your PAT, open ~/.npmrc, and paste your PAT to be the "TOKEN" part of a string //npm.pkg.github.com/:_authToken=TOKEN in that ~/.npmrc file.
python3 -m http.server 8000or set up shortcut srv in .bash_profile:
alias srv='python3 -m http.server 8000'
- Bash ≈ Zsh
- the terminal is kinda like the console log in browser dev tools, but can switch between shell languages
echo≈console.log$notation is just for start of promptpwd= print the current working directory folder pathls= list current folder files/subfoldersls -la=-long data too like updated dates, and-all files including hidden files/folders
cd= change directory~= home folder, like/Users/yourusernamehere.= current folder..= parent folder- use the tab key to auto-complete!
rm= removerm -r foldername= removefoldernameand-recursively inside it toorm -rf foldername= do that, but-force remove regardless of permissions
man somecommand= show a printout of themanual for somecommand- hit
qtoquit (arrow keys to scroll)
- hit
ping 8.8.8.8= continuously check latency against IP address 8.8.8.8 (Google's DNS server), which can be used to continuously check if the server is online (Ctrl+corCtrl+dto stop)-= "previous"cd -= toggle to previous foldergit checkout -= toggle to previously-checked-out branch
alias hi='echo "Hello world!"'- now you can just do
hito get a printout ofHello world!
- now you can just do
command1 && command2= do command1 and then to command2- stuck in Vi/Vim?
Ctrl+cwon't work! hitEscape->:->q!->Enter - common web dev tasks: https://www.joshwcomeau.com/javascript/terminal-for-js-devs/#common-development-tasks
- reinstall dependencies:
rm -rf node_modules; npm install;
- reinstall dependencies:
- https://www.tutorialspoint.com/unix/unix-special-variables.htm
- https://www.tutorialspoint.com/unix/unix-using-arrays.htm
- https://www.tutorialspoint.com/unix/unix-basic-operators.htm
- https://www.tutorialspoint.com/unix/unix-decision-making.htm
- https://www.tutorialspoint.com/unix/unix-shell-loops.htm
- https://www.tutorialspoint.com/unix/unix-quoting-mechanisms.htm for getting variables and special characters parsed or not parsed in strings
- https://www.tutorialspoint.com/unix/unix-io-redirections.htm - there's more to it than just > file
- https://www.tutorialspoint.com/unix/unix-shell-functions.htm
- https://www.tutorialspoint.com/unix/unix-manpage-help.htm
- https://www.tutorialspoint.com/unix/unix-useful-commands.htm
https://www.youtube.com/shorts/fwBIZRq-vzY
-
mkdir, but with multiple sibling folders at the same time:-
mkdir folderthen:mkdir -p folder/{sibling1,sibling2}/{commonA,b,c} -
gives you this:
/folder /sibling1 /commonA /b /c /sibling2 /commonA /b /c
-
-
cd, but back to where you last were instead ofcd ..a bunch of times:-
cd ./somewhere/deeply/nestedthen to get back to./:cd -
-
-
touch, but create a bunch of files with names with a pattern:-
touch file{1..10}.txt=
file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt file7.txt file8.txt file9.txt file10.txt
-
(note: the one-liner command doesn't pad with 0s on my machine despite
{01..10}) -
two 0-padding alternatives that worked for me: (
%02g= zero-padding of width 2 of general number format)-
touch $(seq -f "file%02g.txt" 1 10) -
or this: (the space after
txtmatters for this one!)touch $(printf "file%02g.txt " {1..10})`
-
-
-
tail err.logto read a file, buttail -f err.logto "follow" changes- (note: doesn't seem to print out the right contents if i edit in another tab with
nano)
- (note: doesn't seem to print out the right contents if i edit in another tab with
-
history, but to get the last 5 commands:-
history 5
-