Tag Info

New answers tagged

1

Another script like the one posted by TAFKA 'goldilocks' for displaying colors which is maybe a little more practical for reference purposes: #!/bin/bash useage() { printf "\n\e[1;4mAscii Escape Code Helper Utility\e[m\n\n" printf " \e[1mUseage:\e[m colors.sh [-|-b|-f|-bq|-fq|-?|?] [start] [end] [step]\n\n" printf "The values for the first parameter ...


7

Those are ANSI escape sequences; that link is to a chart of color codes but there are other interesting things on that wikipedia page as well. Not all of them work on (e.g.) a normal linux console. This is incorrect: \033]00m\] # white 0 resets the terminal to its default (which is probably white). The actual code for white foreground is 37. ...


2

Looks like at least some of the list is: txtblk='\e[0;30m' # Black - Regular txtred='\e[0;31m' # Red txtgrn='\e[0;32m' # Green txtylw='\e[0;33m' # Yellow txtblu='\e[0;34m' # Blue txtpur='\e[0;35m' # Purple txtcyn='\e[0;36m' # Cyan txtwht='\e[0;37m' # White bldblk='\e[1;30m' # Black - Bold bldred='\e[1;31m' # Red bldgrn='\e[1;32m' # Green bldylw='\e[1;33m' # ...


0

I came up with the following shell function: hash_string256() { # Hash $1 into a number hash_value=$(printf "%s" "$1" | md5sum |tr -d " -"| tr "a-f" "A-F") # Add the hash with $2 and modulo 256 the result # if $2 == "" it is 0 printf "ibase=16; (%s + %X) %% 100\n" $hash_value "$2" | bc } This function can be used like this (The results ...


7

Trying to run source-highlight as suggested in the linked question produces this error: $ source-highlight -o STDOUT -i .bashrc --out-format=esc source-highlight: could not find a language definition for input file .bashrc That's because .bashrc is not recognized automatically by source-highlight, a quick look through its manual shows that it has the -s ...


0

The problem is of course with column not differentiating between printing and non-printing characters, bash gets around this in its prompt (PS1) with its \[ \] escape feature, I don't know of anything else that does exactly that. I tried a quick and nasty hack, given that your problematic field is at the start of the line, move it to the then end, but you ...


1

I don't think there's such a command, you'd have to do by hand. Something like: awk ' { nf[NR]=NF for (i = 1; i <= NF; i++) { f[NR,i] = $i gsub(/\033\[[0-9;]*[mK]/, "", $i) len[NR,i] = l = length($i) if (l > max[i]) max[i] = l } } END { for (n = 1; n <= NR; n++) { for (i = 1; i < nf[n]; i++) ...


0

Your terminal must support 256-colors and have appropriate TERM environment variable set. You likely do not have 256-color support enabled. For xterm: export TERM="xterm-256color" For urxvt: export TERM="urxvt-256color" For tmux/screen: export TERM="screen-256color" I would place it in ~/.bashrc, ~/.bash_profile or ~/.profile depending on ...


0

Some sed work would do the trick: a sed to remove ANSI color codes sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" a sed to replace space(s) with tabs sed -r "s/\s+/\t/g" Finaly: printf "\033[0;32;1mgreen_apple\033[0m 1 100 orange 20 19 pineapple 1000 87 avocado 4 30" \ | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" \ | sed -r ...


1

If you want a wrapper script for ls that works on all systems, abstracting away these color differences etc. see: http://www.pixelbeat.org/scripts/l



Top 50 recent answers are included