mac 命令行显示配置

来源:互联网 发布:无需网络的收音机 编辑:程序博客网 时间:2024/06/05 06:02

        最近入了个air,试用一下乔老爷子的杰作,犹豫了一阵子才入的,毕竟不便宜,而且关税占17%,一度觉得好亏。。。不过时间应该用来耗费在美好的事物上,不是么?所以咬咬牙还是入了。上手体验确实很爽。超薄的外形,很有质感的金属外壳,酷炫的用户界面,让人激动不已。不过默认的mac命令行界面是黑白的,对于几乎每天都要跟命令行打交到的码农来说,完全黑白的不够赏心悦目。(当然,真正的牛人估计觉得黑白才有质感吧。。)

        打开mac的ls 颜色高亮效果非常简单,只需要在~/.bash_profile中增加下面一行:

export CLICOLOR=1

        如果没有~/.bash_profile文件就自己创建一个就好。

        这样关闭shell后再打开就可以再执行ls命令的时候看到不同的高亮效果了。有的童鞋不满足于系统简单的配色方案,可以到terminal->preferences...中选择自己的配色方案。我暂时用的是系统的方案,看起来比较简洁。以后可以试试其他的方案。

        另外一个配置就是可以自己定制自己的命令行前面的提示信息显示的内容以及格式。用惯的ubuntu之后,感觉不太习惯mac os上的提示,所以搜索了一下相关的文章。

        主要的概念就是系统试用PS环境变量来控制命令行提示符的展示形式。

        其中PS1是主要展示,就是平时我们打开shell的时候显示的那些提示信息。而PS2则是控制副提示标题,一般是需要换行输入的时候显示。

        我的配置很简单:

export PS1="\\u:\\w\\$ "

        用来显示用户名,当前路径,和$符号,另外在最后增加了一个空格用来隔开提示信息和实际用到的命令。

        配置是非常强大的,具体的控制参数如下:

\d – the date in "Weekday Month Date" format (e.g., "Tue May 26")\e – an ASCII escape character (033)\h - the hostname up to the first .\H – the full hostname\j – the number of jobs currently run in background\l – the basename of the shells terminal device name\n – newline\r – carriage return\s – the name of the shell, the basename of $0 (the portion following the final slash)\t – the current time in 24-hour HH:MM:SS format\T – the current time in 12-hour HH:MM:SS format\@ – the current time in 12-hour am/pm format\A – the current time in 24-hour HH:MM format\u – the username of the current user\v – the version of bash (e.g., 4.00)\V – the release of bash, version + patch level (e.g., 4.00.0)\w – Complete path of current working directory\W – the basename of the current working directory\! – the history number of this command\# – the command number of this command\$ – if the effective UID is 0, a #, otherwise a $\nnn – the character corresponding to the octal number nnn\\ – a backslash\[ - begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt\] – end a sequence of non-printing characters





0 0