Macos 如何让mac终端对bash脚本进行颜色编码?

Macos 如何让mac终端对bash脚本进行颜色编码?,macos,bash,Macos,Bash,所以我只是想知道,是否有可能让我的mac电脑以彩色显示我的bash脚本,以便更容易地看到小错误以及其他错误。就像在爪哇一样 scan.nextInt(); Eclipse(一个编写代码的程序)将使Int变为红色。这就是我非常想要的。只是为了便于查看我的代码。我甚至不知道这是否可能,所以感谢所有愿意提供建议的人 其他一些信息:我有一个版本为10.8.5的MacBook,显然在bash(mac默认shell)中是不可能的。您可以使用或zsh(我个人的选择)与 如果您选择zsh,我强烈推荐该框架。显

所以我只是想知道,是否有可能让我的mac电脑以彩色显示我的bash脚本,以便更容易地看到小错误以及其他错误。就像在爪哇一样

scan.nextInt();
Eclipse(一个编写代码的程序)将使Int变为红色。这就是我非常想要的。只是为了便于查看我的代码。我甚至不知道这是否可能,所以感谢所有愿意提供建议的人


其他一些信息:我有一个版本为10.8.5的MacBook,显然在bash(mac默认shell)中是不可能的。您可以使用或zsh(我个人的选择)与


如果您选择zsh,我强烈推荐该框架。

显然,在bash(mac默认shell)中是不可能的。您可以使用或zsh(我个人的选择)与

如果您选择zsh,我强烈推荐该框架。

您知道vi吗?安装。MacVIM内置了语法高亮显示。顺便说一下,Mac上已有的
vim
命令也是如此。最可能的情况是,您需要设置
.vimrc
文件来为您打开语法高亮显示

不太清楚我从哪里得到的,但这是一个
.vimrc
文件,它为您打开语法高亮显示:

" An example for a vimrc file.
"
" Maintainer:       Bram Moolenaar <Bram@vim.org>
" Last change:      2002 Sep 19
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"         for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"       for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup              " do not keep a backup file, use versions instead
else
  set backup                " keep a backup file
endif
set history=50              " keep 50 lines of command line history
set ruler           " show the cursor position all the time
set showcmd         " display incomplete commands
set incsearch               " do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
   set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

  augroup END

else

  set autoindent            " always set autoindenting on

endif " has("autocmd")
syntax on
set ai showmode showmatch report=1 sw=4 showcmd textmode ruler smartindent nobackup nohlsearch ff=unix diffopt+=iwhite
“vimrc文件的示例。
"
“维护者:布拉姆·穆勒纳
“最后更改:2002年9月19日
"
“要使用它,请将其复制到
“对于Unix和OS/2:~/.vimrc
“对于Amiga:s:.vimrc
“对于MS-DOS和Win32:$VIM\\u vimrc
“对于OpenVMS:sys$login:.vimrc
当以“evim”启动时,evim.vim将已经完成这些设置。
如果v:progname=~?“evim”
完成
恩迪夫
“使用Vim设置,而不是Vi设置(更好!)。
“这必须是第一步,因为它会作为副作用改变其他选项。
兼容模式
“允许在插入模式下对所有内容进行退格
设置退格=缩进、下线、开始
如果有(“虚拟机”)
set nobackup“不要保留备份文件,请改用版本
其他的
设置备份“保留备份文件
恩迪夫
设置历史记录=50“保留50行命令行历史记录
“设置标尺”始终显示光标位置
设置showcmd“显示不完整的命令
设置incsearch“执行增量搜索
对于Win32 GUI:从“GUI选项”中删除“t”标志:无tearoff菜单项
“let&guioptions=替换(&guioptions,“t”,“g”)
“不要使用Ex模式,请使用Q进行格式化
地图QGQ
“这是一种也适用于块模式的替代方案,但已删除
“文本丢失,仅用于放置当前寄存器。
“vnoremap p”\u dp
当终端有颜色时,打开语法高亮显示
“同时打开高亮显示上次使用的搜索模式。
如果&t_Co>2||has(“gui_运行”)
语法高亮
高亮显示
恩迪夫
“仅当在支持自动命令的情况下编译时才执行此部分。
如果有(“自动MD”)
“启用文件类型检测。
使用默认的文件类型设置,使mail的“tw”设置为72,
“'cindent'在C文件等中处于打开状态。
同时加载缩进文件,以自动执行语言相关的缩进。
文件类型插件缩进
“将它们放在autocmd组中,以便我们可以轻松删除它们。
AugroupVimrcex
哎呀!
“对于所有文本文件,将“textwidth”设置为78个字符。
autocmd文件类型文本集本地文本宽度=78
编辑文件时,始终跳转到最后一个已知的光标位置。
“当位置无效或在事件处理程序中时,不要执行此操作
“(在gvim上删除文件时发生)。
autocmd BufReadPost*
\如果line(“\”)>0&&line(“\”)您知道vi吗?安装.MacVIM内置了语法高亮显示。顺便说一下,
vim
命令已经在Mac上了。很可能,您需要设置
.vimrc
文件来为您打开语法高亮显示

