]>
code.delx.au - monosys/blob - scripts/linux_colorwrap
3273f4740c6f077794d830f018b08202779c088c
3 PAGERS
= ["less", "more", "most", "tail", "head"]
6 # * Put this file into ~/bin/colorwrap
7 # * Add these aliases to your bash config
8 # alias ls="colorwrap ls"
9 # alias grep="colorwrap grep"
12 import os
, os
.path
, sys
, time
14 class Process(object):
15 def __init__(self
, pid
):
20 return os
.readlink("/proc/%s/fd/0" % self
.pid
)
24 return os
.readlink("/proc/%s/fd/1" % self
.pid
)
28 return file("/proc/%s/cmdline" % self
.pid
).read().split("\x00")
31 for pid
in filter(str.isdigit
, os
.listdir("/proc/")):
32 if os
.path
.exists("/proc/%s/fd/0" % pid
):
37 stdout
= file(cur
.stdout
)
38 return os
.isatty(stdout
.fileno())
42 # Follow from current pid until the end of the chain
44 cur
= Process(os
.getpid())
45 while count
< 32 and cur
.stdout
.startswith("pipe:"):
47 for cur
in validProcesses():
49 if last
.stdout
== cur
.stdin
:
62 if cur
.cmdline
in PAGERS
or isatty(cur
.stdout
):
63 args
.insert(1, "--color=always")
65 os
.execvp(command
, args
)