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

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

git status 中文乱码

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

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 配置就可以解决这个问题,配置命令如下:

$ 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 查看目录树,结果出现了如下的结果:

.
├── 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 即可解决。执行结果如下:

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

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

转载于:https://juejin.im/post/5ceabbce6fb9a07eb309584e

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值