【问题标题】:Editing .zshrc to color coat ls output in iterm2 based on file type根据文件类型编辑 .zshrc 以在 iterm2 中为 ls 输出着色
【发布时间】:2019-02-20 16:50:02
【问题描述】:

所以我知道可能有很多关于此的帖子,但要么我找不到我需要的帖子,要么我的终端讨厌我。我正在尝试使用 OSX 上 iterm2 上的 zsh shell 为 ls 的输出着色。

我尝试过使用别名“alias ls='ls -laGH'”和许多变体,但没有奏效。 我尝试在 zshrc 中使用 LS_COLORS 有很多变化,但没有成功。 我已经尝试了几个小时来安装这个https://github.com/trapd00r/LS_COLORS,但没有成功(当然还安装了zplugin)。

我的预测是由于颜色或主题已经实现但优先于别名或 GitHub 存储库,因此没有任何效果?

任何帮助将不胜感激!

这是当前的 .zshrc:

# Load Nerd Fonts with Powerlevel9k theme for Zsh
POWERLEVEL9K_MODE='nerdfont-complete'
source ~/powerlevel9k/powerlevel9k.zsh-theme

# Customise the Powerlevel9k prompts
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh dir vcs newline status)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(time ram dir_writable)
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true

# Load Zsh tools for syntax highlighting and autosuggestions
HOMEBREW_FOLDER="/usr/local/share"
source "$HOMEBREW_FOLDER/zsh-autosuggestions/zsh-autosuggestions.zsh"

# Colorise the top Tabs of Iterm2 with the same color as background
# Just change the 18/26/33 wich are the rgb values

echo -ne "\033]6;1;bg;red;brightness;18\a"
echo -ne "\033]6;1;bg;green;brightness;26\a"
echo -ne "\033]6;1;bg;blue;brightness;33\a"

# Aliases for list commands with colorful output
alias ls='ls -laGH'
alias add='git add * ; git status'

source '/Users/christianquinn/.zplugin/plugins/trapd00r---LS_COLORS/c.zsh'
source "$HOMEBREW_FOLDER/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"

### Added by Zplugin's installer
source '/Users/christianquinn/.zplugin/bin/zplugin.zsh'
autoload -Uz _zplugin
(( ${+_comps} )) && _comps[zplugin]=_zplugin
### End of Zplugin's installer chunk

【问题讨论】:

    标签: macos zsh iterm2 zshrc


    【解决方案1】:

    ls 的输出进行着色的变量取决于所使用的操作系统。

    在 macOS(或基于 BSD 的系统)上,您必须配置 LSCOLORS 变量,例如

      export LSCOLORS="Gxfxcxdxbxegedabagacab"
    

    在 GNU 的情况下,配置 LS_COLORS 变量

      export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:ow=0;41:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:*.patch=00;34:*.o=00;32:*.so=01;35:*.ko=01;31:*.la=00;33'
    

    有像geoff.greer.fm/lscolors 这样的自定义颜色生成器可以帮助微调所需的颜色。尽管像 trapd00r/LS_COLORS 这样的插件为更大的文件类型集提供了颜色。

    【讨论】:

      猜你喜欢
      • 2019-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 2013-07-30
      相关资源
      最近更新 更多