Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.05 KB | None | 0 0
  1. alias less='less --RAW-CONTROL-CHARS'
  2. export LS_OPTS='--color=auto'
  3. alias ls='ls ${LS_OPTS}
  4.  
  5. export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33'
  6.  
  7. PS1='e[33;1mu@h: e[31mWe[0m$ '
  8.  
  9. PS1='e[se[0;0He[1;33mh tne[1;32mThis is my computere[u[u@h: w]$ '
  10.  
  11. sed "s/[^[[0-9;]*[a-zA-Z]//gi"
  12.  
  13. sed "s/^[^[8m.*$//gi"
  14.  
  15. export TERM=xterm-color
  16. export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
  17. export CLICOLOR=1
  18. export LSCOLORS=ExFxCxDxBxegedabagacad
  19.  
  20. export COLOR_NC='e[0m' # No Color
  21. export COLOR_WHITE='e[1;37m'
  22. export COLOR_BLACK='e[0;30m'
  23. export COLOR_BLUE='e[0;34m'
  24. export COLOR_LIGHT_BLUE='e[1;34m'
  25. export COLOR_GREEN='e[0;32m'
  26. export COLOR_LIGHT_GREEN='e[1;32m'
  27. export COLOR_CYAN='e[0;36m'
  28. export COLOR_LIGHT_CYAN='e[1;36m'
  29. export COLOR_RED='e[0;31m'
  30. export COLOR_LIGHT_RED='e[1;31m'
  31. export COLOR_PURPLE='e[0;35m'
  32. export COLOR_LIGHT_PURPLE='e[1;35m'
  33. export COLOR_BROWN='e[0;33m'
  34. export COLOR_YELLOW='e[1;33m'
  35. export COLOR_GRAY='e[0;30m'
  36. export COLOR_LIGHT_GRAY='e[0;37m'
  37.  
  38. case $TERM in
  39. xterm*|rxvt*)
  40. local TITLEBAR='[33]0;u ${NEW_PWD}07]'
  41. ;;
  42. *)
  43. local TITLEBAR=""
  44. ;;
  45. esac
  46.  
  47. local UC=$COLOR_WHITE # user's color
  48. [ $UID -eq "0" ] && UC=$COLOR_RED # root's color
  49.  
  50. PS1="$TITLEBARn[${UC}]u [${COLOR_LIGHT_BLUE}]${PWD} [${COLOR_BLACK}]$(vcprompt) n[${COLOR_LIGHT_GREEN}]→[${COLOR_NC}] "
  51.  
  52. # 'tput bold' will work regardless of the foreground and background colors.
  53. # Place the tput output into variables, so they are only execd once.
  54. bold=$(tput bold) # This could also be a color.
  55. reset=$(tput sgr0)
  56. export PS1="u@[$bold]h[$reset]:w $ "
  57.  
  58. # Set some options, based on the OS
  59. OS=`uname -s`
  60.  
  61. case "$OS" in
  62. "SunOS" )
  63. # Solaris ls doesn't allow color, so use special characters
  64. LS_OPTS='-F'
  65. alias ls='ls ${LS_OPTS}'
  66. ;;
  67. "Linux" )
  68. # GNU ls supports colors!
  69. # See dircolors to customize colors
  70. export LS_OPTS='--color=auto'
  71. alias ls='ls ${LS_OPTS}'
  72.  
  73. # Get color support for 'less'
  74. export LESS="--RAW-CONTROL-CHARS"
  75.  
  76. # Use colors for less, man, etc.
  77. [[ -f ~/.LESS_TERMCAP ]] && . ~/.LESS_TERMCAP
  78.  
  79. export GREP_OPTIONS="--color=auto"
  80.  
  81. ;;
  82. "Darwin"|"FreeBSD")
  83.  
  84. # Most FreeBSD & Apple Darwin supports colors
  85. export CLICOLOR=true
  86. # Get color support for 'less'
  87. export LESS="--RAW-CONTROL-CHARS"
  88.  
  89. # Use colors for less, man, etc.
  90. [[ -f ~/.LESS_TERMCAP ]] && . ~/.LESS_TERMCAP
  91.  
  92. export GREP_OPTIONS="--color=auto"
  93. ;;
  94. * )
  95. echo "Unknown OS [$OS]"
  96. ;;
  97. esac
  98.  
  99. git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/1/'; }
  100. HOST='33[02;36m]h'; HOST=' '$HOST
  101. TIME='33[01;31m]t 33[01;32m]'
  102. LOCATION=' 33[01;34m]`pwd | sed "s#(/[^/]{1,}/[^/]{1,}/[^/]{1,}/).*(/[^/]{1,}/[^/]{1,})/{0,1}#1_2#g"`'
  103. BRANCH=' 33[00;33m]$(git_branch)[33[00m]n$ '
  104. PS1=$TIME$USER$HOST$LOCATION$BRANCH
  105. PS2='[33[01;36m]>'
  106.  
  107. ls --color=al > /dev/null 2>&1 && alias ls='ls -F --color=al' || alias ls='ls -G'
  108.  
  109. function _colorman() {
  110. env
  111. LESS_TERMCAP_mb=$(printf "e[1;35m")
  112. LESS_TERMCAP_md=$(printf "e[1;34m")
  113. LESS_TERMCAP_me=$(printf "e[0m")
  114. LESS_TERMCAP_se=$(printf "e[0m")
  115. LESS_TERMCAP_so=$(printf "e[7;40m")
  116. LESS_TERMCAP_ue=$(printf "e[0m")
  117. LESS_TERMCAP_us=$(printf "e[1;33m")
  118. "$@"
  119. }
  120. function man() { _colorman man "$@"; }
  121. function perldoc() { command perldoc -n less "$@" |man -l -; }
  122.  
  123. GREP_OPTS='--color=auto' # for aliases since $GREP_OPTIONS is deprecated
  124. GREP_COLOR='1;32' # (legacy) bright green rather than default red
  125. GREP_COLORS="ms=$GREP_COLOR" # (new) Matching text in Selected line = green
  126. alias grep='grep $GREP_OPTS'
  127. alias egrep='egrep $GREP_OPTS'
  128. alias fgrep='fgrep $GREP_OPTS'
  129.  
  130. # use the config at ~/.dircolors if it exists, otherwise generate anew
  131. eval "$( dircolors --sh $(ls -d ~/.dircolors 2>/dev/null) )"
  132.  
  133. # Usage: _ls_colors_add BASE NEW [NEW...]
  134. # Have LS color given NEW extensions the way BASE extension is colored
  135. _ls_colors_add() {
  136. local BASE_COLOR="${LS_COLORS##*:?.$1=}" NEW
  137. if [ "$LS_COLORS" != "$BASE_COLOR" ]; then
  138. BASE_COLOR="${BASE_COLOR%%:*}"
  139. shift
  140. for NEW in "$@"; do
  141. if [ "$LS_COLORS" = "${LS_COLORS#*.$NEW=}" ]; then
  142. LS_COLORS="${LS_COLORS%%:}:*.$NEW=$BASE_COLOR:"
  143. fi
  144. done
  145. fi
  146. export LS_COLORS
  147. }
  148.  
  149. _ls_colors_add zip jar xpi # archives
  150. _ls_colors_add jpg ico JPG PNG webp # images
  151. _ls_colors_add ogg opus # audio (opus now included by default)
  152.  
  153. alias ls="ls -ph --color=auto"
  154.  
  155. # using this as a variable allows easier calling down lower
  156. export GRC='grc -es --colour=auto'
  157.  
  158. # loop through known commands plus all those with named conf files
  159. for cmd in g++ head ld ping6 tail traceroute6 `locate grc/conf.`; do
  160. cmd="${cmd##*grc/conf.}" # we want just the command
  161. # if the command exists, alias it to pass through grc
  162. type "$cmd" >/dev/null 2>&1 && alias "$cmd"="$GRC $cmd"
  163. done
  164.  
  165. # ./configure needs special handling: does it exist and is it executable?
  166. alias configure="[ -x ./configure ] && $GRC ./configure"
  167.  
  168. # GRC plus LS awesomeness (assumes you have an alias for ls)
  169. unalias ll 2>/dev/null
  170. if ls -ld --color=always / >/dev/null 2>&1; then GNU_LS=true; fi
  171. function ll() {
  172. local color= CLICOLOR_FORCE
  173. if [ -t 1 ] || [ "$CLICOLOR_FORCE" = true ]; then
  174. if [ -n "$GNU_LS" ]; then color="--color=always"; fi
  175. CLICOLOR_FORCE=true
  176. else
  177. CLICOLOR_FORCE=
  178. fi
  179. $GRC `alias ls |awk -F "'" '{print $2}'` -l $color ${1+"$@"}
  180. }
  181.  
  182. #!/usr/bin/perl
  183. use strict;
  184. use warnings;
  185.  
  186. open (DIFF, "-|", "diff", @ARGV) or die $!;
  187.  
  188. my $ydiff = 1;
  189. while (<DIFF>) {
  190. if (not -t 1) {
  191. print;
  192. next;
  193. }
  194. chomp;
  195. $ydiff = 0 if /^[ <>@+-]/ or ($. == 1 && /^d+[a-z]{1,5}d+$/);
  196. my $color = "";
  197. if (! $ydiff && /^[@+-<>]/) {
  198. $color = (/^[<-](?!--$)/ ? 1 : /^[+>]/ ? 2 : 5);
  199. } elsif ($ydiff && /t {6}([<|>])(?:t|$)/) {
  200. $color = ($1 eq "<" ? 1 : $1 eq ">" ? 2 : 4);
  201. }
  202. $color ? printf ("e[1;3%dm%se[0;0mn",$color,$_) : print "$_n";
  203. }
  204. close DIFF;
  205.  
  206. # Shorten home dir, cygwin drives, paths that are too long
  207. if [ -d /cygdrive ] && uname -a |grep -qi cygwin; then CYGWIN_OS=1; fi
  208. function PSWD() {
  209. local p="$*" space A B cols="${COLUMNS:-`tput cols 2>/dev/null || echo 80`}"
  210. p="${p/$HOME/~}" # shrink home down to a tilde
  211. if [ -n "$CYGWIN_OS" ] && [ "${p#/cygdrive/?/}" != "$p" ]; then
  212. p="${p:10:1}:${p:11}" # /cygdrive/c/hi -> c:/hi
  213. fi
  214. space="$((${#USER}+${#HOSTNAME}+6))" # width w/out the path
  215. if [ "$cols" -lt 60 ]; then echo -n "$N "; space=-29; p="$p$Nb"; fi
  216. if [ "$cols" -lt "$((space+${#p}+20))" ]; then # < 20 chars for the command
  217. A=$(( (cols-20-space)/4 )) # a quarter of the space (-20 for cmd)
  218. if [ $A -lt 4 ]; then A=4; fi # 4+ chars from beginning
  219. B=$(( cols-20-space-A*2 )) # half (plus rounding) of the space
  220. if [ $B -lt 8 ]; then B=8; fi # 8+ chars from end
  221. p="${p:0:$A}..${p: -$B}"
  222. fi
  223. echo "$p"
  224. }
  225.  
  226. PSC() { echo -ne "[33[${1:-0;38}m]"; }
  227. PR="0;32" # default color used in prompt is green
  228. if [ "$(id -u)" = 0 ]; then
  229. sudo=41 # root is red background
  230. elif [ "$USER" != "${SUDO_USER:-$USER}" ]; then
  231. sudo=31 # not root, not self: red text
  232. else sudo="$PR" # standard user color
  233. fi
  234. PROMPT_COMMAND='[ $? = 0 ] && PS1=${PS1[1]} || PS1=${PS1[2]}'
  235. PSbase="$(PSC $sudo)u$(PSC $PR)@h $(PSC 33)$(PSWD w)"
  236. PS1[1]="$PSbase$(PSC $PR)$ $(PSC)"
  237. PS1[2]="$PSbase$(PSC 31)$ $(PSC)"
  238. PS1="${PS1[1]}"
  239. unset sudo PR PSbase
  240.  
  241. if test $UID = 0
  242. then PS1="%B${PS1}%b "
  243. fi
  244.  
  245. if test $UID = 0
  246. then PS1="33[1m${PS1}33[0m"
  247. fi
  248.  
  249. #
  250. # Colorcodes
  251. #
  252. NORMAL=`echo -e '33[0m'`
  253. RED=`echo -e '33[31m'`
  254. GREEN=`echo -e '33[0;32m'`
  255. LGREEN=`echo -e '33[1;32m'`
  256. BLUE=`echo -e '33[0;34m'`
  257. LBLUE=`echo -e '33[1;34m'`
  258. YELLOW=`echo -e '33[0;33m'`
  259.  
  260.  
  261. #
  262. # command: ip
  263. # highlight ip addresses, default route and interface names
  264. #
  265.  
  266. IP4=$GREEN
  267. IP6=$LBLUE
  268. IFACE=${YELLOW}
  269. DEFAULT_ROUTE=$LBLUE
  270.  
  271. IP_CMD=$(which ip)
  272.  
  273. function colored_ip()
  274. {
  275. ${IP_CMD} $@ | sed
  276. -e "s/inet [^ ]+ /${IP4}&${NORMAL}/g"
  277. -e "s/inet6 [^ ]+ /${IP6}&${NORMAL}/g"
  278. -e "s/^default via .*$/${DEFAULT_ROUTE}&${NORMAL}/"
  279. -e "s/^([0-9]+: +)([^ t]+)/1${IFACE}2${NORMAL}/"
  280. }
  281.  
  282. alias ip='colored_ip'
  283.  
  284. echoc "@{lr}text output in light red"
  285. echoc "@{bLGu}text outpus in blue, light green background and underlined"
  286. echoc "you @{lr} can @{bLGu} mix @{-a} it all too"
  287. echoc -x "ls" #executes ls command and colorizes it automatically to be easy to be seen
  288.  
  289. python -m unittest discover -v
  290.  
  291. python -m unittest discover -v 2>&1 | colout '(.*ERROR$)|(.*FAIL$)|((.*))' red,yellow,black bold
  292.  
  293. #Set variables for foreground colors
  294. fgRed=$(tput setaf 1) ; fgGreen=$(tput setaf 2) ; fgBlue=$(tput setaf 4)
  295. fgMagenta=$(tput setaf 5) ; fgYellow=$(tput setaf 3) ; fgCyan=$(tput setaf 6)
  296. fgWhite=$(tput setaf 7) ; fgBlack=$(tput setaf 0)
  297. #Set variables for background colors
  298. bgRed=$(tput setab 1) ; bgGreen=$(tput setab 2) ; bgBlue=$(tput setab 4)
  299. bgMagenta=$(tput setab 5) ; bgYellow=$(tput setab 3) ; bgCyan=$(tput setab 6)
  300. bgWhite=$(tput setab 7) ; bgBlack=$(tput setab 0)
  301. #Set variables for font weight and text decoration
  302. B=$(tput bold) ; U=$(tput smul) ; C=$(tput sgr0)
  303. #NOTE: ${C} clears the current formatting
  304.  
  305. if [[ $USER = "root" ]]; then
  306. PS1="${B}${fgRed}u${C}@h(s): ${fgGreen}w${C} > "
  307. else
  308. PS1="${B}${fgCyan}u${C}@h(s): ${fgGreen}w${C} > "
  309. fi
  310.  
  311. user@host(bash): ~/bin >
  312.  
  313. sudo apt-get install colordiff
  314.  
  315. # if colordiff is installed, use it
  316. if type colordiff &>/dev/null ; then
  317. alias diff=colordiff
  318.  
  319. #normal=$(tput sgr0) # normal text
  320. normal=$'e[0m' # (works better sometimes)
  321. bold=$(tput bold) # make colors bold/bright
  322. red="$bold$(tput setaf 1)" # bright red text
  323. green=$(tput setaf 2) # dim green text
  324. fawn=$(tput setaf 3); beige="$fawn" # dark yellow text
  325. yellow="$bold$fawn" # bright yellow text
  326. darkblue=$(tput setaf 4) # dim blue text
  327. blue="$bold$darkblue" # bright blue text
  328. purple=$(tput setaf 5); magenta="$purple" # magenta text
  329. pink="$bold$purple" # bright magenta text
  330. darkcyan=$(tput setaf 6) # dim cyan text
  331. cyan="$bold$darkcyan" # bright cyan text
  332. gray=$(tput setaf 7) # dim white text
  333. darkgray="$bold"$(tput setaf 0) # bold black = dark gray text
  334. white="$bold$gray" # bright white text
  335.  
  336. echo "${red}hello ${yellow}this is ${green}coloured${normal}"
  337.  
  338. function coloredEcho(){
  339. local exp=$1;
  340. local color=$2;
  341. if ! [[ $color =~ '^[0-9]$' ]] ; then
  342. case $(echo $color | tr '[:upper:]' '[:lower:]') in
  343. black) color=0 ;;
  344. red) color=1 ;;
  345. green) color=2 ;;
  346. yellow) color=3 ;;
  347. blue) color=4 ;;
  348. magenta) color=5 ;;
  349. cyan) color=6 ;;
  350. white|*) color=7 ;; # white or invalid color
  351. esac
  352. fi
  353. tput setaf $color;
  354. echo $exp;
  355. tput sgr0;
  356. }
  357.  
  358. coloredEcho "This text is green" green
  359.  
  360. if [ "$TERM" = xterm ]; then TERM=xterm-256color; fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement