前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >小记之 Mac 控制台中文乱码的两个坑

小记之 Mac 控制台中文乱码的两个坑

作者头像
波罗学
发布2019-07-31 11:41:09
1.3K0
发布2019-07-31 11:41:09
举报
文章被收录于专栏:码神路漫漫码神路漫漫

今天使用 Mac Terminal 时,解决了两个中文乱码的问题,记录一下。

git status 中文乱码

今天,整理博客文章的时候,发现 git status 展示中文名的文件出现了乱码。因为平时编程时,代码文件的名称基本都是英文,故而很少留意这个问题。默认的 git status 效果如下:

代码语言:javascript
复制
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        "\346\227\245\345\270\270/"

nothing added to commit but untracked files present (use "git add" to track)

在网上搜了些解决方案,发现只需要一个 git 配置就可以解决这个问题,配置命令如下:

代码语言:javascript
复制
$ git config --global core.quotepath false

关于这个选项的介绍,官方原文如下:

Commands that output paths (e.g. ls-files, diff), will quote "unusual" characters in the pathname by enclosing the pathname in double-quotes and escaping those characters with backslashes in the same way C escapes control characters (e.g. \t for TAB, \n for LF, \ for backslash) or bytes with values larger than 0x80 (e.g. octal \302\265 for "micro" in UTF-8). If this variable is set to false, bytes higher than 0x80 are not considered "unusual" any more. Double-quotes, backslash and control characters are always escaped regardless of the setting of this variable. A simple space character is not considered "unusual". Many commands can output pathnames completely verbatim using the -zoption. The default value is true.

大致意思似乎是, 为防止一些转义问题,大于 0x80 以上的编码被认为是 "unusual" ,需要 quote 起来。设置成 false 即以 UTF8 编码解析,解决乱码问题。

tree 目录树乱码

真是奇了,乱码与我为敌啊!今天又遇到第二个乱码问题,为了写文章时,屏幕展示区域多点,我就把 VS Code 的侧边栏关了,然后通过 tree 查看目录树,结果出现了如下的结果:

代码语言:javascript
复制
.
├── Go\ �\210��\231�
│   └── Go\ �\210��\231��\213HTTP请�\202\ QuickStart.md
├── Go\ �\224记
│   ├── 详解\ Go\ �\232\204�\226�\221�\211��\214�\201�\213.md
│   └── 为�\200�\210�\201学\ Go.md
├── Go\ �\217�\237��\206
├── README.md
├── �\227�常
│   └── Mac\ �\216��\210��\217�中�\226\207乱�\201�\232\204两个�\235\221.md
└── �\204件
    ├── pm2\ �\233�\213管�\220\206工�\205�使�\224��\200��\223.md
    ├── �\200�\226\207精�\200\232\ crontab\ �\216�\205��\227��\210��\207��\235\221.md
    └── 快�\200\237�\206解\ kafka\ �\237��\200�\236��\236\204.md

解决方式,通过 tree -N 即可解决。执行结果如下:

代码语言:javascript
复制
├── Go 爬虫
│   └── Go 爬虫之HTTP请求 QuickStart.md
├── Go 笔记
│   ├── 详解 Go 的编译执行流程.md
│   └── 为什么要学 Go.md
├── Go 小知识
├── README.md
├── 日常
│   └── Mac 控制台中文乱码的两个坑.md
└── 组件
    ├── pm2 进程管理工具使用总结.md
    ├── 一文精通 crontab 从入门到出坑.md
    └── 快速了解 kafka 基础架构.md

看了选项的介绍,似乎是因为默认会将一些非打印字符按 ?处理,可以去看看 -q 选项。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年05月27日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • git status 中文乱码
  • tree 目录树乱码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档