Archive
Archive for September, 2010
Dir/File space2score
2010-09-06
Leave a comment
I wrote this little script because I had to manage a task for creating a file naming scheme. It will replace all spaces in file names and subdirectories of a given directory with an underscore.
#!/bin/bash ##### ## Program: ## File/Directory Formatter ## Author: ## Kyle Rizzo ## lifeforce0 {at} gmail {dot} com ## https://lifeforce4.wordpress.com ## Summary: ## This little script will search though all files and subdirs of a given ## location then starting from the bottom up will replace ' '(spaces) with ## '_' underscores. ##### ## Coloring Schemes NC='\033[0;37m' RED='\033[1;31m' YELLOW='\033[1;33m' BLUE='\033[1;34m' CYAN='\033[1;36m' WHITE='\033[1;37m' ## Find only Files with spaces and replace the spaces with underscores #find $1 -depth -type f -name '* *' -print | while IFS= read -r file; do ## Find only Directories with spaces and replace the spaces with underscores #find $1 -depth -type d -name '* *' -print | while IFS= read -r file; do ## Find any files/directories from the given path if none specified used ./ ## and replace spaces with underscores in all names. find $1 -depth -name '* *' -print | while IFS= read -r file; do file=$file basedir=${file%/*} filename=${file##*/} newfilename=$(echo "$filename" | tr -s ' ' _) echo -en "\n$WHITE" echo -en "Renaming $CYAN$filename$WHITE to $YELLOW$newfilename$WHITE \ in $BLUE$basedir/" ## Check if the file is a directory or a file with in a directory. ## Set newfile accordingly if [ ! "$basedir" = "$file" ]; then newfile="$basedir/$newfilename" else newfile="./$newfilename" fi ## Check to see if a file exists with that name ## Refuse to over wright the file if it does. if [ ! -e "$newfile" ]; then mv "$file" "$newfile" else echo "$RED\Refusing to overwrite $BLUE$newfile" fi done echo -en "$NC\n"
Advertisements
Categories: Bash, Computers, Linux, Programming
Bash color code selector.
2010-09-03
Leave a comment
#!/bin/bash ##### ## Program: ## Linux Term Colors - bash script ## Author: ## Kyle Rizzo ## lifeforce0 {at} gmail {dot} com ## https://lifeforce4.wordpress.com ## Summary: ## This script will display all the different color combination's for a ## terminal tested on Bash 3.2.25(1). Then prompt the user with a menu ## that they can create their own color scheme. It will also display ## the escape sequence required to make that scheme. ## These special escape sequences can be used with any language for a ## linux terminal. ## ## "\E[" begins the escape sequence, you can also use "\033" or "\x1B". ## ## Semicolon-separated numbers "HEW" "COLOR1" and "COLOR2". ## Note: The foreground and background numbers do not overlap so order ## does not matter, for formatting reasons I will have it always ## be Foreground then Background. ## ## "m" terminates the escape sequence, the text begins immediately after. ## ## FG hew bit: 0/1 (dark/light) ## Foreground Colors: 3x ## Background Colors: 4x ## ## x representing a different color ## 0 = Black 1 = Red ## 2 = Green 3 = Yellow ## 4 = Blue 5 = Magenta ## 6 = Cyan 7 = White ##### NC="\e[0;37;40m" ## No Color (reset to default) SELECTION=0 ## The user selection of the menu FGBOLD=0 ## Default foreground bold/lightness FGCOLOR=37 ## Default foreground color 'gray' BGCOLOR=40 ## Default background color 'black' ENDM="m" ## End the escape sequence menu () { echo -en "Menu)\n\t\ 1) Display color table\n\t\ 2) Set foreground color \n\t\ 3) Set background color \n\t\ 4) Display selected colors \n\t\ 5) Quit\n> "; read -e SELECTION; } displayTable () { echo -en "B;FG;BG\t"; for i in {40..47}; do echo -en " $i\t"; done echo; for fg in {30..37}; do for h in {0..1}; do echo -en "$NC$h;$fg"; for bg in {40..47}; do echo -en "\t\e[$h$ENDM\e[$fg$ENDM\e[$bg$ENDM RgB "; done echo; done done ## Reset the console to no colors. echo -e $NC; } setFG () { displayTable echo -en "Set the foreground color number [3x]: "; read -e FGCOLOR; echo -en "Light|Bold text y/n: "; read -e FGBOLD; if [ "$FGBOLD" == "Y" ] || [ "$FGBOLD" == "y" ]; then FGBOLD=1 else FGBOLD=0 fi } setBG () { displayTable echo -en "Set the background color number [4x]: "; read -e BGCOLOR; } testColors () { echo -en " \e[$FGBOLD;$FGCOLOR;$BGCOLOR$ENDM"; echo -en " This is a test of the colors you selected."; echo -en "$NC \\"; echo -en "e[$FGBOLD;$FGCOLOR;$BGCOLOR$ENDM\n"; echo -e "$NC========================================================\n\ Press enter if you can not read the text above the line."; } main () { while [ "$SELECTION" -ne 5 ] do menu case "$SELECTION" in 1 ) clear; displayTable ;; 2 ) clear; setFG ;; 3 ) clear; setBG ;; 4 ) clear; testColors ;; 5 ) exit 0;; * ) clear; menu esac done } displayTable main
Categories: Bash, Computers, Linux, Programming
Linux terminal/bash color code C++, Perl, Bash
2010-09-03
Leave a comment
C++
/****************************************************************************** * Program: * Linux Term Colors * Author: * Kyle Rizzo * lifeforce0 {at} gmail {dot} com * https://lifeforce4.wordpress.com * Summary: * This loops though all the font colors on each background for a linux * terminal. Tested on Bash 3.2.25(1). These special escape sequences can * be used with any language for a linux terminal. See my bash and perl * code for other examples of the same output. * * "\E[" begins the escape sequence, you can also use "\033" or "\x1B". * * You can use a semicolon to separated the numbers * (eg 1;30;46 = Bold font (making it lighter in color) * FG as Black (bolding it makes it a dark gray) * BG as Cyan ) * Note: The foreground and background numbers do not overlap so order * does not matter, for formatting reasons I will have it always * be Text-format / Foreground / Background. * * "m" terminates the escape sequence, the text begins immediately after. * * FG hew bit: 0/1 (dark/light) * Foreground Colors: 3x * Background Colors: 4x * * x representing a different color * 0 = Black 1 = Red * 2 = Green 3 = Yellow * 4 = Blue 5 = Magenta * 6 = Cyan 7 = White ******************************************************************************/ #include <iostream> using namespace std; // Set a few standards to make formatting easier. const string NC = "\E[0m"; // No Color (reset to default) const string HOME_CURSOR = "\E[0;0H"; // Place the cursor at 0;0 position. const string CLEAR_SCREEN = "\E[2J"; /****************************************************************************** * Loop though each background color for both normal and bold fonts of a given * color. ******************************************************************************/ int main(int argc, char **argv) { // Clear the screen and reset the cursor to the top left. cout << CLEAR_SCREEN << HOME_CURSOR; // print program name. cout << endl << argv[0] << endl; // display the color table. cout << "B;FG;BG\t"; for (int i = 40; i < 48; i++) cout << " " << i << "m\t"; cout << endl; for (int fg = 30; fg < 38; fg++) for (int h = 0; h < 2; h++) { cout << NC << h << ";" << fg << "m"; for (int bg = 40; bg < 48; bg++) { cout << "\t" << "\E[" << h << "m" << "\E[" << fg << "m" << "\E[" << bg << "m" << " RgB "; } cout << endl; } // Reset the console to no colors. cout << NC << endl; return 0; }
Perl
#!/use/bin/perl ##### ## Program: ## Linux Term Colors - perl script ## Author: ## Kyle Rizzo ## lifeforce0 {at} gmail {dot} com ## https://lifeforce4.wordpress.com ## Summary: ## This loops though all the font colors on each background for a linux ## terminal. Tested on Bash 3.2.25(1). These special escape sequences can ## be used with any language for a linux terminal. See my bash and C++ ## code for other examples of the same output. ## ## "\E[" begins the escape sequence, you can also use "\033" or "\x1B". ## ## Semicolon-separated numbers "HEW" "COLOR1" and "COLOR2". ## Note: The foreground and background numbers do not overlap so order ## does not matter, for formatting reasons I will have it always ## be Foreground then Background. ## ## "m" terminates the escape sequence, the text begins immediately after. ## ## FG hew bit: 0/1 (dark/light) ## Foreground Colors: 3x ## Background Colors: 4x ## ## x representing a different color ## 0 = Black 1 = Red ## 2 = Green 3 = Yellow ## 4 = Blue 5 = Magenta ## 6 = Cyan 7 = White ##### ## Set a few standards to make formatting easier. my $NC = "\e[0;37;40m"; ## No Color (reset to default) print "\n$0\n"; print "B;FG;BG\t"; foreach $i (40..47) { print " " . $i . "m\t"; } print "\n"; foreach $fg (30..37) { foreach $h (0..1) { print $NC . $h . ";" . $fg . "m"; foreach $bg (40..47) { print "\t" . "\e[" . $h . "m" . "\e[" . $fg . "m" . "\e[" . $bg . "m" . " RgB "; } print "\n"; } } ## Reset the console to no colors. print $NC . "\n";
Bash
#!/bin/bash ##### ## Program: ## Linux Term Colors - bash script ## Author: ## Kyle Rizzo ## lifeforce0 {at} gmail {dot} com ## https://lifeforce4.wordpress.com ## Summary: ## This loops though all the font colors on each background for a linux ## terminal. Tested on Bash 3.2.25(1). These special escape sequences can ## be used with any language for a linux terminal. See my perl and C++ ## code for other examples of the same output. ## ## "\E[" begins the escape sequence, you can also use "\033" or "\x1B". ## ## Semicolon-separated numbers "HEW" "COLOR1" and "COLOR2". ## Note: The foreground and background numbers do not overlap so order ## does not matter, for formatting reasons I will have it always ## be Foreground then Background. ## ## "m" terminates the escape sequence, the text begins immediately after. ## ## FG hew bit: 0/1 (dark/light) ## Foreground Colors: 3x ## Background Colors: 4x ## ## x representing a different color ## 0 = Black 1 = Red ## 2 = Green 3 = Yellow ## 4 = Blue 5 = Magenta ## 6 = Cyan 7 = White ##### ## Set a few standards to make formatting easier. NC="\e[0;37;40m"; ## No Color (reset to default) echo; echo "$0"; echo -en "B;FG;BG\t"; for i in {40..47}; do echo -en " $i"; echo -en "m\t"; done echo; for fg in {30..37}; do for h in {0..1}; do echo -en "$NC$h;$fg"; echo -en "m"; for bg in {40..47}; do echo -en "\t"; echo -en "\e[$h"; echo -en "m"; echo -en "\e[$fg"; echo -en "m"; echo -en "\e[$bg"; echo -en "m"; echo -en " RgB "; done echo; done done ## Reset the console to no colors. echo -e $NC;
Categories: Bash, C++, Linux, Perl, Programming
A more complete VGA Resolutions list for GRUB and LILO.
2010-09-02
Leave a comment
I created this list a few months ago because there just wasn’t enough information online for the different frame buffer codes at different resolutions. You can find the original post here at: My Blog at LinuxQuestions.org
This is what I have figured out so far if you know the codes for the settings where there are question marks(?) please PM me (on linuxquestions.org) and I will update this list. Hopefully someone fines it and feels its useful. I always wondered about it with my computers being setup with GRUB’s VGA modes.
Width-Height-Depth | VGA:Codes | HEX:Codes |
80×25(TEXT) | 3840 | 0F00 |
80×50(TEXT) | 3841 | 0F01 |
80×43(TEXT) | 3842 | 0F02 |
80×28(TEXT) | 3843 | 0F03 |
80×30(TEXT) | 3845 | 0F05 |
80×34(TEXT) | 3846 | 0F06 |
80×60(TEXT) | 3847 | 0F07 |
Width-Height-Depth | VGA:Codes | HEX:Codes |
320x200x8 | 816 | 0330 |
320x200x16 | 782 | 030E |
320x200x32 | 783 | 030F |
320x240x8 | 820 | 0334 |
320x240x16 | 821 | 0335 |
320x240x32 | 822 | 0336 |
320x400x8 | 817 | 0331 |
320x400x16 | 818 | 0332 |
320x400x32 | 819 | 0333 |
640x400x8 | 768 | 0300 |
640x400x16 | 829 | 033d |
640x400x32 | 830 | 033e |
Width-Height-Depth | VGA:Codes | HEX:Codes |
640x480x8 | 769 | 0301 |
640x480x16 | 785 | 0311 |
640x480x32 | 786 | 0312 |
768x480x8 | 866 | 0362 |
768x480x16 | ??? | ???? |
768x480x32 | ??? | ???? |
800x600x8 | 771 | 0303 |
800x600x16 | 788 | 0314 |
800x600x32 | 789 | 0315 |
Width-Height-Depth | VGA:Codes | HEX:Codes |
1024x768x8 | 773 | 0305 |
1024x768x16 | 791 | 0317 |
1024x768x32 | 792 | 0318 |
1280x800x8 | 864 | 0360 |
1280x800x16 | ??? | ???? |
1280x800x32 | 865 | 0361 |
1440x900x8 | 868 | 0364 |
1440x900x16 | ??? | ???? |
1440x900x32 | 869 | 0365 |
Categories: Linux