Cmder配置

命令行神器cmder

windows上做开发,不管是cmd还是powershell,似乎都不够美观,不够强大,今天就来介绍一款可以替代cmd的神器,Cmder,话不多少,如图:
main.png
Cmder的主要优点是可移植性。 它设计为完全独立,没有外部依赖性,这使其非常适合USB Sticks或云存储。 因此,可以随身携带控制台,别名和二进制文件(如wget,curl和git)
它有如下特点;

  • 可设置命令别名
  • 丰富的颜色主题(Solarized、Twilight、Ubuntu、xterm、Monokai,甚至接受自定)、可定制字体
  • 支持tab分页、同屏多端口(支持水平分割、垂直分割)
  • 支持自定terminal,无论是CMD、PowerShell、bash都可以,还可以注入环境变量
    下载链接:Cmder.net
    同时他也是一个开源项目:在github上的地址:cmder

安装方法

1.下载最新版本
2.将存档解压缩到共享位置。
3.(可选)将自己的可执行文件放入%cmder_root%\ bin文件夹以注入PATH。
4.(可选)创建%userprofile%\ cmder_config \ bin文件夹以注入单个用户PATH。 默认是在第一次运行时自动创建它。
5.(可选)将自己的可执行文件放入%userprofile%\ cmder_config \ bin文件夹以注入PATH
6.使用/ C命令行参数运行Cmder.exe。 示例:cmder.exe / C%userprofile%\ cmder_config
 - 如果缺少,将创建以下目录结构。
 ```bash
C:\ Users \ [用户名] \ cmder_config
         ├───bin
         └───config
             └───profile.d

 - 共享安装和单个用户配置位置都可以包含一整套`init`和`profile.d`脚本,从而启用带有用户覆盖的共享配置。
## Cmder.exe 命令行参数
用法:`Cmder.exe /REGISTER ALL`(需要管理员权限)
| 参数                 | 说明                                                 |
| ------------------------- | ------------------------------------------------------------ |
| `/C [user_root_path]`     | 个人用户Cmder根文件夹,例如: `%userprofile%\cmder_config` |
| `/M`                      | 使用 `conemu-%computername%.xml` 来储存设置,而不是用户设置 `user_conemu.xml` |
| `/REGISTER [ALL, USER]`   | 注册Windows右键菜单
| `/UNREGISTER [ALL, USER]` | 反注册Windows右键菜单
| `/SINGLE`                 | 以单一模式启动Cmder.                                  |
| `/START [start_path]`     | 启动的文件夹路径.                                     |
| `/TASK [task_name]`       | 启动后的任务.                                  |

## 手动设置
- 设置默认启动`powershell`
![image.png](https://upload-images.jianshu.io/upload_images/2476137-f67fe8da070991ba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
- 设置启动目录:`setting -> Startup - > Task`,修改`{cmd::Cmder}`项,把:
`*cmd /k "%ConEmuDir%\..\init.bat" -new_console:d:%USERPROFILE%`
修改成 :`cmd /k "%ConEmuDir%\..\init.bat"  -new_console:d: `
![image.png](https://upload-images.jianshu.io/upload_images/2476137-a364cab0180c3232.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
- 解决文字重叠问题
`Win + ALT + P `,唤出设置界面直接去掉右边那个monospce的对勾即可
![image.png](https://upload-images.jianshu.io/upload_images/2476137-fbed1fca959290cd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

- `ls`命令不支持中文
`win+alt+p`打开设置面板,找到`Startup -> Envrioment`选项
在下面的文本框里添加一行` set LANG=zh_CN.UTF-8`
![image.png](https://upload-images.jianshu.io/upload_images/2476137-90781fea3f92a2fa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后重启cmder
然后用ls命令查看目录下的文件,带中文的文件名都能正常显示了
- 修改命令提示符号
cmder默认的命令提示符是 `λ` ,如果想改成常见的 `$` ,具体操作如下:
打开cmder安装目录下的`\vendor\clink.lua`文件找到`lambda = "λ"和lambda = "("..env..") λ"`把`λ`替换成`$`然后重启cmder即可,但`powerShell`需要另行设置,打开cmder安装目录下的`\vendor\profile.ps1`文件找到`λ <PostPrompt> <repl input>`和`λ <PostPrompt> |`和`Microsoft.PowerShell.UtilityWrite-Host "nλ " -NoNewLine -ForegroundColor "DarkGray"`把`λ`替换成`$` ,然后重启cmder即可
下面是官方说明:
### Prompt

Open the following file in your favourite IDE:

\cmder\vendor\clink.lua


*NOTE:* To avoid the `clink.lua` getting overwritten on update, create a new file at `%cmder_root%\config\my_prompt.lua` with your changes -- 

Find the following lines:

local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg}{svn} \n\x1b[2;37;40m{lamb} \x1b[0m"
local lambda = "λ"

#### Prompt Color

The color is controlled by [escape sequences](https://stackoverflow.com/a/33206814/1454514), which is written as `ESC [` in the documentation or `\x1b[` in our `clink.lua` file.
For example, `\x1b[1;32;40m` will display the path (`{cwd}`) in green.

If you change **32** to **36**, you'll get cyan path:
![cmder-cyan](//upload-images.jianshu.io/upload_images/2476137-f1b513fd58dff8ac.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
If you change **32** to **33**, you'll get yellow path:
![cmder-yellow](//upload-images.jianshu.io/upload_images/2476137-f3c9acaea8273a0e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
- Android Studio,PHPStorm和其他基于IntelliJ的IDE
要将Cmder作为任何基于IntelliJ的IDE运行,可以按照以下步骤操作:
1.在Cmder安装目录中创建一个新的`cmder_shell.bat`文件,其中包含以下内容:`@cmd.exe /k %0\..\vendor\init.bat`
2.在IDE环境中,按`Ctrl + Alt + S`并在搜索框中键入`terminal`。
3.在** Shell路径**中,将* cmd.exe *更改为以下内容:`[cmder_root] \ cmder_shell.bat`(cmder_root是你创建的环境变量,或者是你的cmder文件夹路径)
![image.png](https://upload-images.jianshu.io/upload_images/2476137-42dacd52b5ea576b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4.然后就可以看到terminal啦
![image.png](https://upload-images.jianshu.io/upload_images/2476137-7a1d3b449504035e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

- 把cmder加入环境变量
1. 用Cmder安装目录替换`[cmder_root]`。
**提示:**定义一个环境变量用作`[cmder_root]`。
![image.png](https://upload-images.jianshu.io/upload_images/2476137-a5ce5a6a3103f424.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2. 定义`%ConEmuDir%`,在创建变量时使用以下值:
     - 变量名称:`%ConEmuDir%`
     - 值:[cmder_root] \ vendor \ conemu-maximus5例如:`C:\ apps \ cmder \ vendor \ conemu-maximus5`
3. 添加到`path` 找到 `path`变量,再添加一条为你的cmder地址,比如我的就是`D:\Program Files\Cmder\` 
4. 选择`win+r`命令,输入`cmder`就可以运行了
- 自定义aliases

   cmder还增加了alias功能,它让你用短短的指令执行一些常见但指令超长又难以记忆的语法;比如 `ls cls`等等
   打开cmder安装目录下的**`\config\user-aliases.cmd`**文件
   下面是我自己定义的常用的

st="D:\Sublime Text 3\sublime_text.exe" //输入st打开Sublime Text 3编辑器
w=cd /d E:/www //输入w跳转到E盘下的www目录
..=cd .. //输入..返回上一级文件夹
wp=.\node_modules.bin\webpack $* //如果webpack不是全局安装而是安装在项目下webpack命令不能直接用,
//需要.\node_modules.bin\webpack调用,每次都这样写太麻烦。
//现在只要输入wp就可以用webpack命令

### Cmder常用快捷键
1. 利用Tab自动路径补全
2. 利用Ctrl+T建立新页签
3. 利用Ctrl+W关闭页签
4. 利用Ctrl+Tab切换页签
5. Alt+F4 关闭所有页签
6. Alt+Shift+1 开启cmd.exe
7. Alt+Shift+2 开启powershell.exe
8. Alt+Shift+3 开启powershell.exe (系统管理员权限)
9. Ctrl+1 快速切换到第1个页签
10. Ctrl+n 快速切换到第n个页签( n值无上限)
11. Alt+enter 切换到全屏状态
12. Ctrl+r 历史命令搜索
13. Ctrl+` 全局召唤
还有更多的配置,等着挖掘...
posted @ 2019-03-19 19:05  是河兔兔啊  阅读(317)  评论(0编辑  收藏  举报