htaccess - prettify a minified version - .htaccess

I have an .htaccess with a good number of redirects. After being modified by a Wordpress plugin, it appears that all the rules have been concatenated; at least no line breaks are visible.
Edit:
This seems to be a problem only when the file is opened in Windows Notepad. When I open it with Sublime, or even copy a snippet to here, it shows the line breaks. I toggled line-wrap in Notepad, but it still treats the whole thing as a single line.

This seems to be a problem only when the file is opened in Windows Notepad.
This is because the file has non-Windows line endings (\r\n), but probably Linux line endings (\n). Windows Notepad only recognizes Windows line endings.
You can use Notepad++ to convert line endings, but this does not stop Wordpress to apply the linux line endings, obviously.

Related

Possible to use git on cross-OS network share?

We have a few work flows where we want to use git repositories mounted on NFS network shares. This generally works well, with the exception of line endings. Obviously, line endings on Linux and Windows differ, so a git status on the CentOS host may show no changes, and a git status in the same directory on Windows shows all files as modified.
Can any of the various git mechanisms to deal with line endings be configured to support this scenario ? We only want Unix-style line endings in our repos, of course, and we don't really care about the Windows SEEING the Unix line endings, but on occasion, a Windows tool will add or accidentally convert files, which we would then not want checked in with those endings.
There are a couple possible solutions here. The best solution depends on whether you care about the endings in the working tree.
If you always want line endings in the repository to be LF, and you don't care about the working tree, you can set the following in the .gitattributes file in your repository (creating it if it doesn't exist):
* text=auto
That will make Git guess whether a given file is binary or text, and if it's text, it will perform conversion to the proper line endings when it's checked out. On Unix, the proper line endings will be LF, and on Windows, usually it will be CRLF (although you can use core.eol to override that).
If you always want line endings in both the objects and the working tree to be LF, then you need to do a little more work. You need to set each individual text file type appropriately with eol=lf:
*.c text eol=lf
*.h text eol=lf
The reason this is necessary is because eol=lf overrides text detection, which means it's not safe to apply to binary files, such as PDFs or JPEG files. If you applied it to all files in your repository, you'd corrupt any binary files that happened to contain a CRLF.
Regardless of which you do, you should do a git add --renormalize . and then a git commit. That will ensure that all of your files in the repository contain LF endings and they'll be checked out with the appropriate endings whenever Git checks them out. That doesn't prevent Windows tools from dirtying the repository with CRLF line endings, but if they do that by accident, only LF endings will be checked in.

Configuration file pulled from S3 segfaults OpenSwan

I'm trying to configure OpenSwan, an open source IPsec solution written in C.
I have a script to download a configuration file ipsec.conf on an Amazon Linux EC2 that was created on my Macbook and uploaded to S3.
When I start the ipsec service, it segfaults.
Curiously, if I open the configuration file with VIM, make no changes, and simply write/quit, it works. This lends me to believe somehow the file has some weird characters/formatting.
I know of dos2unix, which I ran on the configuration file but that did not prevent the segfault.
I'm wondering what exactly VIM is doing when I write/quit. I could script that operation on my configuration file after pulling it. Or anything else that would help me understand what's going on.
First, try to open the file with vim, then exit vim (:q) without having saved the file before. If vim says File modified since last complete write; write or use ! to override., this means that this is not something that vim does when write/quit that changes your file, but that this is something that vim does when it opens the file. And this is the most common case.
Vim parses the input file depending on the locale, and if some characters can not be understood according to the locale, vim may forget them. So, when saving the file, those characters will be removed.
Now, use vim to save your file as ipsec-ok.conf.
And run the following command:
bash -c 'diff <(od -xa ipsec.conf) <(od -xa ipsec-ok.conf)'
This will display the differences between the original file and the one that works with OpenSwan. In ascii and hexadecimal formats. This way, you will find the unsupported characters that make OpenSwan dump a core.

what does charcter ^G mean in vim?

