node使用Git Bash作為命令行終端示例
命令行也有苦惱
不知身為前端er的你是不是還在使用 Windows 開發(fā)?反正我是。使用 Git?使用 npm scripts?好吧,命令行是少不了的吧?想必很多同學和我一樣,使用 Git Bash 作為命令行終端吧。
可是每次都要敲,累不累?想想一次簡單的 Git 提交需要幾個步驟?
$ git add -A $ git commit -m 'commit' $ git push
圖簡便的你可能會在 package.json 中這樣配置:
{ // ... "scripts": { // ... "push": "git add -A && git commit -m 'commit' && git push" } } // ...
然后再敲 npm run push
。啊啊心好累。
用過 browser-sync cli
嗎?反正為了圖簡便,我是經(jīng)常用的。敲過最變態(tài)的是下面這一行:
browser-sync start --server --files "dist/*" --index "dist/index.html" --open "external" --reload-debounce --no-notify
.bat/.sh 的故事
敲過一次之后,發(fā)誓再也不這么玩了。索性在桌面保存了一個 bs.bat
文件,把上面的內容放進去。每次都從桌面 copy 到工作目錄中去,雙擊完事。
后來玩 github 稍微勤了一些,commit、pull 的時候,命令行敲起來固然爽得不行,可是累啊。在上一家公司做 react-native 應用的時候,對 react-native run start
cd android && ./gradlew assembleRelease
也是深惡痛絕。最后無不以 bat、sh文件收尾。
nshm 的由來
前些時間接觸到一個管理 npm registry
的 package,叫 nrm
,用起來真是爽。nrm use taobao
nrm add xx url
簡單就能解決問題。這讓我萌生一個想法:能不能不要每次都從桌面 copy 那些簡單的腳本啊,來個簡單的命令行自己把文件寫目錄不就 OK 了嗎?
醞釀了一段時間。遲遲不肯動手。今天中午下樓抽煙,靈機一動,思路來了,花了半下午時間,邊寫邊重構,最終做出來一個略嫌簡陋但還能湊合用的工具,名之曰 “nshm”,取 “Node.js .sh scripts Manager” 的縮寫。
使用起來很簡單,看文檔就行。
安裝
$ npm install nshm -g $ nshm <command> [args...]
添加一條自定義命令
$ nshm add <command_name> -[t|f] [text|path] # add file content $ nshm add commit --file ./my-commit.sh # or $ nshm add commit -f ./my-commit.sh # add text content $ nshm add pull --text "git pull" # or $ nshm add pull -t "git pull"
多個命令合并成一條命令
$ nshm co <command_name> [command|text] [command|text] [command|text] [...] $ nshm co git commit pull "git status"
刪除緩存的命令
$ nshm rm <command_name> <command_name> <...> $ nshm rm commit pull git
清除所有緩存的命令
$ nshm clean
列出現(xiàn)有的命令
# view all names $ nshm ls # view all details $ nshm ls -a
Example 01
$ nshm add add -t "git add -A" $ nshm add commit -t "git commit -m 'push'" $ nshm add pull -t "git push" $ nshm co git add commit pull # init my directory # then we'll get `add.sh` `commit.sh` `pull.sh` $ nshm git
Example 02
# browserSync cli # here we use `${}` as placeholders # for necessary params $ nshm add bs -t "browser-sync start --server --files \"${files}\" --index \"${index}\" --open \"external\" --reload-debounce --no-notify" # now we get the `bs.sh` file under our working directory $ nshm bs --file '**' --index 'index.html'
結尾
工具默認自帶了 Git 相關的 commit
pull
及集成兩者的 git
命令,還有上面提到的 browser-sync
的命令(簡稱作bs
)。也可以使用 nshm add
的形式自己添加。
微不足道的工具,自娛自樂一下,雖然顯得 low 了點,也能解決自己的一點問題。
以上就是node使用Git Bash作為命令行終端示例的詳細內容,更多關于node命令行終端Git Bash的資料請關注腳本之家其它相關文章!
相關文章
Node在Controller層進行數(shù)據(jù)校驗的過程詳解
這篇文章主要給大家介紹了關于Node在Controller層進行數(shù)據(jù)校驗的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-08-08快速搭建Node.js(Express)用戶注冊、登錄以及授權的方法
這篇文章主要介紹了快速搭建Node.js(Express)用戶注冊、登錄以及授權,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05Nodejs監(jiān)控事件循環(huán)異常示例詳解
這篇文章主要給大家介紹了關于Nodejs監(jiān)控事件循環(huán)異常的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Nodejs具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-09-09