linux 使用indent格式化代码

indent是一个代码整理工具,能够方便快速的将代码格式化.

这是我较习惯的代码风格,网上还有很多其他的

代码风格

参数:

-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs -nprs -npsl -saf -sai -saw -nsc -nsob -nss

用法:

indent [-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs -nprs -npsl -saf -sai -saw -nsc -nsob -nss] MutexBuffer.c

参数真的非常多,每次输入很麻烦,所以使用alias别名,配置进系统文件,使用起来会方便很多.

下面开始配置:

  • 有些Linux 版本貌似是自带的,没有的yum安装一下

    yum install indent

  • 切换root用户,打开/etc/bashrc 文件

    su root

    gedit /etc/bashrc

    我有尝试过编辑 /etc/profile文件, 但想要其生效, 每次使用前都需要重新输入命令source /etc/profile . 原理上这个文件比bashrc优先级高, 不太清楚为什么.

    /etc/profile: 为系统的每个用户设置环境变量信息, 在用户第一次登录时, 文件被执行.

    /etc/bashrc :此文件包含bash shell的bash信息, 每次打开新的shell时,该文件被读取.

  • 在文件末尾, 输入以下命令

    alias format="indent -nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs -nprs -npsl -saf -sai -saw -nsc -nsob -nss"

  • 保存后,执行下面命令,使刚才修改的环境变量生效.

    source /etc/bashrc

  • 然后就可以使用啦

format MutexBuffer.c

关机重启后,都是生效的~

[参考文章:https://blog.csdn.net/u011068702/article/details/53932530]

原文地址:https://www.cnblogs.com/musecho/p/11609441.html