I open an XML file in Vim and found that there are a lot of ^M and ^G symbols showen in it.So I try to use dos2unix to drop the ^M symbols,but it told me that the file is binary file, which makes it skipping the file.After drop the ^G symbols manunally, dos2unix is successfully process that file. My question is: what does ^G actually mean here ? Is it ^G in a file makes it a binary file?
^G is the bell character. When the file is displayed on a traditional terminal, you will hear a beep when you reach that character. There is no difference between "binary" and "text" files, really, so dos2unix is just guessing, and in this case guessing wrong. You can use the option -f to force it to convert files it thinks are binary.
To add to the above answer, Ctrl-M is also usually an end-of-line / linebreak character corresponding to the "\r\n" carriage return used by Windows.
You can read more about in the answers to this question, which include some methods of converting them to unix-style line endings (if you need to): What does ^M character mean in Vim?

Syncing vimrc and plugins between unix and windows machine

I am using the method described in this screencast to keep my vimrc and plugins synced across multiple machines. The problem I'm running into is that one machine is running ubuntu and the other running win7.
I've found two types of problems so far. The first seems to be with line endings. To get my windows vimrc to be read on the linux box, I had to do :set fileformat=unix and write. But even after doing that, I am getting similar line-ending problems with all the plugins:
jg#jg-VirtualBox:~$ vim ~/.vimrc
Error detected while processing /home/jg/.vimrc:
line 11:
E484: Can't open file /home/jg/vimfiles/plugin/autotag.vim
Error detected while processing /home/jg/.vim/plugin/DrawIt.vim:
line 60:
E492: Not an editor command: ^M
line 62:
E15: Invalid expression: &cp^M
line 1290:
E171: Missing :endif
Error detected while processing /home/jg/.vim/plugin/auto_number.vim:
line 5:
E488: Trailing characters
I could do something like vim ~/.vim/**/*.vim to load them all and then :argdo set ff=unix | w to fix all the files in the same way, but that seems like a poor method, since any time I update the git repo with my vimfiles from one computer and pull it from the other, I'll have to remember to do this file conversion. Is there a better way?
Finally, certain configuration details in the vimrc, such as the location of the location of certain binaries, will be different depending on the OS. What is the best way to handle these differences? Should I be peppering my .vimrc with if statements branching on has("gui_win32"), or is there a better way?
Thanks!
Yes, you'll have to add branches in your vimrc to have machine/OS-specific settings. That's not as dirty as it sounds: a single if/ifelse/endif is enough.
Another approach is to keep your machine/OS specific settings in a separate non-version-controled file: because it is very localized, you don't need to propagate its contents on other machines/OSes.
You could put these settings in ~/.vim/vimrc.local and explicitely add this file to .gitignore or outside of the repo in ~/.vimrc.local and source that file from your vimrc.
Vim has troubles with Windows line endings on Linux but it doesn't have troubles dealing with Linux line endings on Windows. Just use Linux line endings everywhere and you'll be fine.

SVN incosistent eol when adding file

Quiet simply I am trying to add new files to my repository, my command goes like this:
svn add * --force
but this produces:
svn: File 'install/config.xml.php' has inconsistent newlines svn:
Inconsistent line ending style
The thing is that this file is not yet under version control, so when I try to propdel or anything similar it doesn't work.
I am sure this file is not under version control because svn status shows this:
? install/version
? install/config.xml.php
I have already enabled the autoprops in svn default config but this did not help.
Any ideas?
Btw: this is a server, so no GUI.
vim makes it easy to force line endings to entirely CRLF or entirely CR.
:set ff=unix
:wq
d2u, dtox, dos2unix, are some names for simple utilities that are often installed on systems to do this task. You could also use the standard tr(1) utility:
tr -d '\r' < input > output
While working on Windows OS use Notepad ++:
Edit -> EOL Conversion.
- Windows Format
- UNIX/OSX Format
- Old Mac Format
You have current format information in the status bar.

Resources