node使用Git Bash作為命令行終端示例
命令行也有苦惱
不知身為前端er的你是不是還在使用 Windows 開發(fā)?反正我是。使用 Git?使用 npm scripts?好吧,命令行是少不了的吧?想必很多同學(xué)和我一樣,使用 Git Bash 作為命令行終端吧。
可是每次都要敲,累不累?想想一次簡單的 Git 提交需要幾個(gè)步驟?
$ 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ā)誓再也不這么玩了。索性在桌面保存了一個(gè) bs.bat
文件,把上面的內(nèi)容放進(jìn)去。每次都從桌面 copy 到工作目錄中去,雙擊完事。
后來玩 github 稍微勤了一些,commit、pull 的時(shí)候,命令行敲起來固然爽得不行,可是累啊。在上一家公司做 react-native 應(yīng)用的時(shí)候,對 react-native run start
cd android && ./gradlew assembleRelease
也是深惡痛絕。最后無不以 bat、sh文件收尾。
nshm 的由來
前些時(shí)間接觸到一個(gè)管理 npm registry
的 package,叫 nrm
,用起來真是爽。nrm use taobao
nrm add xx url
簡單就能解決問題。這讓我萌生一個(gè)想法:能不能不要每次都從桌面 copy 那些簡單的腳本啊,來個(gè)簡單的命令行自己把文件寫目錄不就 OK 了嗎?
醞釀了一段時(shí)間。遲遲不肯動(dòng)手。今天中午下樓抽煙,靈機(jī)一動(dòng),思路來了,花了半下午時(shí)間,邊寫邊重構(gòu),最終做出來一個(gè)略嫌簡陋但還能湊合用的工具,名之曰 “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"
多個(gè)命令合并成一條命令
$ 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'
結(jié)尾
工具默認(rèn)自帶了 Git 相關(guān)的 commit
pull
及集成兩者的 git
命令,還有上面提到的 browser-sync
的命令(簡稱作bs
)。也可以使用 nshm add
的形式自己添加。
微不足道的工具,自娛自樂一下,雖然顯得 low 了點(diǎn),也能解決自己的一點(diǎn)問題。
以上就是node使用Git Bash作為命令行終端示例的詳細(xì)內(nèi)容,更多關(guān)于node命令行終端Git Bash的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Node在Controller層進(jìn)行數(shù)據(jù)校驗(yàn)的過程詳解
這篇文章主要給大家介紹了關(guān)于Node在Controller層進(jìn)行數(shù)據(jù)校驗(yàn)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08快速搭建Node.js(Express)用戶注冊、登錄以及授權(quán)的方法
這篇文章主要介紹了快速搭建Node.js(Express)用戶注冊、登錄以及授權(quán),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-05-05Nodejs監(jiān)控事件循環(huán)異常示例詳解
這篇文章主要給大家介紹了關(guān)于Nodejs監(jiān)控事件循環(huán)異常的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Nodejs具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09