不太清楚我从哪里得到的,但这是一个
.vimrc
文件,它为您打开语法高亮显示:

" An example for a vimrc file.
"
" Maintainer:       Bram Moolenaar <Bram@vim.org>
" Last change:      2002 Sep 19
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"         for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"       for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup              " do not keep a backup file, use versions instead
else
  set backup                " keep a backup file
endif
set history=50              " keep 50 lines of command line history
set ruler           " show the cursor position all the time
set showcmd         " display incomplete commands
set incsearch               " do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
   set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

  augroup END

else

  set autoindent            " always set autoindenting on

endif " has("autocmd")
syntax on
set ai showmode showmatch report=1 sw=4 showcmd textmode ruler smartindent nobackup nohlsearch ff=unix diffopt+=iwhite
“vimrc文件的示例。
"
“维护者:布拉姆·穆勒纳
“最后更改:2002年9月19日
"
“要使用它,请将其复制到
“对于Unix和OS/2:~/.vimrc
“对于Amiga:s:.vimrc
“对于MS-DOS和Win32:$VIM\\u vimrc
“对于OpenVMS:sys$login:.vimrc
当以“evim”启动时,evim.vim将已经完成这些设置。
如果v:progname=~?“evim”
完成
恩迪夫
“使用Vim设置,而不是Vi设置(更好!)。
“这必须是第一步,因为它会作为副作用改变其他选项。
兼容模式
“允许在插入模式下对所有内容进行退格
设置退格=缩进、下线、开始
如果有(“虚拟机”)
set nobackup“不要保留备份文件,请改用版本
其他的
设置备份“保留备份文件
恩迪夫
设置历史记录=50“保留50行命令行历史记录
“设置标尺”始终显示光标位置
设置showcmd“显示不完整的命令
设置incsearch“执行增量搜索
对于Win32 GUI:从“GUI选项”中删除“t”标志:无tearoff菜单项
“let&guioptions=替换(&guioptions,“t”,“g”)
“不要使用Ex模式,请使用Q进行格式化
地图QGQ
“这是一种也适用于块模式的替代方案,但已删除
“文本丢失,仅用于放置当前寄存器。
“vnoremap p”\u dp
当终端有颜色时,打开语法高亮显示
“同时打开高亮显示上次使用的搜索模式。
如果&t_Co>2||has(“gui_运行”)
语法高亮
高亮显示
恩迪夫
“仅当在支持自动命令的情况下编译时才执行此部分。
如果有(“自动MD”)
“启用文件类型检测。
使用默认的文件类型设置,使mail的“tw”设置为72,
“'cindent'在C文件等中处于打开状态。
同时加载缩进文件,以自动执行语言相关的缩进。
文件类型插件缩进
“将它们放在autocmd组中,以便我们可以轻松删除它们。
AugroupVimrcex
哎呀!
“对于所有文本文件,将“textwidth”设置为78个字符。
autocmd文件类型文本设置本地文本宽度