How can I define custom colors for use in ZSH prompt? - configuration

I'm having some difficulty configuring my zsh prompt. Specifically I would like the font to have the color defined by the hex code: #87afdf
Currently, I've set up the prompt as follows:
PROMPT='%B[%d]
➞ %b'
I've attempted to add colors in the following way:
autoload -U colors && colors
PROMPT='%{$fg[#87afdf]%}%B[%d]
➞ %b%{$reset_color%}'
But this only gives me the following gibberish:
$fg[#87afdf][/Users/gregory]
➞ $reset_color
Any ideas on how to proceed would be very much appreciated.

You have to use a 256-color palette. You can see the numerical values for each of the 256 colors in ZSH using the following command:
for code in {000..255}; do print -P -- "$code: %F{$code}Color%f"; done
The same for bash:
for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Color"; done

Solution for Oh-My-Zsh users
How to print available colors
As already mentioned you have to use a 256-color palette.
The easiest way to see which colors are available is to use the following command (as ZSH uses spectrum underneath):
spectrum_ls
it will print all available colors
...
How to use color in Oh-my-zsh theme
To use color in your theme you have to write it like $FG[<0-255>] for example $FG[172]
Upper case might be important there as $fg[172] does not work on my console!
Possible problem
Your terminal might support only 8 colors instead of 256. If it is true you will not see all the colors after executing spectrum_ls.
In such case you have to configure your terminal to support 256 colors.
Source
https://dev.to/yujinyuz/custom-colors-in-oh-my-zsh-themes-4h13

Unless you're using a very unusual terminal, you can't use just any color combination that you would like. Standard terminals are limited to (at best) a 256-color palette.
The colors function which ships with zsh is simply to allow the colors from the old 16-color palette to be referred to by name, it will not help in using colors outside of that range.
There is a simple script available which will setup $FG and $BG arrays to provide a way to use colors from the 256-color palette by number, but without needing to deal with the escape sequences necessary for the terminal to deal with those.

Related

How can I change specific recurring text on a very large HTML file?

I have a very big HTML file (talking about 20MB) and I need to remove from the file a large amount of nodes of the form:
<tr><td>SPECIFIC-STRING</td><td>RANDOM-STRING</td><td>RANDOM-STRING</td></tr><tr><td style="padding-top:0" colspan="3">RANDOM-STRING</td></tr>
The file I need to work on is basically made of thousands of these strings, and I only need to remove those that have a specific first string, for instance, all those with the first string being "banana":
<tr><td>banana</td><td>RANDOM-STRING</td><td>RANDOM-STRING</td></tr><tr><td style="padding-top:0" colspan="3">RANDOM-STRING</td></tr>
I tried achieving this opening the file in Geany and using the replace feature with this regex:
<tr><td>banana<\/td><td>(.*)<\/td><td>(.*)<\/td><\/tr><tr><td(.*)<\/td><\/tr>
but the console output was that it removed X amount of occurrences, when I know there are way more occurrences than that in the file.
Firefox, Chrome and Brackets fail even to view the html code of the file due to it's size. I can't think of another way to do this due to my large unexperience with HTML.
You could be using a stream editor which as the name suggest streams the file content, thus never loads the whole file into the main memory.
A popular editor is sed. It does support RegEx.
Your command would have the following structure.
sed -i -E 's/SEARCH_REGEX/REPLACEMENT/g' INPUTFILE
-E for support of extended RegEx
-i for in-place editing mode
s denotes that you want to replace values
g is for global. By default sed would only replace the first occurrence so to replace all occrrences you must provide g
SEARCH_REGEX is the RegEx you need to find the substrings you want to replace
REPLACEMENT is the value you want to replace all matches with
INPUTFILE is the file sed is gonna read line-by line and do the replacement for you.
While regex may not be the best tool to do this kinda job, try this adjustment to your pattern:
<tr><td>banana<\/td><td>(.*?)<\/td><td>(.*?)<\/td><\/tr><tr><td(.*?)<\/td><\/tr>
That's making your .* matches lazy. I am wondering if those patterns are consuming too much.

Sublime Text - find all instances of an html class name project-wide

I want to find all instances of a class named "validation" in all of my html files project wide. It's a very large project and a search for the word "validation" gives me hundreds of irrelevant results (js functions, css, js/css minified, other classes, functions and html page content containing the word validation, etc). It can sometimes be the second, third, or fourth class declared so searching for "class='validation" doesn't work.
Is there a way to specify that I only want results where validation is a class declared on an html block?
Yes. In the sublime menu go to Find --> Find in Files...
Then match what is in the following image.
The first thing you will want to do is consider other possibilities with how you can solve this problem. Currently, it sounds like you are only using sublime text. Have you considered trying to use a command-line tool like grep?
Here is an example of how it could be used.
I have a project called enfold-child with a bunch of frontend assets for a wordpress project. Let's say, I want to find all of my scss files with the class "home" listed in them somewhere, but I do NOT want to pull in built css files, or anything in my node_modules folder. The way i would do that is as follows:
Folder structure:
..
|build
|scss_files
|node_modules
|css_files
|style.css
grep -rnw build --exclude=*{.css} --exclude-dir=node_modules -e home
grep = handy search utility.
-r = recursive search.
-n = provide line numbers for each match
-w = Select only those lines containing matches that form whole words.
-e = match against a regular expression.
home = the expression I want to search for.
In general, the command line has most anything one could want/need to do most of the nifty operations offered by most text-editors -- such as Sublime. Becoming familiar with the command line will save you a bunch of time and headaches in the future.
In SublimeText, right-click on the folder you want to start the search from and click on Find in Folder. Make sure regex search is enabled (the .* button in the search panel) and use this regex as the search string:
class="([^"]+ )?validation[ "]
That regex will handle cases where "validation" is the only classname as well as cases where its one of several classnames (in which case it can be anywhere in the list).
If you didn't stick to double quotes, this version will work with single or double quotes:
class=['"]([^'"]+ )?validation[ '"]
If you want to use these regexes from the command line with grep, you'll need to include a -E argument for "extended regular expressions".

How to add html attributes and values for all lines quickly with vim and plugins?

My os:debian8.
uname -a
Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07) x86_64 GNU/Linux
Here is my base file.
home
help
variables
compatibility
modelines
searching
selection
markers
indenting
reformatting
folding
tags
makefiles
mapping
registers
spelling
plugins
etc
I want to create a html file as bellow.
home
help
variables
compatibility
modelines
searching
selection
markers
indenting
reformatting
folding
tags
makefiles
mapping
registers
spelling
plugins
etc
Every line was added href and id attributes,whose values are line content pasted .html and line content itself correspondingly.
How to add html attributes and values for all lines quickly with vim and plugins?
sed,awk,sublime text 3 are all welcomed to solve the problem.
$ sed 's:.*:&:' file
home
help
variables
compatibility
modelines
searching
selection
markers
indenting
reformatting
folding
tags
makefiles
mapping
registers
spelling
plugins
etc
if you want to do this in vi itself, no plug-in neccessary
Open the file, type : and insert this line as the command
%s:.*:&
it will make all the substitutions in the file.
sed is the best solution (simple and pretty fast here) if your are sure of the content, if not it need a bit of complexity that is better treated by awk:
awk '
{
# change special char for HTML constraint
Org = URL = HTML = $0
# sample of modification
gsub( / /, "%20", URL)
gsub( /</, "%3C", HTML)
printf( "%s\n", URL, Org, HTML)
}
' YourFile
To complete this easily in Sublime Text, without any plugins added:
Open the base file in Sublime Text
Type Ctrl+Shift+P and in the fuzzy search input type syn html to set the file syntax to HTML.
In the View menu, make sure Word Wrap is toggled off.
Ctrl+A to select all.
Ctrl+Shift+L to break selection into multi-line edit.
Ctrl+C to copy selection into clipboard as multiple lines.
Alt+Shift+W to wrap each line with a tag-- then tap a to convert the default <p> tag into an <a> tag (hit esc to quit out of any context menus that might pop up)
Type a space then href=" -- you should see this being added to every line as they all have cursors. Also you should note that Sublime has automatically closed your quotes for you, so you have href="" with the cursor between the quotes.
ctrl+v -- this is where the magic happens-- your clipboard contains every lines worth of contents, so it will paste each appropriate value into the quotes where the cursor is lying. Then you simply type .html to add the extension.
Use the right arrow to move the cursors outside of the quotes for the href attribute and follow the two previous steps to similarly add an id attribute with the intended ids pasted in.
Voila! You're done.
Multi-line editing is very powerful as you learn how to combine it with other keyboard shortcuts. It has been a huge improvement in my workflow. If you have any questions please feel free to comment and I'll adjust as needed.
With bash one-liner:
while read v; do printf '%s\n' "$v" "$v" "$v"; done < file
(OR)
while read v; do echo "$v"; done < file
Try this -
awk '{print a$1b$1c$1d}' a='' d='' file
home
help
variables
compatibility
modelines
searching
selection
markers
indenting
reformatting
folding
tags
makefiles
mapping
registers
spelling
plugins
etc
Here I have created 4 variable a,b,c & d which you can edit as per your choice.
OR
while read -r i;do echo ""$i";done < f
home
help
variables
compatibility
To execute it directly in vim:
!sed 's:.*:&:' %
In awk, no regex, no nothing, just print strings around $1s, escaping "s:
$ awk '{print "" $1 ""}' file
home
help
If you happen to have empty lines in there just add /./ before the {:
/./{print ...
list=$(cat basefile.txt)
for val in $list
do
echo ""$val"" >> newfile.html
done
Using bash, you can always make a script or type this into the command line.
This vim replacement pattern handles your base file:
s#^\s*\(.\{-}\)\s*$#\1#
^\s* matches any leading spaces, then
.\{-} captures everything after that, non-greedily — allowing
\s$ to match any trailing spaces.
This avoids giving you stuff like home .
You can also process several base files with vim at once:
vim -c 'bufdo %s#^\s*\(.\{-}\)\s*$#\1# | saveas! %:p:r.html' some.txt more.txt`
bufdo %s#^\s*\(.\{-}\)\s*$#\1# runs the replacement on each buffer loaded into vim,
saveas! %:p:r.html saves each buffer with an html extension, overwriting if necessary,
vim will open and show you the saved more.html, which you can correct as needed, and
you can use :n and :prev to visit some.html.
Something like sed’s probably best for big jobs, but this lets you tweak the conversions in vim right after it’s made them, use :u to undo, etc. Enjoy!

How can I disable Vim's HTML error highlighting?

I use Vim to edit HTML with embedded macros, where the macros are bracketed with double angle brackets, e.g., "<>". Vim's standard HTML highlighting sees the second "<" and ">" as errors, and highlights them as such. How can I prevent this? I'd be happy to either teach $VIMHOME/syntax/html.vim that double-angle-brackets are OK, or to simply disable the error highlighting, but I'm not sure how to do either one. ("highlight clear htmlTagError" has no effect. In fact, "highlight clear" has no effect in an HTML buffer.)
If you want to introduce full syntax highlighting in your macros, it'll be easiest to start with a syntax file like htmldjango ($VIMRUNTIME/syntax/htmldjango.vim, which then uses html.vim and django.vim from the same directory); in it, there is special meaning in {{ ... }}, among other things. You want it just the same, but with << and >> being your delimiters.
To just highlight << ... >> specially, you'd need a syntax line like this:
syntax region mylangMacro start="<<" end=">>" containedin=ALLBUT,mylangMacro
And then you could highlight it with:
highlight default link mylangMacro Macro
This could either go in ~/.vim/after/syntax/html.vim or could be done in the style of htmldjango as a new syntax highlighter (this would be my preferred approach; you can then make HTML files use this new syntax file with an autocmd).
(You can also remove the error highlighting with syntax clear htmlTagError which would go in the same sort of position. But hopefully you'll think getting separate highlighting is better than just removing the error.)
Here are instructions to edit existing syntax highlighting in Vim:
http://vimdoc.sourceforge.net/htmldoc/syntax.html#mysyntaxfile-add
vim runtime paths for Unix/Linux:
$HOME/.vim,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
$HOME/.vim/after
Create a directory in your vim runtime path called "after/syntax".
Commands for Unix/Linux:
mkdir ~/.vim/after
mkdir ~/.vim/after/syntax
Write a Vim script that contains the commands you want to use. For example, to change the colors for the C syntax: highlight cComment
ctermfg=Green guifg=Green
Write that file in the "after/syntax" directory. Use the name of the syntax, with ".vim" added. For our C syntax: :w
~/.vim/after/syntax/c.vim
That's it. The next time you edit a C file the Comment color will be
different. You don't even have to restart Vim.
If you have multiple files, you can use the filetype as the directory
name. All the "*.vim" files in this directory will be used, for
example: ~/.vim/after/syntax/c/one.vim ~/.vim/after/syntax/c/two.vim
Alternatively, you could take a much easier route and use syntax highlighting within the Nano command line editor, which you can define your own syntax very easily with regular expressions:
http://how-to.wikia.com/wiki/How_to_use_syntax_highlighting_with_the_GNU_nano_text_editor

MySQL the command line and pagers

I cant find anything about this from searching here.
I use mysql on the command line at work and I work with fairly large tables so I set the mysql pager allowing a more readable result if I run a query, that returns 1000's of results. I use the command below to set the pager.
\P less -Sin
This suits my needs but has left me wondering if there are any more pager styles that mysql uses on the command line.
The MySQL client just passes its output to whatever command you specify with \P (for "Pager").
-Sin are commandline switches to the program less. From man less:
-i Causes searches to ignore case
-n Suppresses line numbers
-S Causes lines longer than the screen width to be chopped rather than folded.
For more options of the MySQL client, see reference.
mysql> pager less
PAGER set to 'less'
You might want to try pspg:
Unix pager designed for work with tables. Designed for PostgreSQL, but MySQL is supported too.
Main target
possibility to freeze first few rows, first few columns
possibility to use fancy colors - like mcview or FoxPro
In action:
This post is old, but still very helpful.
You can set the pager to whatever you want, including a script that parses all output before feeding it back to you. The examples there include using an add-on tool that makes EXPLAIN output more readable.
Also note that to turn off this functionality and return to normal stdout the command is nopager.
If you don't like less you can use more :)
\P more