Skip to content

Commit

Permalink
feat(cz-git): add env CZ_EDITOR to change editor during confirm (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhengqbbb committed Sep 12, 2024
1 parent aa70a41 commit 0fad291
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
18 changes: 10 additions & 8 deletions .x-cmd/bump
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# shellcheck shell=dash

(
x bun x taze -r -I -i \
-x inquirer \
-x @types/inquirer \
-x https-proxy-agent \
-x rimraf \
-x @types/rimraf \
-x lint-staged \
-x pkg-dir \
# - "inquirer" - keep with "commitizen" same version
# - "rimraf" - v4 need node >= v14
# - "cosmiconfig" - will lead bundle size to 10MB +
x bun x taze -r -I -i \
-x inquirer \
-x @types/inquirer \
-x https-proxy-agent \
-x rimraf \
-x lint-staged \
-x pkg-dir \
-x cosmiconfig
)
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ useMediumZoom()
<i class="i-ri:heart-3-line" /> Sponsor
</a>
<a
href="https://afdian.net/a/qbbsh"
href="https://afdian.com/a/qbbsh"
target="_blank" rel="noopener"
class="px-5 leading-9 b b-$vp-custom-block-warning-border text-$vp-custom-block-warning-text-deep bg-$vp-custom-block-warning-bg rd-5 text-center font-600 whitespace-nowrap hover:op-80 transition-opacity"
flex="~ items-center gap-1"
Expand Down
27 changes: 26 additions & 1 deletion docs/faq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CZ_DEBUG=1 czg

> The `prepare-commit-msg` githook opens an editor after the commit message has been prepared [=> githooks man](https://git-scm.com/docs/githooks#_prepare_commit_msg)
1. Changing the default editor from `vi` to `cat`
1. Changing the default git editor from `vi` to `cat` and have a try
```sh
git config --local core.editor cat
```
Expand All @@ -50,6 +50,31 @@ CZ_DEBUG=1 czg
}
```
## Modifying the editor (EDITOR) used when choosing to edit during commit confirmation (Yneh)
> Here's an example using VSCode `code --wait` command

:::: code-group
::: code-group-item .zshrc | .bashrc

```sh
export CZ_EDITOR="code --wait"
```

:::
::: code-group-item package.json + cross-env

```json
{
"scripts": {
"commit": "cross-env CZ_EDITOR='code --wait' cz"
}
}
```

:::
::::


## Cannot find the command after global install

Expand Down
27 changes: 26 additions & 1 deletion docs/zh/faq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CZ_DEBUG=1 czg

> 在使用 `prepare-commit-msg` hook 中会在消息合并后使用 editor [=> githooks 命令手册](https://git-scm.com/docs/githooks#_prepare_commit_msg)
1. 将 editor 从默认 `vi` 改为 `cat`
1.git 配置中的 editor 从默认 `vi` 改为 `cat` 并尝试
```sh
git config --local core.editor cat
```
Expand All @@ -49,6 +49,31 @@ CZ_DEBUG=1 czg
}
```
## 修改在确认是否提交时 (Yneh),选择编辑时所使用的编辑器 (EDITOR)
> 这里以 VSCode 的 `code --wait` 命令为例
:::: code-group
::: code-group-item .zshrc | .bashrc
```sh
export CZ_EDITOR="code --wait"
```
:::
::: code-group-item package.json + cross-env
```json
{
"scripts": {
"commit": "cross-env CZ_EDITOR='code --wait' cz"
}
}
```
:::
::::
## 全局安装后无法找到命令
- 输入命令 `npm prefix -g` 查看当中 npm 全局下载的 bin 文件夹路径是否添加到系统环境变量 `$PATH`
Expand Down
2 changes: 1 addition & 1 deletion packages/cz-git/src/shared/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function editor(file?: string, opts?: any | object, cb?: any) {
opts = {}

const ed = process.platform.startsWith('win') ? 'notepad' : 'vim'
const editor = opts.editor || process.env.VISUAL || process.env.EDITOR || ed
const editor = opts.editor || process.env.CZ_EDITOR || process.env.VISUAL || process.env.EDITOR || ed
const args = editor.split(/\s+/)
const bin = args.shift()

Expand Down

0 comments on commit 0fad291

Please sign in to comment.