linux下编辑文件,常用的有vi/vim,emacs,还有gedit -- 当然,还有谁有其他各种喜好。 emacs,vi什么的自然是控制台下搞,干干净净。 但是到了gedit的时候,因为是X display ,所以控制台方面就各种肆无忌惮的放warning

因为是写代码么,所以常常是shell跑到某个位置,然后vi/emacs/gedit一个命令打开文件,开始编辑。

在不装插件的时候,gedit其实还是挺干净的,插件一搞,各种error,warning防不胜防。尤其是某些该死的环境参数什么的,ignore完全没啥影响,不专门去搞,谁去关心。 但是,不调的话,

$ gedit xxx.c

然后下面就是哗啦啦的一堆warning. 真是不爽。

解决办法:

1. 写个bash后台打开gedit

新建个文件,名叫edit或者其他神马的

写入内容:
#!/bin/sh
nohup  gedit ${1+"$@"}  >/dev/null 2>&1

解释下: i) nohup,后台打开 ii) >/dev/null 2>&1 输出结果和错误提示都输出到空的地方(/dev/null) iii) ${1+"$@"} 你输入的参数 比如,你输入

$ edit -a -b -c -d

就相当于

$ nohup gedit -a -b -c -d  >/dev/null 2>&1
允许执行
$ chmod +x edit

然后移动到/usr/bin,~/bin 或者其他什么地方,只要在环境变量中设置好PATH即可。

以后碰到编辑的时候,可以使用命令

edit file_name

就可以,效果和gedit一样,唯独缺少错误提示。

2. alias

编辑.bash_profile或者.bashrc

添加如下命令

alias gedit='gedit -b'
注销重启

这时,你的gedit 命令默认带上参数 -b -b的意思,根据自带usage

  -b, --background                  Run gedit in the background

2和1相比,好处是没必要改口命令,坏处是你的gedit自带-b,哪天不想了得去掉alias注销重来。不方便。 1和2相比,好处是比较通用。gedit可以这样,其他任何程序都可以这么玩 -- 当然,如果把控制台程序也这么玩的话,那提示神马的都没了

继续写代码去...

Categories: Code

Yu

Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

Leave a Reply

Your email address will not be published. Required fields are marked *