红绿互换

gr2rg(){
  perl -ne 's/
  (\033\[(\d+;)*[34])([12])
  ((;\d+)*m)
  /$1.(3-$3).$4/xge;
  print' $*
}

把上面几行加入 .bash_profile 里面,实现红绿互换

-bash-3.2# echo -e "\e[31mRED\e[0m"

RED

-bash-3.2# echo -e "\e[31mRED\e[0m" | gr2rg

RED

-bash-3.2# echo -e "\e[32mGREEN\e[0m"

GREEN

-bash-3.2# echo -e "\e[32mGREEN\e[0m" | gr2rg

GREEN


你可能感兴趣的:(红绿互换)